charginfo.js 13 KB

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