scan_result.js 15 KB

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