charging.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. import * as echarts from '../../ec-canvas/echarts';
  2. import * as lf from '../../ec-canvas/echarts-liquidfill';
  3. let chart = null;
  4. function initChart(canvas, width, height, dpr) {
  5. chart = echarts.init(canvas, lf, {
  6. width: width,
  7. height: height,
  8. devicePixelRatio: dpr // new
  9. });
  10. canvas.setChart(chart);
  11. var options111 = {
  12. series: [{
  13. type: 'liquidFill',
  14. data: [],
  15. color: ['#128cec'],//主体填充颜色
  16. center: ['50%', '50%'],//中心位置
  17. radius: '72%',//大小
  18. outline: {
  19. show: false
  20. },
  21. backgroundStyle: {
  22. color: '#cceaff'
  23. },
  24. label: {
  25. show: true,
  26. color: '#128cec',
  27. insideColor: '#ffffff',
  28. fontSize: 20,
  29. fontWeight: 'bold',
  30. align: 'center',
  31. baseline: 'middle',
  32. position: 'inside',
  33. formatter: function (p) {
  34. //console.log(p);
  35. if (isNaN(p.value)) {
  36. return '启动充电中';
  37. }
  38. return (p.value * 100).toFixed(2) + '%' + '\n' + '当前电量';
  39. }
  40. }
  41. }]
  42. };
  43. chart.setOption(options111);
  44. return chart;
  45. }
  46. let log = require('../../utils/log.js');
  47. var chargingPng;
  48. var chargingStatus;
  49. var chargingStatusFlag = true;
  50. Page({
  51. /**
  52. * 页面的初始数据
  53. */
  54. data: {
  55. orderid: null,
  56. userId: null,
  57. chargPileId: null,
  58. chargingRate: 0,
  59. chargingTime: '',
  60. yczds:'',
  61. totalMoney:'',
  62. cdscdy:0,
  63. cdscdl:0,
  64. chargingOrder: null,
  65. chargPile: null,
  66. ec: {
  67. onInit: initChart
  68. }
  69. },
  70. drawCircle: function(step) {
  71. var newoption = chart.getOption();
  72. newoption.series[0].data[0] = parseFloat(step / 100.0).toFixed(2);
  73. chart.setOption(newoption, true);
  74. // console.info(newoption)
  75. // console.info(step)
  76. // console.info(newoption.series[0].data[0])
  77. },
  78. stopCharging(e) {
  79. wx.showLoading({
  80. title: '结束充电中...',
  81. mask: true
  82. });
  83. clearInterval(chargingStatus);
  84. let {
  85. orderid,
  86. userId,
  87. chargPileId
  88. } = this.data;
  89. log.info('[充电中]', '[结束充电]', '[请求]', {
  90. chargPileId,
  91. userId,
  92. orderid
  93. });
  94. wx.request({
  95. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/chargstop',
  96. data: {
  97. chargPileId,
  98. userId,
  99. orderid
  100. },
  101. method: 'POST',
  102. success(res) {
  103. wx.hideLoading();
  104. let {
  105. data
  106. } = res;
  107. log.info('[充电中]', '[结束充电]', '[响应]', data);
  108. if (data && data.code == 200) {
  109. //wx.showModal({
  110. //showCancel: false,
  111. //content: '结束充电成功'
  112. //});
  113. log.info('[充电中]', '[结束充电]', '[成功跳转订单支付界面]', data);
  114. let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`;
  115. setTimeout(()=>{
  116. wx.redirectTo({
  117. url
  118. });
  119. },3000)
  120. } else {
  121. log.info('[充电中]', '[结束充电]', '[失败data null||data.code<>200]', data);
  122. wx.showModal({
  123. showCancel: false,
  124. content: '结束充电失败',
  125. confirmColor:'#00AADD',
  126. });
  127. }
  128. },
  129. fail(err){
  130. wx.hideLoading();
  131. wx.showModal({
  132. showCancel: false,
  133. content: '结束充电失败',
  134. confirmColor:'#00AADD',
  135. });
  136. log.info('[充电中]', '[结束充电]', '[fail]', err );
  137. }
  138. });
  139. },
  140. showChargingPng1() {
  141. var i = 0;
  142. let that = this;
  143. if (that.data.chargingOrder && that.data.chargingOrder.soc && that.data.chargingOrder.soc != 0) {
  144. chargingPng = setInterval(function() {
  145. if (i <= that.data.chargingOrder.soc) {
  146. that.drawCircle(i);
  147. that.setData({
  148. chargingRate: i
  149. });
  150. i++;
  151. } else {
  152. //console.log(chargingPng);
  153. clearInterval(chargingPng);
  154. }
  155. }, 20);
  156. }
  157. },
  158. showChargingPng() {
  159. if (this.data.chargingOrder && this.data.chargingOrder.soc && this.data.chargingOrder.soc != 0) {
  160. this.drawCircle(this.data.chargingOrder.soc);
  161. this.setData({
  162. chargingRate: this.data.chargingOrder.soc
  163. });
  164. }
  165. },
  166. /**
  167. * 生命周期函数--监听页面加载
  168. */
  169. onLoad: function(options) {
  170. //console.log(options);
  171. let {
  172. orderid,
  173. userId,
  174. chargPileId
  175. } = options;
  176. log.info('[充电中]', '[加载完成]', '[参数]', {
  177. orderid,
  178. userId,
  179. chargPileId
  180. });
  181. this.setData({
  182. orderid,
  183. userId,
  184. chargPileId
  185. });
  186. if (!orderid||orderid=="null"){
  187. orderid=undefined;
  188. }
  189. let that = this;
  190. log.info('[充电中]', '[获取订单状态]', '[请求]', {
  191. chargPileId,
  192. userId,
  193. orderid
  194. });
  195. wx.request({
  196. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  197. data: {
  198. chargPileId,
  199. userId,
  200. orderid
  201. },
  202. method: 'POST',
  203. success(res) {
  204. let {
  205. data
  206. } = res;
  207. log.info('[充电中]', '[获取订单状态]', '[响应]', data);
  208. if (data && data.code == 200) {
  209. let {
  210. result: chargingOrder
  211. } = data;
  212. let {
  213. chargPileId,
  214. soc: chargingRate
  215. } = chargingOrder;
  216. let orderid_r = chargingOrder.orderid;
  217. //console.log(chargingOrder);
  218. log.info('[充电中]', '[获取充电桩]', '[请求]', chargPileId);
  219. wx.request({
  220. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  221. // data: chargPileId,
  222. data:{
  223. chargPileId:chargPileId,
  224. userId: userId
  225. },
  226. method: 'POST',
  227. success(res1) {
  228. //console.log(res1.data);
  229. res1.data = res1.data.result
  230. if (res1.data) {
  231. let {
  232. data: chargPile
  233. } = res1;
  234. log.info('[充电中]', '[获取充电桩]', '[响应]', chargPile);
  235. that.setData({
  236. chargPile
  237. });
  238. }
  239. }
  240. });
  241. console.log("chargingOrder.chargPileStatus " + chargingOrder.chargPileStatus);
  242. if (chargingOrder.chargPileStatus == 1) { //启动中,继续轮训
  243. log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态1启动中,继续轮训]', data)
  244. that.setData({
  245. chargingOrder,
  246. chargPileId,
  247. orderid: orderid_r
  248. });
  249. } else if (chargingOrder.chargPileStatus == 2) { //充电中,继续轮训
  250. //console.log(chargingOrder.chargPileStatus == 2);
  251. if (chargingOrder.ljcdsj || chargingOrder.ljcdsj == 0) {
  252. var chargingTimeHour = Math.floor(chargingOrder.ljcdsj / 60);
  253. if (chargingTimeHour <= 9) {
  254. chargingTimeHour = '0' + chargingTimeHour;
  255. }
  256. var chargingTimeMinute = chargingOrder.ljcdsj % 60;
  257. if (chargingTimeMinute <= 9) {
  258. chargingTimeMinute = '0' + chargingTimeMinute
  259. }
  260. var chargingTime = chargingTimeHour + ":" + chargingTimeMinute + ":00";
  261. }
  262. var totalMoney = (parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)).toFixed(2);
  263. var cdscdl = parseFloat(chargingOrder.cdscdl).toFixed(2);
  264. var cdscdy = parseFloat(chargingOrder.cdscdy).toFixed(2);
  265. var yczds = parseFloat(chargingOrder.yczds).toFixed(2);
  266. that.setData({
  267. chargingOrder,
  268. chargPileId,
  269. chargingTime,
  270. orderid: orderid_r,
  271. totalMoney,
  272. cdscdl,
  273. cdscdy,
  274. yczds
  275. });
  276. that.showChargingPng();
  277. } else if (chargingOrder.chargPileStatus == 3) { //充电完成,适用于主动拔枪
  278. clearInterval(chargingStatus);
  279. log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  280. let {
  281. orderid,
  282. userId,
  283. chargPileId
  284. } = that.data;
  285. let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`;
  286. wx.redirectTo({
  287. url
  288. });
  289. } else if (chargingOrder.chargPileStatus == 4) { //启动异常,回退界面
  290. clearInterval(chargingStatus);
  291. log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态4启动异常删除订单]', data);
  292. wx.showModal({
  293. showCancel: false,
  294. content: '开启充电失败',
  295. confirmColor:'#00AADD',
  296. });
  297. that.delOrder(orderid_r);
  298. console.log(orderid_r);
  299. }
  300. } else if (data && data.code == 500) {
  301. // console.info("ddddddddddddddddddddddddddd")
  302. // console.info(orderid)
  303. // console.info(userId)
  304. // console.info(chargPileId)
  305. // console.info("ddddddddddddddddddddddddddd")
  306. clearInterval(chargingStatus);
  307. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  308. let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`;
  309. wx.redirectTo({
  310. url
  311. });
  312. }else{
  313. console.log(res);
  314. }
  315. },
  316. fail(err) {
  317. // var chargingOrder = {chargStatus:1};
  318. // that.setData({
  319. // chargingOrder
  320. // });
  321. }
  322. });
  323. },
  324. delOrder(orderId){
  325. // if (orderId){
  326. if (false){
  327. log.info('[充电中]', '[删除订单]', '[请求]', { "orderid": orderId });
  328. wx.request({
  329. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/exceptOrder',
  330. data: {"orderid":orderId},
  331. method: 'POST',
  332. success(res1) {
  333. console.log(res1.data);
  334. log.info('[充电中]', '[删除订单]', '[响应]', res1.data);
  335. //if (res1.data ) {
  336. //}
  337. wx.navigateBack();
  338. }
  339. });
  340. }
  341. },
  342. /**
  343. * 生命周期函数--监听页面初次渲染完成
  344. */
  345. onReady: function() {},
  346. /**
  347. * 生命周期函数--监听页面显示
  348. */
  349. onShow: function(e) {
  350. clearInterval(chargingStatus);
  351. this.showChargingPng();
  352. let {
  353. orderid,
  354. userId,
  355. chargPileId
  356. } = this.data;
  357. if (!orderid || orderid == "null") {
  358. orderid = undefined;
  359. }
  360. let that = this;
  361. chargingStatus = setInterval(function() {
  362. if(!chargingStatusFlag){
  363. return;
  364. }
  365. let chargPileIdCache = chargPileId;
  366. let userIdCache = userId;
  367. let orderidCache = orderid;
  368. wx.request({
  369. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  370. data: {
  371. chargPileId,
  372. userId,
  373. orderid
  374. },
  375. method: 'POST',
  376. success(res) {
  377. let {
  378. data
  379. } = res;
  380. if (data && data.code == 200) {
  381. let {
  382. result: chargingOrder
  383. } = data;
  384. let {
  385. chargPileId,
  386. soc: chargingRate
  387. } = chargingOrder;
  388. let orderid_r = chargingOrder.orderid;
  389. //console.log(chargingOrder.chargPileStatus);
  390. if (chargingOrder.chargPileStatus == 1) { //启动中,继续轮训
  391. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态1启动中,继续轮训]', data);
  392. that.setData({
  393. chargingOrder,
  394. chargPileId,
  395. orderid: orderid_r
  396. });
  397. } else if (chargingOrder.chargPileStatus == 2) { //充电中,继续轮训
  398. if (chargingOrder.ljcdsj || chargingOrder.ljcdsj == 0) {
  399. var chargingTimeHour = Math.floor(chargingOrder.ljcdsj / 60);
  400. if (chargingTimeHour <= 9) {
  401. chargingTimeHour = '0' + chargingTimeHour;
  402. }
  403. var chargingTimeMinute = chargingOrder.ljcdsj % 60;
  404. if (chargingTimeMinute <= 9) {
  405. chargingTimeMinute = '0' + chargingTimeMinute
  406. }
  407. var chargingTime = chargingTimeHour + ":" + chargingTimeMinute + ":00";
  408. }
  409. var cdscdl = parseFloat(chargingOrder.cdscdl).toFixed(2);
  410. var cdscdy = parseFloat(chargingOrder.cdscdy).toFixed(2);
  411. var totalMoney = (parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)).toFixed(2);
  412. var yczds = parseFloat(chargingOrder.yczds).toFixed(2);
  413. // var orderid = orderid_r;
  414. that.setData({
  415. chargingOrder,
  416. chargPileId,
  417. chargingTime,
  418. chargingRate,
  419. orderid:orderid_r,
  420. cdscdl,
  421. cdscdy,
  422. totalMoney,
  423. yczds
  424. });
  425. that.drawCircle(chargingRate);
  426. console.info("-----------")
  427. console.info(that.data.orderid)
  428. console.info(orderid)
  429. console.info(orderid_r)
  430. console.info("-----------")
  431. } else if (chargingOrder.chargPileStatus == 3) { //充电完成,适用于主动拔枪
  432. clearInterval(chargingStatus);
  433. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  434. let {
  435. orderid,
  436. userId,
  437. chargPileId
  438. } = that.data;
  439. let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`;
  440. wx.redirectTo({
  441. url
  442. });
  443. } else if (chargingOrder.chargPileStatus == 4) { //启动异常,回退界面
  444. clearInterval(chargingStatus);
  445. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态4启动异常删除订单]', data);
  446. wx.showModal({
  447. showCancel: false,
  448. content: '开启充电失败',
  449. confirmColor:'#00AADD',
  450. });
  451. console.log(orderid_r);
  452. that.delOrder(orderid_r);
  453. } else if (chargingOrder.chargPileStatus == 5) { //订单被删除
  454. clearInterval(chargingStatus);
  455. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态5订单被删除]', data);
  456. wx.showModal({
  457. showCancel: false,
  458. content: '开启充电失败',
  459. confirmColor:'#00AADD',
  460. });
  461. console.log(orderid_r);
  462. that.delOrder(orderid_r);
  463. }
  464. } else if (data && data.code == 500) {
  465. if(data.msg == '没有充电桩实时充电状态'){
  466. let url = `/pages/index/index`;
  467. wx.reLaunch({
  468. url
  469. });
  470. }
  471. // console.info("ddddddddddddddddddddddddddd")
  472. // console.info(that.data.orderid)
  473. // console.info(userIdCache)
  474. // console.info(chargPileIdCache)
  475. // console.info("ddddddddddddddddddddddddddd")
  476. clearInterval(chargingStatus);
  477. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  478. let url = `/pages/order/order?orderid=${that.data.orderid}&userId=${userIdCache}&chargPileId=${chargPileIdCache}`;
  479. wx.redirectTo({
  480. url
  481. });
  482. }else{
  483. console.log("2222222222222222222222222222");
  484. console.log(res);
  485. console.log(data);
  486. console.log(data.code);
  487. console.log(data && data.code == 500);
  488. console.log("2222222222222222222222222222");
  489. }
  490. }
  491. });
  492. }, 5000);
  493. // }, 5000);
  494. },
  495. phoneCall(e) {
  496. wx.makePhoneCall({
  497. phoneNumber: getApp().globalData.helpPhoneNum
  498. });
  499. },
  500. exceptionWarn(){
  501. let userInfo = wx.getStorageSync('userInfo');
  502. let isLogin = wx.getStorageSync('isLogin');
  503. let that = this;
  504. wx.showModal({
  505. title: '提示',
  506. content: '如果您无法正常结束充电,请提交申诉(一小时内最多提交两次)',
  507. confirmText: '提交',
  508. showCancel:true,
  509. confirmColor:'#00AADD',
  510. cancelColor:'#00AADD',
  511. success: function (res1) {
  512. if(!res1.confirm){
  513. return;
  514. }
  515. chargingStatusFlag = false;
  516. wx.request({
  517. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/applyDeleteChargPileLog',
  518. data: {
  519. loginName: userInfo.loginName,
  520. orderid:that.data.orderid
  521. },
  522. method: 'POST',
  523. success: function (res) {
  524. console.info(res);
  525. if(res.data.code == 200){
  526. clearInterval(chargingStatus);
  527. chargingStatusFlag = false;
  528. wx.showModal({
  529. title: '提示',
  530. content: '申诉成功,异常订单已删除',
  531. confirmColor:'#00AADD',
  532. showCancel: false,
  533. success: function (res1) {
  534. if (res1.confirm) {
  535. let url = `/pages/index/index`;
  536. wx.reLaunch({
  537. url
  538. });
  539. }
  540. }
  541. })
  542. }else{
  543. chargingStatusFlag = true;
  544. console.info(res.data.msg)
  545. wx.showModal({
  546. title: '提示',
  547. content: '申诉失败, ' + res.data.msg + '。如有疑问请拨打客服电话4009608068',
  548. confirmColor:'#00AADD',
  549. showCancel: false,
  550. // success: function (res1) {
  551. // if (res1.confirm) {
  552. // wx.switchTab({
  553. // url: '/pages/index/index'
  554. // })
  555. // }
  556. // }
  557. })
  558. }
  559. },
  560. fail(e) {
  561. chargingStatusFlag = true;
  562. console.log("删除车辆失败");
  563. log.info('[删除车辆]','[fail]', e);
  564. }
  565. });
  566. }
  567. });
  568. },
  569. /**
  570. * 生命周期函数--监听页面隐藏
  571. */
  572. onHide: function() {
  573. clearInterval(chargingStatus);
  574. },
  575. /**
  576. * 生命周期函数--监听页面卸载
  577. */
  578. onUnload: function() {
  579. clearInterval(chargingStatus);
  580. },
  581. /**
  582. * 页面相关事件处理函数--监听用户下拉动作
  583. */
  584. onPullDownRefresh: function() {
  585. },
  586. /**
  587. * 页面上拉触底事件的处理函数
  588. */
  589. onReachBottom: function() {
  590. },
  591. /**
  592. * 用户点击右上角分享
  593. */
  594. onShareAppMessage: function() {
  595. }
  596. })