charginfo.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. import * as echarts from '../../ec-canvas/echarts';
  2. import * as lf from '../../ec-canvas/echarts-liquidfill';
  3. let log = require('../../utils/log.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. name:'',
  10. address:'',
  11. chargprice: '',
  12. serviceprice: '',
  13. chargid: '',
  14. sumprice: '',
  15. fastFree:0,
  16. slowFree:0,
  17. fastSum:0,
  18. slowSum:0,
  19. pagesize:30,
  20. pagenum:1,
  21. total:-1,
  22. loadTotal: 0,
  23. dataLoading: false,
  24. finishedLoadTap: 0,
  25. finishedLoadShowTimes: 0,
  26. chargList: [],
  27. seeInfoChargPile:{},
  28. userInfo:{},
  29. isLogin: false,
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function(e) {
  35. let that = this;
  36. wx.getStorage({
  37. key: 'index_seeInfo_chargpile',
  38. success: function (res) {
  39. var seeInfoChargPile = res.data;
  40. seeInfoChargPile.sharpTotalPrice = (seeInfoChargPile.sharpChargPrice==null || seeInfoChargPile.sharpServicePrice==null)? null:(seeInfoChargPile.sharpChargPrice + seeInfoChargPile.sharpServicePrice).toFixed(6);
  41. seeInfoChargPile.peakTotalPrice = (seeInfoChargPile.peakChargPrice==null || seeInfoChargPile.peakServicePrice==null)? null:(seeInfoChargPile.peakChargPrice + seeInfoChargPile.peakServicePrice).toFixed(6);
  42. seeInfoChargPile.flatTotalPrice = (seeInfoChargPile.flatChargPrice==null || seeInfoChargPile.flatServicePrice==null)? null:(seeInfoChargPile.flatChargPrice + seeInfoChargPile.flatServicePrice).toFixed(6);
  43. seeInfoChargPile.valleyTotalPrice = (seeInfoChargPile.valleyChargPrice==null || seeInfoChargPile.valleyServicePrice==null)? null:(seeInfoChargPile.valleyChargPrice + seeInfoChargPile.valleyServicePrice).toFixed(6);
  44. seeInfoChargPile.totalprice = (seeInfoChargPile.chargprice==null || seeInfoChargPile.serviceprice==null)? null:(seeInfoChargPile.chargprice + seeInfoChargPile.serviceprice).toFixed(6);
  45. that.setData({
  46. seeInfoChargPile
  47. });
  48. console.info(seeInfoChargPile)
  49. wx.removeStorage({
  50. key: 'index_seeInfo_chargpile',
  51. success(res) {
  52. }
  53. });
  54. }
  55. });
  56. let { name, address, chargprice, serviceprice, chargid } = e;
  57. name = name=='null'?null:name;
  58. address = address=='null'?null:address;
  59. chargprice = chargprice=='null'?null:chargprice;
  60. serviceprice = serviceprice=='null'?null:serviceprice;
  61. chargid = chargid=='null'?null:chargid;
  62. // let sumprice = (chargprice==null || serviceprice==null)? null:chargprice+serviceprice;
  63. let sumprice = (chargprice==null || serviceprice==null)? null:chargprice+serviceprice;
  64. this.setData({
  65. name,
  66. address,
  67. chargprice,
  68. serviceprice,
  69. chargid,
  70. sumprice
  71. });
  72. this.getPage();
  73. },
  74. getPage(){
  75. if(this.data.chargList.length == this.data.total){
  76. this.setData({
  77. finishedLoadTap:this.data.finishedLoadTap+1
  78. })
  79. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  80. this.setData({
  81. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  82. })
  83. wx.showToast({
  84. title: '全部加载完毕',
  85. icon: 'success',
  86. duration: 2000
  87. })
  88. }
  89. return
  90. }
  91. if(this.data.dataLoading){
  92. return
  93. }
  94. this.setData({
  95. dataLoading: true
  96. })
  97. wx.showLoading({
  98. title: '数据加载中....',
  99. })
  100. let that = this;
  101. wx.request({
  102. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo',
  103. data: {
  104. id: that.data.chargid,
  105. pagenum: this.data.pagenum++,
  106. pagesize: 30,
  107. },
  108. method: 'POST',
  109. success(res) {
  110. console.log(res);
  111. let chargList = res.data.chargList.rows;
  112. chargList.forEach(key => {
  113. let chargstatusname = '';
  114. let chargstatusclass = '';
  115. if(key.chargstatus == 2){
  116. chargstatusname='空闲中'
  117. chargstatusclass = 'chargstatus_kxz'
  118. }else if(key.chargstatus == 11){
  119. chargstatusname='已插枪'
  120. chargstatusclass = 'chargstatus_ycq'
  121. }else if(key.chargstatus == 3 || key.chargstatus == 10){
  122. chargstatusname='充电中'
  123. chargstatusclass = 'chargstatus_cdz'
  124. }else if(key.chargstatus == 0){
  125. chargstatusname='离线'
  126. chargstatusclass = 'chargstatus_lx'
  127. }else{
  128. chargstatusname='故障'
  129. chargstatusclass = 'chargstatus_gz'
  130. }
  131. key.chargstatusname = chargstatusname;
  132. key.chargstatusclass = chargstatusclass;
  133. })
  134. console.log(chargList);
  135. // that.rechargeTimeOrder(chargemoneylogs);
  136. wx.hideLoading()
  137. that.setData({
  138. chargList: that.data.chargList.concat(chargList),
  139. total: res.data.chargList.total,
  140. dataLoading: false,
  141. fastFree : res.data.fastFree,
  142. slowFree : res.data.slowFree,
  143. fastSum : res.data.fastSum,
  144. slowSum : res.data.slowSum
  145. });
  146. }
  147. });
  148. },
  149. goScanResult(e){
  150. // scan_result
  151. console.info('xxxxxxxxxxxxxx')
  152. let {
  153. keywords
  154. } = e.currentTarget.dataset;
  155. let userInfo = wx.getStorageSync('userInfo');
  156. let isLogin = wx.getStorageSync('isLogin');
  157. let chargid = keywords.chargPileId;
  158. let that = this;
  159. if(isLogin && userInfo.bindingPhone==0){
  160. console.info('xxxxxxxxxxxxxx1')
  161. wx.showModal({
  162. title: '提示',
  163. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  164. showCancel:false,
  165. confirmText: '去绑定',
  166. confirmColor:'#00AADD',
  167. success: function (res1) {
  168. let url = `/pages/bindPhone/bindPhone`;
  169. wx.navigateTo({
  170. url
  171. });
  172. }
  173. });
  174. return;
  175. }
  176. wx.showLoading({
  177. title: '努力加载中...',
  178. })
  179. if (!isLogin) {
  180. console.info('xxxxxxxxxxxxxx2')
  181. log.info('[首页]', '[未登陆跳转登录界面]');
  182. let url = `/pages/login/phone_login/phone_login`;
  183. wx.hideLoading();
  184. wx.navigateTo({
  185. url
  186. });
  187. // return;
  188. } else {
  189. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId });
  190. wx.request({
  191. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  192. data: {
  193. userId: userInfo.userId
  194. },
  195. method: 'POST',
  196. success(res) {
  197. let {
  198. data
  199. } = res;
  200. let {
  201. result: order
  202. } = data;
  203. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  204. if (data && order && data.code == 200) {
  205. wx.hideLoading();
  206. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  207. wx.showModal({
  208. showCancel: false,
  209. content: '你有未支付的订单,请先支付',
  210. confirmColor:'#00AADD',
  211. success: function (res) {
  212. //console.log(res);
  213. if (!res.cancel) {
  214. //点击确定
  215. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  216. wx.navigateTo({
  217. url
  218. });
  219. }
  220. }
  221. });
  222. //console.log(that.data.result);
  223. } else {
  224. //console.log('无订单');
  225. log.info('[首页]', '[用户无未支付订单]');
  226. wx.request({
  227. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  228. // data: scanResult,
  229. data: {
  230. chargPileId: chargid,
  231. userId: userInfo.userId
  232. },
  233. method: 'POST',
  234. success(res) {
  235. console.log(chargid);
  236. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  237. if (!res.data || res.data.code == 500) {
  238. that.scanFlag = false;
  239. wx.hideLoading();
  240. //没有该充电桩信息
  241. wx.showModal({
  242. showCancel: false,
  243. confirmColor:'#00AADD',
  244. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
  245. });
  246. } else {
  247. res.data = res.data.result
  248. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  249. if (!res.data.chargstatus || res.data.chargstatus == 0 || res.data.chargstatus == 1 || res.data.chargstatus == 4 || res.data.chargstatus == 5 || res.data.chargstatus == 6 || res.data.chargstatus == 9) {
  250. //充电桩故障
  251. wx.showModal({
  252. showCancel: false,
  253. content: '终端故障,维修中',
  254. confirmColor:'#00AADD',
  255. });
  256. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  257. wx.showModal({
  258. showCancel: false,
  259. content: '正在充电中',
  260. confirmColor:'#00AADD',
  261. });
  262. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  263. wx.setStorage({
  264. key: "scan_chargpile",
  265. data: res.data
  266. });
  267. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  268. let url = `/pages/scan_result/scan_result`;
  269. wx.hideLoading();
  270. wx.navigateTo({
  271. url
  272. });
  273. }
  274. wx.hideLoading();
  275. }
  276. },
  277. fail(e) {
  278. getApp().showNetworkError();
  279. }
  280. });
  281. }
  282. },
  283. fail(e) {
  284. that.scanFlag = false;
  285. wx.hideLoading();
  286. getApp().showNetworkError();
  287. }
  288. });
  289. }
  290. },
  291. /**
  292. * 生命周期函数--监听页面初次渲染完成
  293. */
  294. onReady: function() {
  295. },
  296. /**
  297. * 生命周期函数--监听页面显示
  298. */
  299. onShow: function(e) {
  300. let userInfo = wx.getStorageSync('userInfo');
  301. let isLogin = wx.getStorageSync('isLogin');
  302. //console.log(userInfo);
  303. // 页面显示
  304. if (userInfo && isLogin) {
  305. //userInfo.flag = true;
  306. this.setData({
  307. userInfo: userInfo,
  308. isLogin: isLogin
  309. });
  310. } else {
  311. //未登录信息
  312. this.setData({
  313. userInfo: {}
  314. });
  315. }
  316. },
  317. /**
  318. * 生命周期函数--监听页面隐藏
  319. */
  320. onHide: function() {
  321. },
  322. /**
  323. * 生命周期函数--监听页面卸载
  324. */
  325. onUnload: function() {
  326. },
  327. bindScrollTolowerEvent: function(){
  328. this.getPage();
  329. },
  330. /**
  331. * 页面相关事件处理函数--监听用户下拉动作
  332. */
  333. onPullDownRefresh: function() {
  334. },
  335. /**
  336. * 页面上拉触底事件的处理函数
  337. */
  338. onReachBottom: function() {
  339. },
  340. /**
  341. * 用户点击右上角分享
  342. */
  343. onShareAppMessage: function() {
  344. }
  345. })