charginfo.js 20 KB

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