charginfo.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. this.setData({
  314. scrollTop: 0
  315. });
  316. },
  317. goScanResult(e){
  318. // scan_result
  319. console.info('xxxxxxxxxxxxxx')
  320. let {
  321. keywords
  322. } = e.currentTarget.dataset;
  323. let userInfo = wx.getStorageSync('userInfo');
  324. let isLogin = wx.getStorageSync('isLogin');
  325. let chargid = keywords.chargPileId;
  326. let that = this;
  327. if(isLogin && userInfo.bindingPhone==0){
  328. console.info('xxxxxxxxxxxxxx1')
  329. wx.showModal({
  330. title: '提示',
  331. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  332. showCancel:false,
  333. confirmText: '去绑定',
  334. confirmColor:'#00AADD',
  335. success: function (res1) {
  336. let url = `/pages/bindPhone/bindPhone`;
  337. wx.navigateTo({
  338. url
  339. });
  340. }
  341. });
  342. return;
  343. }
  344. wx.showLoading({
  345. title: '努力加载中...',
  346. })
  347. if (!isLogin) {
  348. console.info('xxxxxxxxxxxxxx2')
  349. log.info('[首页]', '[未登陆跳转登录界面]');
  350. let url = `/pages/login/phone_login/phone_login`;
  351. wx.hideLoading();
  352. wx.navigateTo({
  353. url
  354. });
  355. // return;
  356. } else {
  357. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId });
  358. wx.request({
  359. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  360. data: {
  361. userId: userInfo.userId
  362. },
  363. method: 'POST',
  364. success(res) {
  365. let {
  366. data
  367. } = res;
  368. let {
  369. result: order
  370. } = data;
  371. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  372. if (data && order && data.code == 200) {
  373. wx.hideLoading();
  374. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  375. wx.showModal({
  376. showCancel: false,
  377. content: '你有未支付的订单,请先支付',
  378. confirmColor:'#00AADD',
  379. success: function (res) {
  380. //console.log(res);
  381. if (!res.cancel) {
  382. //点击确定
  383. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  384. wx.navigateTo({
  385. url
  386. });
  387. }
  388. }
  389. });
  390. //console.log(that.data.result);
  391. } else {
  392. //console.log('无订单');
  393. log.info('[首页]', '[用户无未支付订单]');
  394. wx.request({
  395. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  396. // data: scanResult,
  397. data: {
  398. chargPileId: chargid,
  399. userId: userInfo.userId
  400. },
  401. method: 'POST',
  402. success(res) {
  403. console.log(chargid);
  404. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  405. if (!res.data || res.data.code == 500) {
  406. that.scanFlag = false;
  407. wx.hideLoading();
  408. //没有该充电桩信息
  409. wx.showModal({
  410. showCancel: false,
  411. confirmColor:'#00AADD',
  412. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
  413. });
  414. } else {
  415. res.data = res.data.result
  416. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  417. 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) {
  418. //充电桩故障
  419. wx.showModal({
  420. showCancel: false,
  421. content: '终端故障,维修中',
  422. confirmColor:'#00AADD',
  423. });
  424. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  425. wx.showModal({
  426. showCancel: false,
  427. content: '正在充电中',
  428. confirmColor:'#00AADD',
  429. });
  430. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  431. wx.setStorage({
  432. key: "scan_chargpile",
  433. data: res.data
  434. });
  435. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  436. let url = `/pages/scan_result/scan_result`;
  437. wx.hideLoading();
  438. wx.navigateTo({
  439. url
  440. });
  441. }
  442. wx.hideLoading();
  443. }
  444. },
  445. fail(e) {
  446. getApp().showNetworkError();
  447. }
  448. });
  449. }
  450. },
  451. fail(e) {
  452. that.scanFlag = false;
  453. wx.hideLoading();
  454. getApp().showNetworkError();
  455. }
  456. });
  457. }
  458. },
  459. seeReservation: function(e){
  460. let userInfo = wx.getStorageSync('userInfo');
  461. let isLogin = wx.getStorageSync('isLogin');
  462. let that = this;
  463. if(isLogin && userInfo.bindingPhone==0){
  464. console.info('xxxxxxxxxxxxxx1')
  465. wx.showModal({
  466. title: '提示',
  467. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  468. showCancel:false,
  469. confirmText: '去绑定',
  470. confirmColor:'#00AADD',
  471. success: function (res1) {
  472. let url = `/pages/bindPhone/bindPhone`;
  473. wx.navigateTo({
  474. url
  475. });
  476. }
  477. });
  478. return;
  479. }
  480. if (!isLogin) {
  481. console.info('xxxxxxxxxxxxxx2')
  482. log.info('[首页]', '[未登陆跳转登录界面]');
  483. let url = `/pages/login/phone_login/phone_login`;
  484. wx.hideLoading();
  485. wx.navigateTo({
  486. url
  487. });
  488. return;
  489. }
  490. let idx = e.currentTarget.dataset.idx;
  491. console.info(idx)
  492. let {
  493. chargStationId,
  494. chargPileName,
  495. chargPileId,
  496. chargStationName,
  497. id
  498. } = idx;
  499. let userId = userInfo.userId;
  500. let url = `/pages/reservation/reservation?chargStationId=` + chargStationId + `&chargPileName=` + chargPileName + `&chargPileId=` + chargPileId + `&chargPileIdId=` + id + "&chargStationName=" + chargStationName + "&userId=" + userId;
  501. wx.navigateTo({
  502. url
  503. });
  504. },
  505. /**
  506. * 生命周期函数--监听页面初次渲染完成
  507. */
  508. onReady: function() {
  509. },
  510. /**
  511. * 生命周期函数--监听页面显示
  512. */
  513. onShow: function(e) {
  514. let userInfo = wx.getStorageSync('userInfo');
  515. let isLogin = wx.getStorageSync('isLogin');
  516. //console.log(userInfo);
  517. // 页面显示
  518. if (userInfo && isLogin) {
  519. //userInfo.flag = true;
  520. this.setData({
  521. userInfo: userInfo,
  522. isLogin: isLogin
  523. });
  524. } else {
  525. //未登录信息
  526. this.setData({
  527. userInfo: {}
  528. });
  529. }
  530. },
  531. chargingLog(e){
  532. let idx = e.currentTarget.dataset.idx;
  533. let chargPileId = idx.chargPileId;
  534. console.info(chargPileId);
  535. let url = '/pages/ucenter/charginglog/opsCharginglog?chargPileId=' + chargPileId
  536. wx.navigateTo({
  537. url
  538. });
  539. return;
  540. },
  541. callphone(){
  542. let that = this
  543. let phonenum = that.data.offlineServicecall;
  544. wx.makePhoneCall({
  545. phoneNumber: that.data.offlineServicecall, //此号码并非真实电话号码,仅用于测试
  546. success:function(){
  547. console.log("拨打电话成功!" + phonenum)
  548. },
  549. fail:function(){
  550. console.log("拨打电话失败!" + phonenum)
  551. }
  552. })
  553. },
  554. /**
  555. * 生命周期函数--监听页面隐藏
  556. */
  557. onHide: function() {
  558. },
  559. /**
  560. * 生命周期函数--监听页面卸载
  561. */
  562. onUnload: function() {
  563. },
  564. bindScrollTolowerEvent: function(){
  565. this.getPage();
  566. },
  567. /**
  568. * 页面相关事件处理函数--监听用户下拉动作
  569. */
  570. onPullDownRefresh: function() {
  571. },
  572. /**
  573. * 页面上拉触底事件的处理函数
  574. */
  575. onReachBottom: function() {
  576. },
  577. /**
  578. * 用户点击右上角分享
  579. */
  580. onShareAppMessage: function() {
  581. }
  582. })