charginfo.js 17 KB

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