charginfo.js 17 KB

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