charginfo.js 15 KB

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