elpackage.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. // pages/scan_result/elpackage.js
  2. let log = require('../../utils/log.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. progressPercentage: 100, // 初始进度值为50%
  9. // chargPile: null,
  10. chargPile: true,
  11. orderid: null,
  12. userId: null,
  13. repaidbalance: 0,
  14. resultTable: [],
  15. // 是否减免停车费
  16. carParkingRate: false,
  17. // 停车时间
  18. parkTime: 0,
  19. url:'/images/scan_result.png',
  20. authStatus: 1,
  21. defPlateNumber:''
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. let that = this;
  28. wx.getStorage({
  29. key: 'scan_chargpile',
  30. success: function (res) {
  31. console.log(res);
  32. //console.log(res.data);
  33. var chargPile = res.data;
  34. let authStatus = chargPile.authStatus
  35. let resultTable = chargPile.resultList
  36. that.resetResultList(resultTable)
  37. that.setData({
  38. resultTable,
  39. authStatus
  40. })
  41. chargPile.sharpTotalPrice = parseFloat((chargPile.sharpChargPrice + chargPile.sharpServicePrice).toFixed(6));
  42. chargPile.peakTotalPrice = parseFloat((chargPile.peakChargPrice + chargPile.peakServicePrice).toFixed(6));
  43. chargPile.flatTotalPrice = parseFloat((chargPile.flatChargPrice + chargPile.flatServicePrice).toFixed(6));
  44. chargPile.valleyTotalPrice = parseFloat((chargPile.valleyChargPrice + chargPile.valleyServicePrice).toFixed(6));
  45. chargPile.totalprice = parseFloat((chargPile.chargprice + chargPile.serviceprice).toFixed(6));
  46. that.setData({
  47. chargPile
  48. });
  49. //console.log(chargPile);
  50. // 更新是否减停车费
  51. that.execParking(that,chargPile)
  52. wx.removeStorage({
  53. key: 'scan_chargpile',
  54. success(res) {
  55. console.log(res);
  56. }
  57. });
  58. log.info('[扫码]', '[加载完成]', '[参数]', res.data);
  59. let userInfo = wx.getStorageSync('userInfo');
  60. wx.request({
  61. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/syncUser',
  62. data: {
  63. loginName: userInfo.loginName
  64. },
  65. method: 'POST',
  66. success: function (res) {
  67. let {
  68. data
  69. } = res;
  70. log.info('[扫码]', '[同步用户数据]', '[响应]', data);
  71. console.info('[扫码]', '[同步用户数据]', '[响应]', data);
  72. if (data.code && data.code != 200) {
  73. log.info('[扫码]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  74. } else {
  75. that.setData({
  76. repaidbalance:data.repaidbalance
  77. });
  78. }
  79. },
  80. fail(e) {
  81. console.log("用户数据同步失败");
  82. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  83. }
  84. });
  85. }
  86. });
  87. },
  88. execParking(that,chargPile){
  89. let stationId = chargPile.chargStationId;
  90. wx.request({
  91. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carParkingRate?stationId=' + stationId,
  92. // data: {
  93. // loginName: userInfo.loginName
  94. // },
  95. method: 'POST',
  96. success: function (res) {
  97. // 是否减免停车费
  98. // carParkingRate: false,
  99. // parkTime: 0,
  100. console.info(res)
  101. let reduceTime = res.data?.reduceTime;
  102. if(!reduceTime){
  103. that.setData({
  104. carParkingRate:false
  105. })
  106. return;
  107. }
  108. that.setData({
  109. carParkingRate:true
  110. })
  111. try{
  112. that.setData({
  113. parkTime: parseFloat((reduceTime/ 3600).toFixed(2))
  114. })
  115. }catch(e){
  116. that.setData({
  117. carParkingRate:false
  118. })
  119. }
  120. },
  121. fail(e) {
  122. console.log("用户数据同步失败");
  123. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  124. }
  125. });
  126. },
  127. beginChargeInner(that,plateNumber){
  128. let userInfo = wx.getStorageSync('userInfo');
  129. let isLogin = wx.getStorageSync('isLogin');
  130. // 扫码启动
  131. wx.showLoading({
  132. title: '开启充电中...',
  133. mask: true
  134. });
  135. log.info('[扫码]', '[开始充电流程]');
  136. //同步用户数据
  137. log.info('[扫码]', '[同步用户数据]', '[请求]', {
  138. loginName: userInfo.loginName
  139. });
  140. wx.request({
  141. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/syncUser',
  142. data: {
  143. loginName: userInfo.loginName,
  144. },
  145. method: 'POST',
  146. success: function (res) {
  147. wx.hideLoading();
  148. let {
  149. data
  150. } = res;
  151. log.info('[扫码]', '[同步用户数据]', '[响应]', data);
  152. console.info('[扫码]', '[同步用户数据]', '[响应]', data);
  153. if (data.code && data.code != 200) {
  154. wx.removeStorageSync('userInfo');
  155. wx.removeStorageSync('isLogin');
  156. let url = '/pages/login/phone_login/phone_login';
  157. wx.redirectTo({
  158. url,
  159. });
  160. log.info('[扫码]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  161. } else {
  162. wx.setStorageSync('userInfo', data);
  163. wx.setStorageSync('isLogin', true);
  164. let repaidbalance = data.repaidbalance;
  165. that.setData({
  166. repaidbalance
  167. });
  168. //开始充电
  169. if(data.bindingPhone==0){
  170. wx.showModal({
  171. title: '提示',
  172. content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
  173. confirmText: '去登录',
  174. showCancel:false,
  175. confirmColor:'#00AADD',
  176. success: function (res1) {
  177. if (res1.confirm) {
  178. wx.removeStorageSync('userInfo');
  179. wx.removeStorageSync('isLogin');
  180. let url = '/pages/login/phone_login/phone_login';
  181. wx.redirectTo({
  182. url
  183. })
  184. }
  185. }
  186. });
  187. log.info('[扫码]', '[同步用户数据]', '[未绑定手机号]', data);
  188. }else if (!data.repaidbalance || data.repaidbalance <= 0) {
  189. wx.showModal({
  190. showCancel: false,
  191. content: '余额不足,请充值!',
  192. confirmColor:'#00AADD',
  193. success: function (res) {
  194. if (res.confirm) {
  195. let url = "/pages/chargemoney/chargemoney";
  196. wx.navigateTo({
  197. url
  198. });
  199. }
  200. }
  201. });
  202. log.info('[扫码]', '[同步用户数据]', '[data.repaidbalance null||data.repaidbalance<=0余额不足跳转充值界面]', data);
  203. } else if (data.repaidbalance > 0 && data.repaidbalance <= 15) {
  204. wx.showModal({
  205. title: '余额:' + data.repaidbalance + '元',
  206. showCancel: false,
  207. confirmText: "去充值",
  208. confirmColor:'#00AADD',
  209. content: '余额过低,请尽快充值!',
  210. success: function (res) {
  211. if (res.confirm) {
  212. let url = "/pages/chargemoney/chargemoney";
  213. wx.navigateTo({
  214. url
  215. });
  216. }
  217. }
  218. });
  219. log.info('[扫码]', '[同步用户数据]', '[0<data.repaidbalance<=15余额过低]', data);
  220. // wx.showModal({
  221. // title:'请选择',
  222. // showCancel: true,
  223. // confirmText:"继续充电",
  224. // cancelText:"去充值",
  225. // content: '余额过低,请尽快充值!',
  226. // success: function (res) {
  227. // if (res.confirm) {
  228. // that.beginCharge_satrt();
  229. // } else if (res.cancel) {
  230. // let url = "/pages/chargemoney/chargemoney";
  231. // wx.navigateTo({
  232. // url
  233. // });
  234. // }
  235. // }
  236. // });
  237. } else if (data.repaidbalance > 15) {
  238. log.info('[扫码]', '[同步用户数据]', '[余额充足开始充电]', data);
  239. that.beginCharge_satrt(plateNumber,1);
  240. }
  241. }
  242. }
  243. });
  244. // 扫描结束
  245. },
  246. beginChargeMsg(e){
  247. let that = this
  248. wx.requestSubscribeMessage({
  249. tmplIds: ['3FR5XRyycT81ZWMdVi_ZQYKJcVatZr2Tm7DgcLwCD1I','KWHBIONCrdumgTkE1dpIpAZRgrN5TuhpHuZ0uU-Eud4','XWj70eHMLAjLlufPuhE_NQmdSQzhrOwEXIblWveH0bk'],
  250. success (res33333) {
  251. that.beginCharge(e)
  252. },fail(reee){
  253. console.info("ffffffffffffff")
  254. console.info(reee)
  255. }
  256. })
  257. },
  258. beginCharge(e) {
  259. let that = this
  260. let userInfo = wx.getStorageSync('userInfo');
  261. let isLogin = wx.getStorageSync('isLogin');
  262. if(!that.data.carParkingRate){
  263. that.beginChargeInner(that,'');
  264. return;
  265. }
  266. // 读取默认车牌
  267. wx.request({
  268. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carList?loginName=' + userInfo.loginName,
  269. // data: {
  270. // loginName: userInfo.loginName
  271. // },
  272. method: 'POST',
  273. success: function (res) {
  274. let userCarList = res.data;
  275. userCarList = userCarList.filter(it=>it.defaultType==1);
  276. console.info(userCarList)
  277. if(userCarList.length==0 ){
  278. wx.showModal({
  279. title: '提示',
  280. content: '当前充电站可减免停车费,是否绑定车牌信息?',
  281. confirmText: '绑定车牌',
  282. cancelText: '直接启动',
  283. showCancel:true,
  284. confirmColor:'#00AADD',
  285. cancelColor:'#00AADD',
  286. success: function (ress1) {
  287. if(ress1.confirm){
  288. let url = '/pages/ucenter/car/chooseCar'
  289. wx.navigateTo({
  290. url
  291. });
  292. }else{
  293. that.beginChargeInner(that,'')
  294. }
  295. }
  296. });
  297. }else{
  298. let userCar = userCarList[0]
  299. wx.showModal({
  300. title: '提示',
  301. content: '确定使用' + userCar.plateNumber + '车牌信息减免停车费?',
  302. confirmText: '确定',
  303. cancelText: '其他车牌',
  304. showCancel:true,
  305. confirmColor:'#00AADD',
  306. cancelColor:'#00AADD',
  307. success: function (ress1) {
  308. if(ress1.confirm){
  309. that.beginChargeInner(that,userCar.plateNumber)
  310. }else{
  311. let url = '/pages/ucenter/car/chooseCar'
  312. wx.navigateTo({
  313. url
  314. });
  315. }
  316. return;
  317. },
  318. fail: function(res1){
  319. console.info(res1)
  320. }
  321. });
  322. }
  323. },
  324. fail(e) {
  325. console.log("查询车辆失败");
  326. log.info('[查询车辆]','[fail]', e);
  327. }
  328. });
  329. },
  330. beginCharge_satrt(plateNumber,runTimes) {
  331. wx.showLoading({
  332. title: '开启充电中...',
  333. mask: true
  334. });
  335. let that = this;
  336. let terminalNum = this.data.chargPile.chargPileId;
  337. let userInfo = wx.getStorageSync('userInfo');
  338. let isLogin = wx.getStorageSync('isLogin');
  339. console.log(terminalNum);
  340. let userId = userInfo.userId;
  341. let chargstarttime = new Date().getTime();
  342. console.log(chargstarttime);
  343. log.info('[扫码]', '[开始充电]', '[请求]', {
  344. //chargPileId: '201811010000004202',
  345. chargPileId: terminalNum,
  346. userId: userId,
  347. chargstarttime: chargstarttime
  348. });
  349. wx.request({
  350. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/miniprogramadd',
  351. data: {
  352. //chargPileId: '201811010000004202',
  353. chargPileId: terminalNum,
  354. userId: userId,
  355. chargstarttime: chargstarttime,
  356. userPlateNumber: plateNumber,
  357. runTimes:runTimes
  358. },
  359. method: 'POST',
  360. fail(e) {
  361. wx.hideLoading();
  362. //开启充电失败,提示用户
  363. wx.showModal({
  364. showCancel: false,
  365. content: '开启充电失败',
  366. confirmColor:'#00AADD',
  367. });
  368. log.info('[扫码]', '[开始充电]', '[fail]', e);
  369. },
  370. success(res) {
  371. wx.hideLoading();
  372. let {
  373. data
  374. } = res;
  375. log.info('[扫码]', '[开始充电]', '[响应]', data);
  376. if (data && data.code == 200) {
  377. //if (data && data.code == 200 && data.orderid) {
  378. //开启充电成功,跳转到正在充电界面
  379. let {
  380. orderid
  381. } = data;
  382. log.info('[扫码]', '[开始充电]', '[成功,跳转充电中页面]', data);
  383. //console.log(this.data.city);
  384. let url = `/pages/charging/charging?orderid=${orderid}&userId=${userId}&chargPileId=${terminalNum}`;
  385. wx.redirectTo({
  386. url
  387. });
  388. } else if (data && data.code == 501) {
  389. //开启充电失败,提示用户
  390. wx.showModal({
  391. showCancel: false,
  392. content: '余额不足,请充值!',
  393. confirmColor:'#00AADD',
  394. });
  395. log.info('[扫码]', '[开始充电]', '[失败data.code=501余额不足]', data);
  396. } else if (data && data.code == 502) {
  397. //开启充电失败,提示用户
  398. wx.showModal({
  399. showCancel: false,
  400. content: data.message,
  401. confirmColor:'#00AADD',
  402. });
  403. log.info('[扫码]', '[开始充电]', '[失败data.code=502' + data.message + ']', data);
  404. } else if (data && data.code == 503) {
  405. //开启充电失败,提示用户
  406. let msg = res?.data?.message
  407. wx.showModal({
  408. title: '提示',
  409. showCancel: true,
  410. content: msg,
  411. cancelText:'其他车辆',
  412. confirmText:'继续启动',
  413. confirmColor:'#00AADD',
  414. cancelColor:'#00AADD',
  415. success: function (res) {
  416. if (res.cancel) {
  417. //点击取消,其他车辆
  418. } else {
  419. //点击确定,继续启动
  420. that.beginCharge_satrt(plateNumber,runTimes + 1)
  421. }
  422. },
  423. fail: function (res) { },//接口调用失败的回调函数
  424. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  425. });
  426. log.info('[扫码]', '[开始充电]', '[失败data.code=502' + data.message + ']', data);
  427. } else {
  428. //开启充电失败,提示用户
  429. let msg = res?.data?.message
  430. msg = msg?msg:'开启充电失败'
  431. wx.showModal({
  432. showCancel: false,
  433. content: msg,
  434. confirmColor:'#00AADD',
  435. });
  436. log.info('[扫码]', '[开始充电]', '[失败]', data);
  437. }
  438. }
  439. });
  440. },
  441. previewImage(e){
  442. let cur = e.target.dataset.src;//获取本地一张图片链接
  443. console.info(cur)
  444. wx.previewImage({
  445. current: cur, //字符串,默认显示urls的第一张
  446. urls: [cur] // 数组,需要预览的图片链接列表
  447. })
  448. },
  449. /**
  450. * 生命周期函数--监听页面初次渲染完成
  451. */
  452. onReady: function () {
  453. },
  454. /**
  455. * 生命周期函数--监听页面显示
  456. */
  457. onShow: function () {
  458. let car = wx.getStorageSync('chooseCar_plateNumber')
  459. let plateNumber = ''
  460. if(car){
  461. plateNumber = car.plateNumber;
  462. wx.removeStorageSync('chooseCar_plateNumber')
  463. }
  464. this.setData({
  465. plateNumber
  466. })
  467. console.info('将会自动跳过弹窗,默认车牌号:' + plateNumber)
  468. if(car){
  469. this.beginChargeInner(this,plateNumber)
  470. }
  471. },
  472. /**
  473. * 生命周期函数--监听页面隐藏
  474. */
  475. onHide: function () {
  476. },
  477. /**
  478. * 生命周期函数--监听页面卸载
  479. */
  480. onUnload: function () {
  481. },
  482. /**
  483. * 页面相关事件处理函数--监听用户下拉动作
  484. */
  485. onPullDownRefresh: function () {
  486. },
  487. /**
  488. * 页面上拉触底事件的处理函数
  489. */
  490. onReachBottom: function () {
  491. },
  492. /**
  493. * 用户点击右上角分享
  494. */
  495. onShareAppMessage: function () {
  496. }
  497. })