charginfo.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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:30,
  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.getPage();
  149. },
  150. previewImage(e){
  151. var that = this,
  152. //获取当前图片的下表
  153. index = e.currentTarget.dataset.index,
  154. //数据源
  155. pictures = this.data.chargfeatureList;
  156. wx.previewImage({
  157. //当前显示下表
  158. current: pictures[index],
  159. //数据源
  160. urls: pictures
  161. })
  162. },
  163. getPage(){
  164. if(this.data.chargList.length == this.data.total){
  165. this.setData({
  166. finishedLoadTap:this.data.finishedLoadTap+1
  167. })
  168. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  169. this.setData({
  170. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  171. })
  172. wx.showToast({
  173. title: '全部加载完毕',
  174. icon: 'success',
  175. duration: 2000
  176. })
  177. }
  178. return
  179. }
  180. if(this.data.dataLoading){
  181. return
  182. }
  183. this.setData({
  184. dataLoading: true
  185. })
  186. wx.showLoading({
  187. title: '数据加载中....',
  188. })
  189. let that = this;
  190. wx.request({
  191. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo',
  192. data: {
  193. id: that.data.chargid,
  194. pagenum: this.data.pagenum++,
  195. pagesize: 30,
  196. },
  197. method: 'POST',
  198. success(res) {
  199. console.log(res);
  200. let chargList = res.data.chargList.rows;
  201. chargList.forEach(key => {
  202. let chargstatusname = '';
  203. let chargstatusclass = '';
  204. if(key.chargstatus == 2){
  205. chargstatusname='空闲中'
  206. chargstatusclass = 'chargstatus_kxz'
  207. }else if(key.chargstatus == 11){
  208. chargstatusname='已插枪'
  209. chargstatusclass = 'chargstatus_ycq'
  210. }else if(key.chargstatus == 3 || key.chargstatus == 10){
  211. chargstatusname='充电中'
  212. chargstatusclass = 'chargstatus_cdz'
  213. }else if(key.chargstatus == 0){
  214. chargstatusname='离线'
  215. chargstatusclass = 'chargstatus_lx'
  216. }else{
  217. chargstatusname='故障'
  218. chargstatusclass = 'chargstatus_gz'
  219. }
  220. key.chargstatusname = chargstatusname;
  221. key.chargstatusclass = chargstatusclass;
  222. })
  223. console.log(chargList);
  224. // that.rechargeTimeOrder(chargemoneylogs);
  225. wx.hideLoading()
  226. that.setData({
  227. chargList: that.data.chargList.concat(chargList),
  228. total: res.data.chargList.total,
  229. dataLoading: false,
  230. fastFree : res.data.fastFree,
  231. slowFree : res.data.slowFree,
  232. fastSum : res.data.fastSum,
  233. slowSum : res.data.slowSum
  234. });
  235. }
  236. });
  237. },
  238. goScanResult(e){
  239. // scan_result
  240. console.info('xxxxxxxxxxxxxx')
  241. let {
  242. keywords
  243. } = e.currentTarget.dataset;
  244. let userInfo = wx.getStorageSync('userInfo');
  245. let isLogin = wx.getStorageSync('isLogin');
  246. let chargid = keywords.chargPileId;
  247. let that = this;
  248. if(isLogin && userInfo.bindingPhone==0){
  249. console.info('xxxxxxxxxxxxxx1')
  250. wx.showModal({
  251. title: '提示',
  252. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  253. showCancel:false,
  254. confirmText: '去绑定',
  255. confirmColor:'#00AADD',
  256. success: function (res1) {
  257. let url = `/pages/bindPhone/bindPhone`;
  258. wx.navigateTo({
  259. url
  260. });
  261. }
  262. });
  263. return;
  264. }
  265. wx.showLoading({
  266. title: '努力加载中...',
  267. })
  268. if (!isLogin) {
  269. console.info('xxxxxxxxxxxxxx2')
  270. log.info('[首页]', '[未登陆跳转登录界面]');
  271. let url = `/pages/login/phone_login/phone_login`;
  272. wx.hideLoading();
  273. wx.navigateTo({
  274. url
  275. });
  276. // return;
  277. } else {
  278. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId });
  279. wx.request({
  280. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  281. data: {
  282. userId: userInfo.userId
  283. },
  284. method: 'POST',
  285. success(res) {
  286. let {
  287. data
  288. } = res;
  289. let {
  290. result: order
  291. } = data;
  292. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  293. if (data && order && data.code == 200) {
  294. wx.hideLoading();
  295. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  296. wx.showModal({
  297. showCancel: false,
  298. content: '你有未支付的订单,请先支付',
  299. confirmColor:'#00AADD',
  300. success: function (res) {
  301. //console.log(res);
  302. if (!res.cancel) {
  303. //点击确定
  304. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  305. wx.navigateTo({
  306. url
  307. });
  308. }
  309. }
  310. });
  311. //console.log(that.data.result);
  312. } else {
  313. //console.log('无订单');
  314. log.info('[首页]', '[用户无未支付订单]');
  315. wx.request({
  316. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  317. // data: scanResult,
  318. data: {
  319. chargPileId: chargid,
  320. userId: userInfo.userId
  321. },
  322. method: 'POST',
  323. success(res) {
  324. console.log(chargid);
  325. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  326. if (!res.data || res.data.code == 500) {
  327. that.scanFlag = false;
  328. wx.hideLoading();
  329. //没有该充电桩信息
  330. wx.showModal({
  331. showCancel: false,
  332. confirmColor:'#00AADD',
  333. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
  334. });
  335. } else {
  336. res.data = res.data.result
  337. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  338. 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) {
  339. //充电桩故障
  340. wx.showModal({
  341. showCancel: false,
  342. content: '终端故障,维修中',
  343. confirmColor:'#00AADD',
  344. });
  345. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  346. wx.showModal({
  347. showCancel: false,
  348. content: '正在充电中',
  349. confirmColor:'#00AADD',
  350. });
  351. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  352. wx.setStorage({
  353. key: "scan_chargpile",
  354. data: res.data
  355. });
  356. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  357. let url = `/pages/scan_result/scan_result`;
  358. wx.hideLoading();
  359. wx.navigateTo({
  360. url
  361. });
  362. }
  363. wx.hideLoading();
  364. }
  365. },
  366. fail(e) {
  367. getApp().showNetworkError();
  368. }
  369. });
  370. }
  371. },
  372. fail(e) {
  373. that.scanFlag = false;
  374. wx.hideLoading();
  375. getApp().showNetworkError();
  376. }
  377. });
  378. }
  379. },
  380. seeReservation: function(e){
  381. let userInfo = wx.getStorageSync('userInfo');
  382. let isLogin = wx.getStorageSync('isLogin');
  383. let that = this;
  384. if(isLogin && userInfo.bindingPhone==0){
  385. console.info('xxxxxxxxxxxxxx1')
  386. wx.showModal({
  387. title: '提示',
  388. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  389. showCancel:false,
  390. confirmText: '去绑定',
  391. confirmColor:'#00AADD',
  392. success: function (res1) {
  393. let url = `/pages/bindPhone/bindPhone`;
  394. wx.navigateTo({
  395. url
  396. });
  397. }
  398. });
  399. return;
  400. }
  401. if (!isLogin) {
  402. console.info('xxxxxxxxxxxxxx2')
  403. log.info('[首页]', '[未登陆跳转登录界面]');
  404. let url = `/pages/login/phone_login/phone_login`;
  405. wx.hideLoading();
  406. wx.navigateTo({
  407. url
  408. });
  409. return;
  410. }
  411. let idx = e.currentTarget.dataset.idx;
  412. console.info(idx)
  413. let {
  414. chargStationId,
  415. chargPileName,
  416. chargPileId,
  417. chargStationName,
  418. id
  419. } = idx;
  420. let userId = userInfo.userId;
  421. let url = `/pages/reservation/reservation?chargStationId=` + chargStationId + `&chargPileName=` + chargPileName + `&chargPileId=` + chargPileId + `&chargPileIdId=` + id + "&chargStationName=" + chargStationName + "&userId=" + userId;
  422. wx.navigateTo({
  423. url
  424. });
  425. },
  426. /**
  427. * 生命周期函数--监听页面初次渲染完成
  428. */
  429. onReady: function() {
  430. },
  431. /**
  432. * 生命周期函数--监听页面显示
  433. */
  434. onShow: function(e) {
  435. let userInfo = wx.getStorageSync('userInfo');
  436. let isLogin = wx.getStorageSync('isLogin');
  437. //console.log(userInfo);
  438. // 页面显示
  439. if (userInfo && isLogin) {
  440. //userInfo.flag = true;
  441. this.setData({
  442. userInfo: userInfo,
  443. isLogin: isLogin
  444. });
  445. } else {
  446. //未登录信息
  447. this.setData({
  448. userInfo: {}
  449. });
  450. }
  451. },
  452. chargingLog(e){
  453. let idx = e.currentTarget.dataset.idx;
  454. let chargPileId = idx.chargPileId;
  455. console.info(chargPileId);
  456. let url = '/pages/ucenter/charginglog/opsCharginglog?chargPileId=' + chargPileId
  457. wx.navigateTo({
  458. url
  459. });
  460. return;
  461. },
  462. callphone(){
  463. let that = this
  464. let phonenum = that.data.offlineServicecall;
  465. wx.makePhoneCall({
  466. phoneNumber: that.data.offlineServicecall, //此号码并非真实电话号码,仅用于测试
  467. success:function(){
  468. console.log("拨打电话成功!" + phonenum)
  469. },
  470. fail:function(){
  471. console.log("拨打电话失败!" + phonenum)
  472. }
  473. })
  474. },
  475. /**
  476. * 生命周期函数--监听页面隐藏
  477. */
  478. onHide: function() {
  479. },
  480. /**
  481. * 生命周期函数--监听页面卸载
  482. */
  483. onUnload: function() {
  484. },
  485. bindScrollTolowerEvent: function(){
  486. this.getPage();
  487. },
  488. /**
  489. * 页面相关事件处理函数--监听用户下拉动作
  490. */
  491. onPullDownRefresh: function() {
  492. },
  493. /**
  494. * 页面上拉触底事件的处理函数
  495. */
  496. onReachBottom: function() {
  497. },
  498. /**
  499. * 用户点击右上角分享
  500. */
  501. onShareAppMessage: function() {
  502. }
  503. })