charginfo.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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. offlineServicecall:'',
  12. stationTagList:[],
  13. chargprice: '',
  14. serviceprice: '',
  15. chargid: '',
  16. sumprice: '',
  17. fastFree:0,
  18. slowFree:0,
  19. fastSum:0,
  20. slowSum:0,
  21. pagesize:10,
  22. pagenum:1,
  23. total:-1,
  24. loadTotal: 0,
  25. dataLoading: false,
  26. finishedLoadTap: 0,
  27. finishedLoadShowTimes: 0,
  28. chargList: [],
  29. seeInfoChargPile:{},
  30. userInfo:{},
  31. chargfeatureList:[],
  32. isLogin: false,
  33. resultTable: [],
  34. // 是否减免停车费
  35. carParkingRate: false,
  36. // 停车时间
  37. parkTime: 0,
  38. scrollTop:0
  39. },
  40. execParking(that,stationId){
  41. wx.request({
  42. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carParkingRate?stationId=' + stationId,
  43. // data: {
  44. // loginName: userInfo.loginName
  45. // },
  46. method: 'POST',
  47. success: function (res) {
  48. // 是否减免停车费
  49. // carParkingRate: false,
  50. // parkTime: 0,
  51. console.info(res)
  52. let reduceTime = res.data?.reduceTime;
  53. if(!reduceTime){
  54. that.setData({
  55. carParkingRate:false
  56. })
  57. return;
  58. }
  59. that.setData({
  60. carParkingRate:true
  61. })
  62. try{
  63. that.setData({
  64. parkTime: parseFloat((reduceTime/ 3600).toFixed(2))
  65. })
  66. }catch(e){
  67. that.setData({
  68. carParkingRate:false
  69. })
  70. }
  71. },
  72. fail(e) {
  73. console.log("用户数据同步失败");
  74. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  75. }
  76. });
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function(e) {
  82. let that = this;
  83. let stationTagList = [];
  84. let offlineServicecall ="";
  85. wx.getStorage({
  86. key: 'index_seeInfo_chargpile',
  87. success: function (res) {
  88. console.info(res)
  89. var seeInfoChargPile = res.data;
  90. stationTagList = seeInfoChargPile.stationTagList
  91. offlineServicecall = seeInfoChargPile.offlineServicecall
  92. that.setData({
  93. stationTagList,
  94. offlineServicecall,
  95. })
  96. console.info(stationTagList)
  97. // 异步更新
  98. console.info(seeInfoChargPile.chargStationId)
  99. that.execParking(that,seeInfoChargPile.chargStationId)
  100. let resultTable = seeInfoChargPile.resultList
  101. that.setData({
  102. resultTable
  103. })
  104. that.setData({
  105. resultTable
  106. })
  107. let chargfeatureList;
  108. if(seeInfoChargPile.chargfeatures){
  109. chargfeatureList = seeInfoChargPile.chargfeatures.split(',')
  110. }else{
  111. chargfeatureList = [];
  112. }
  113. seeInfoChargPile.sharpTotalPrice = parseFloat((seeInfoChargPile.sharpChargPrice==null || seeInfoChargPile.sharpServicePrice==null || seeInfoChargPile.sharpChargPrice=='暂无费用' || seeInfoChargPile.sharpServicePrice=='暂无费用')? null:(seeInfoChargPile.sharpChargPrice + seeInfoChargPile.sharpServicePrice).toFixed(6));
  114. seeInfoChargPile.peakTotalPrice = parseFloat((seeInfoChargPile.peakChargPrice==null || seeInfoChargPile.peakServicePrice==null || seeInfoChargPile.peakChargPrice=='暂无费用' || seeInfoChargPile.peakServicePrice=='暂无费用' )? null:(seeInfoChargPile.peakChargPrice + seeInfoChargPile.peakServicePrice).toFixed(6));
  115. seeInfoChargPile.flatTotalPrice = parseFloat((seeInfoChargPile.flatChargPrice==null || seeInfoChargPile.flatServicePrice==null || seeInfoChargPile.flatChargPrice=='暂无费用' || seeInfoChargPile.flatServicePrice=='暂无费用' )? null:(seeInfoChargPile.flatChargPrice + seeInfoChargPile.flatServicePrice).toFixed(6));
  116. seeInfoChargPile.valleyTotalPrice = parseFloat((seeInfoChargPile.valleyChargPrice==null || seeInfoChargPile.valleyServicePrice==null || seeInfoChargPile.valleyChargPrice=='暂无费用' || seeInfoChargPile.valleyServicePrice=='暂无费用' )? null:(seeInfoChargPile.valleyChargPrice + seeInfoChargPile.valleyServicePrice).toFixed(6));
  117. seeInfoChargPile.totalprice = parseFloat((seeInfoChargPile.chargprice==null || seeInfoChargPile.serviceprice==null || seeInfoChargPile.chargprice=='暂无费用' || seeInfoChargPile.serviceprice=='暂无费用')? null:(seeInfoChargPile.chargprice + seeInfoChargPile.serviceprice).toFixed(6));
  118. that.setData({
  119. seeInfoChargPile,
  120. chargfeatureList
  121. });
  122. console.info(seeInfoChargPile)
  123. console.info(chargfeatureList)
  124. wx.removeStorage({
  125. key: 'index_seeInfo_chargpile',
  126. success(res) {
  127. }
  128. });
  129. }
  130. });
  131. let { name, address, chargprice, serviceprice, chargid } = e;
  132. name = name=='null'?null:name;
  133. address = address=='null'?null:address;
  134. // stationTagList = !stationTagList?null:stationTagList;
  135. chargprice = chargprice=='null'?null:chargprice;
  136. serviceprice = serviceprice=='null'?null:serviceprice;
  137. chargid = chargid=='null'?null:chargid;
  138. // let sumprice = (chargprice==null || serviceprice==null)? null:chargprice+serviceprice;
  139. let sumprice = (chargprice==null || serviceprice==null)? null:chargprice+serviceprice;
  140. this.setData({
  141. name,
  142. address,
  143. // stationTagList,
  144. chargprice,
  145. serviceprice,
  146. chargid,
  147. sumprice
  148. });
  149. this.fastAndSlow()
  150. this.getPage();
  151. },
  152. fastAndSlow(e){
  153. let that = this;
  154. wx.request({
  155. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/fastAndSlow',
  156. data: {
  157. id: that.data.chargid,
  158. },
  159. method: 'POST',
  160. success(res) {
  161. that.setData({
  162. fastFree : res.data.fastFree,
  163. slowFree : res.data.slowFree,
  164. fastSum : res.data.fastSum,
  165. slowSum : res.data.slowSum
  166. });
  167. }
  168. });
  169. },
  170. previewImage(e){
  171. var that = this,
  172. //获取当前图片的下表
  173. index = e.currentTarget.dataset.index,
  174. //数据源
  175. pictures = this.data.chargfeatureList;
  176. wx.previewImage({
  177. //当前显示下表
  178. current: pictures[index],
  179. //数据源
  180. urls: pictures
  181. })
  182. },
  183. getPage(){
  184. if(this.data.chargList.length == this.data.total){
  185. this.setData({
  186. finishedLoadTap:this.data.finishedLoadTap+1
  187. })
  188. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  189. this.setData({
  190. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  191. })
  192. wx.showToast({
  193. title: '全部加载完毕',
  194. icon: 'success',
  195. duration: 2000
  196. })
  197. }
  198. return
  199. }
  200. if(this.data.dataLoading){
  201. return
  202. }
  203. this.setData({
  204. dataLoading: true
  205. })
  206. wx.showLoading({
  207. title: '数据加载中....',
  208. })
  209. let that = this;
  210. wx.request({
  211. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo',
  212. data: {
  213. id: that.data.chargid,
  214. pagenum: this.data.pagenum++,
  215. pagesize: 10,
  216. },
  217. method: 'POST',
  218. success(res) {
  219. console.log(res);
  220. console.log(that.data.pagenum+":num");
  221. let chargList = res.data.chargList.rows;
  222. chargList.forEach(key => {
  223. let chargstatusname = '';
  224. let chargstatusclass = '';
  225. if(key.chargstatus == 2){
  226. chargstatusname='空闲中'
  227. chargstatusclass = 'chargstatus_kxz'
  228. }else if(key.chargstatus == 11){
  229. chargstatusname='已插枪'
  230. chargstatusclass = 'chargstatus_ycq'
  231. }else if(key.chargstatus == 3 || key.chargstatus == 10){
  232. chargstatusname='充电中'
  233. chargstatusclass = 'chargstatus_cdz'
  234. }else if(key.chargstatus == 0){
  235. chargstatusname='离线'
  236. chargstatusclass = 'chargstatus_lx'
  237. }else{
  238. chargstatusname='故障'
  239. chargstatusclass = 'chargstatus_gz'
  240. }
  241. key.chargstatusname = chargstatusname;
  242. key.chargstatusclass = chargstatusclass;
  243. })
  244. console.log(chargList);
  245. // that.rechargeTimeOrder(chargemoneylogs);
  246. wx.hideLoading()
  247. that.setData({
  248. chargList: that.data.chargList.concat(chargList),
  249. total: res.data.total,
  250. dataLoading: false,
  251. fastFree : res.data.fastFree,
  252. slowFree : res.data.slowFree,
  253. fastSum : res.data.fastSum,
  254. slowSum : res.data.slowSum
  255. });
  256. }
  257. });
  258. },
  259. refreshPage: function(e) {
  260. wx.showLoading({
  261. title: '数据加载中....',
  262. })
  263. let that = this;
  264. that.setData({
  265. pagenum:1
  266. });
  267. wx.request({
  268. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo',
  269. data: {
  270. id: that.data.chargid,
  271. pagenum: this.data.pagenum++,
  272. pagesize: 10,
  273. },
  274. method: 'POST',
  275. success(res) {
  276. let chargList = res.data.chargList.rows;
  277. chargList.forEach(key => {
  278. let chargstatusname = '';
  279. let chargstatusclass = '';
  280. if(key.chargstatus == 2){
  281. chargstatusname='空闲中'
  282. chargstatusclass = 'chargstatus_kxz'
  283. }else if(key.chargstatus == 11){
  284. chargstatusname='已插枪'
  285. chargstatusclass = 'chargstatus_ycq'
  286. }else if(key.chargstatus == 3 || key.chargstatus == 10){
  287. chargstatusname='充电中'
  288. chargstatusclass = 'chargstatus_cdz'
  289. }else if(key.chargstatus == 0){
  290. chargstatusname='离线'
  291. chargstatusclass = 'chargstatus_lx'
  292. }else{
  293. chargstatusname='故障'
  294. chargstatusclass = 'chargstatus_gz'
  295. }
  296. key.chargstatusname = chargstatusname;
  297. key.chargstatusclass = chargstatusclass;
  298. })
  299. console.log(chargList);
  300. // that.rechargeTimeOrder(chargemoneylogs);
  301. wx.hideLoading()
  302. that.setData({
  303. chargList: chargList,
  304. total: res.data.total,
  305. dataLoading: false,
  306. fastFree : res.data.fastFree,
  307. slowFree : res.data.slowFree,
  308. fastSum : res.data.fastSum,
  309. slowSum : res.data.slowSum
  310. });
  311. }
  312. });
  313. wx.request({
  314. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/fastAndSlow',
  315. data: {
  316. id: that.data.chargid,
  317. },
  318. method: 'POST',
  319. success(res) {
  320. that.setData({
  321. fastFree : res.data.fastFree,
  322. slowFree : res.data.slowFree,
  323. fastSum : res.data.fastSum,
  324. slowSum : res.data.slowSum
  325. });
  326. }
  327. });
  328. this.setData({
  329. scrollTop: 0
  330. });
  331. },
  332. goScanResult(e){
  333. // scan_result
  334. console.info('xxxxxxxxxxxxxx')
  335. let {
  336. keywords
  337. } = e.currentTarget.dataset;
  338. let userInfo = wx.getStorageSync('userInfo');
  339. let isLogin = wx.getStorageSync('isLogin');
  340. let chargid = keywords.chargPileId;
  341. let that = this;
  342. if(isLogin && userInfo.bindingPhone==0){
  343. console.info('xxxxxxxxxxxxxx1')
  344. wx.showModal({
  345. title: '提示',
  346. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  347. showCancel:false,
  348. confirmText: '去绑定',
  349. confirmColor:'#00AADD',
  350. success: function (res1) {
  351. let url = `/pages/bindPhone/bindPhone`;
  352. wx.navigateTo({
  353. url
  354. });
  355. }
  356. });
  357. return;
  358. }
  359. wx.showLoading({
  360. title: '努力加载中...',
  361. })
  362. if (!isLogin) {
  363. console.info('xxxxxxxxxxxxxx2')
  364. log.info('[首页]', '[未登陆跳转登录界面]');
  365. let url = `/pages/login/phone_login/phone_login`;
  366. wx.hideLoading();
  367. wx.navigateTo({
  368. url
  369. });
  370. // return;
  371. } else {
  372. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId });
  373. wx.request({
  374. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  375. data: {
  376. userId: userInfo.userId
  377. },
  378. method: 'POST',
  379. success(res) {
  380. let {
  381. data
  382. } = res;
  383. let {
  384. result: order
  385. } = data;
  386. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  387. if (data && order && data.code == 200) {
  388. wx.hideLoading();
  389. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  390. wx.showModal({
  391. showCancel: false,
  392. content: '你有未支付的订单,请先支付',
  393. confirmColor:'#00AADD',
  394. success: function (res) {
  395. //console.log(res);
  396. if (!res.cancel) {
  397. //点击确定
  398. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  399. wx.navigateTo({
  400. url
  401. });
  402. }
  403. }
  404. });
  405. //console.log(that.data.result);
  406. } else {
  407. //console.log('无订单');
  408. log.info('[首页]', '[用户无未支付订单]');
  409. wx.request({
  410. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  411. // data: scanResult,
  412. data: {
  413. chargPileId: chargid,
  414. userId: userInfo.userId
  415. },
  416. method: 'POST',
  417. success(res) {
  418. console.log(chargid);
  419. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  420. if (!res.data || res.data.code == 500) {
  421. that.scanFlag = false;
  422. wx.hideLoading();
  423. //没有该充电桩信息
  424. wx.showModal({
  425. showCancel: false,
  426. confirmColor:'#00AADD',
  427. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
  428. });
  429. } else {
  430. res.data = res.data.result
  431. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  432. 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) {
  433. //充电桩故障
  434. wx.showModal({
  435. showCancel: false,
  436. content: '终端故障,维修中',
  437. confirmColor:'#00AADD',
  438. });
  439. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  440. wx.showModal({
  441. showCancel: false,
  442. content: '正在充电中',
  443. confirmColor:'#00AADD',
  444. });
  445. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  446. wx.setStorage({
  447. key: "scan_chargpile",
  448. data: res.data
  449. });
  450. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  451. let url = `/pages/scan_result/scan_result`;
  452. wx.hideLoading();
  453. wx.navigateTo({
  454. url
  455. });
  456. }
  457. wx.hideLoading();
  458. }
  459. },
  460. fail(e) {
  461. getApp().showNetworkError();
  462. }
  463. });
  464. }
  465. },
  466. fail(e) {
  467. that.scanFlag = false;
  468. wx.hideLoading();
  469. getApp().showNetworkError();
  470. }
  471. });
  472. }
  473. },
  474. seeReservation: function(e){
  475. let userInfo = wx.getStorageSync('userInfo');
  476. let isLogin = wx.getStorageSync('isLogin');
  477. let that = this;
  478. if(isLogin && userInfo.bindingPhone==0){
  479. console.info('xxxxxxxxxxxxxx1')
  480. wx.showModal({
  481. title: '提示',
  482. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  483. showCancel:false,
  484. confirmText: '去绑定',
  485. confirmColor:'#00AADD',
  486. success: function (res1) {
  487. let url = `/pages/bindPhone/bindPhone`;
  488. wx.navigateTo({
  489. url
  490. });
  491. }
  492. });
  493. return;
  494. }
  495. if (!isLogin) {
  496. console.info('xxxxxxxxxxxxxx2')
  497. log.info('[首页]', '[未登陆跳转登录界面]');
  498. let url = `/pages/login/phone_login/phone_login`;
  499. wx.hideLoading();
  500. wx.navigateTo({
  501. url
  502. });
  503. return;
  504. }
  505. let idx = e.currentTarget.dataset.idx;
  506. console.info(idx)
  507. let {
  508. chargStationId,
  509. chargPileName,
  510. chargPileId,
  511. chargStationName,
  512. id
  513. } = idx;
  514. let userId = userInfo.userId;
  515. let url = `/pages/reservation/reservation?chargStationId=` + chargStationId + `&chargPileName=` + chargPileName + `&chargPileId=` + chargPileId + `&chargPileIdId=` + id + "&chargStationName=" + chargStationName + "&userId=" + userId;
  516. wx.navigateTo({
  517. url
  518. });
  519. },
  520. /**
  521. * 生命周期函数--监听页面初次渲染完成
  522. */
  523. onReady: function() {
  524. },
  525. /**
  526. * 生命周期函数--监听页面显示
  527. */
  528. onShow: function(e) {
  529. let userInfo = wx.getStorageSync('userInfo');
  530. let isLogin = wx.getStorageSync('isLogin');
  531. //console.log(userInfo);
  532. // 页面显示
  533. if (userInfo && isLogin) {
  534. //userInfo.flag = true;
  535. this.setData({
  536. userInfo: userInfo,
  537. isLogin: isLogin
  538. });
  539. } else {
  540. //未登录信息
  541. this.setData({
  542. userInfo: {}
  543. });
  544. }
  545. },
  546. chargingLog(e){
  547. let idx = e.currentTarget.dataset.idx;
  548. let chargPileId = idx.chargPileId;
  549. console.info(chargPileId);
  550. let url = '/pages/ucenter/charginglog/opsCharginglog?chargPileId=' + chargPileId
  551. wx.navigateTo({
  552. url
  553. });
  554. return;
  555. },
  556. callphone(){
  557. let that = this
  558. let phonenum = that.data.offlineServicecall;
  559. wx.makePhoneCall({
  560. phoneNumber: that.data.offlineServicecall, //此号码并非真实电话号码,仅用于测试
  561. success:function(){
  562. console.log("拨打电话成功!" + phonenum)
  563. },
  564. fail:function(){
  565. console.log("拨打电话失败!" + phonenum)
  566. }
  567. })
  568. },
  569. /**
  570. * 生命周期函数--监听页面隐藏
  571. */
  572. onHide: function() {
  573. },
  574. /**
  575. * 生命周期函数--监听页面卸载
  576. */
  577. onUnload: function() {
  578. },
  579. bindScrollTolowerEvent: function(){
  580. this.getPage();
  581. },
  582. /**
  583. * 页面相关事件处理函数--监听用户下拉动作
  584. */
  585. onPullDownRefresh: function() {
  586. },
  587. /**
  588. * 页面上拉触底事件的处理函数
  589. */
  590. onReachBottom: function() {
  591. },
  592. /**
  593. * 用户点击右上角分享
  594. */
  595. onShareAppMessage: function() {
  596. }
  597. })