charging.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. Page({
  50. /**
  51. * 页面的初始数据
  52. */
  53. data: {
  54. orderid: null,
  55. userId: null,
  56. chargPileId: null,
  57. chargingRate: 0,
  58. chargingTime: '',
  59. yczds:'',
  60. totalMoney:'',
  61. cdscdy:0,
  62. cdscdl:0,
  63. chargingOrder: null,
  64. chargPile: null,
  65. ec: {
  66. onInit: initChart
  67. }
  68. },
  69. drawCircle: function(step) {
  70. var newoption = chart.getOption();
  71. newoption.series[0].data[0] = parseFloat(step / 100.0).toFixed(2);
  72. chart.setOption(newoption, true);
  73. // console.info(newoption)
  74. // console.info(step)
  75. // console.info(newoption.series[0].data[0])
  76. },
  77. stopCharging(e) {
  78. wx.showLoading({
  79. title: '结束充电中...',
  80. mask: true
  81. });
  82. clearInterval(chargingStatus);
  83. let {
  84. orderid,
  85. userId,
  86. chargPileId
  87. } = this.data;
  88. log.info('[充电中]', '[结束充电]', '[请求]', {
  89. chargPileId,
  90. userId,
  91. orderid
  92. });
  93. wx.request({
  94. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/chargstop',
  95. data: {
  96. chargPileId,
  97. userId,
  98. orderid
  99. },
  100. method: 'POST',
  101. success(res) {
  102. wx.hideLoading();
  103. let {
  104. data
  105. } = res;
  106. log.info('[充电中]', '[结束充电]', '[响应]', data);
  107. if (data && data.code == 200) {
  108. //wx.showModal({
  109. //showCancel: false,
  110. //content: '结束充电成功'
  111. //});
  112. log.info('[充电中]', '[结束充电]', '[成功跳转订单支付界面]', data);
  113. let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`;
  114. setTimeout(()=>{
  115. wx.redirectTo({
  116. url
  117. });
  118. },3000)
  119. } else {
  120. log.info('[充电中]', '[结束充电]', '[失败data null||data.code<>200]', data);
  121. wx.showModal({
  122. showCancel: false,
  123. content: '结束充电失败'
  124. });
  125. }
  126. },
  127. fail(err){
  128. wx.hideLoading();
  129. wx.showModal({
  130. showCancel: false,
  131. content: '结束充电失败'
  132. });
  133. log.info('[充电中]', '[结束充电]', '[fail]', err );
  134. }
  135. });
  136. },
  137. showChargingPng1() {
  138. var i = 0;
  139. let that = this;
  140. if (that.data.chargingOrder && that.data.chargingOrder.soc && that.data.chargingOrder.soc != 0) {
  141. chargingPng = setInterval(function() {
  142. if (i <= that.data.chargingOrder.soc) {
  143. that.drawCircle(i);
  144. that.setData({
  145. chargingRate: i
  146. });
  147. i++;
  148. } else {
  149. //console.log(chargingPng);
  150. clearInterval(chargingPng);
  151. }
  152. }, 20);
  153. }
  154. },
  155. showChargingPng() {
  156. if (this.data.chargingOrder && this.data.chargingOrder.soc && this.data.chargingOrder.soc != 0) {
  157. this.drawCircle(this.data.chargingOrder.soc);
  158. this.setData({
  159. chargingRate: this.data.chargingOrder.soc
  160. });
  161. }
  162. },
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function(options) {
  167. //console.log(options);
  168. let {
  169. orderid,
  170. userId,
  171. chargPileId
  172. } = options;
  173. log.info('[充电中]', '[加载完成]', '[参数]', {
  174. orderid,
  175. userId,
  176. chargPileId
  177. });
  178. this.setData({
  179. orderid,
  180. userId,
  181. chargPileId
  182. });
  183. if (!orderid||orderid=="null"){
  184. orderid=undefined;
  185. }
  186. let that = this;
  187. log.info('[充电中]', '[获取订单状态]', '[请求]', {
  188. chargPileId,
  189. userId,
  190. orderid
  191. });
  192. wx.request({
  193. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  194. data: {
  195. chargPileId,
  196. userId,
  197. orderid
  198. },
  199. method: 'POST',
  200. success(res) {
  201. let {
  202. data
  203. } = res;
  204. log.info('[充电中]', '[获取订单状态]', '[响应]', data);
  205. if (data && data.code == 200) {
  206. let {
  207. result: chargingOrder
  208. } = data;
  209. let {
  210. chargPileId,
  211. soc: chargingRate
  212. } = chargingOrder;
  213. let orderid_r = chargingOrder.orderid;
  214. //console.log(chargingOrder);
  215. log.info('[充电中]', '[获取充电桩]', '[请求]', chargPileId);
  216. wx.request({
  217. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  218. // data: chargPileId,
  219. data:{
  220. chargPileId:chargPileId,
  221. userId: userId
  222. },
  223. method: 'POST',
  224. success(res1) {
  225. //console.log(res1.data);
  226. res1.data = res1.data.result
  227. if (res1.data) {
  228. let {
  229. data: chargPile
  230. } = res1;
  231. log.info('[充电中]', '[获取充电桩]', '[响应]', chargPile);
  232. that.setData({
  233. chargPile
  234. });
  235. }
  236. }
  237. });
  238. console.log("chargingOrder.chargPileStatus " + chargingOrder.chargPileStatus);
  239. if (chargingOrder.chargPileStatus == 1) { //启动中,继续轮训
  240. log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态1启动中,继续轮训]', data)
  241. that.setData({
  242. chargingOrder,
  243. chargPileId,
  244. orderid: orderid_r
  245. });
  246. } else if (chargingOrder.chargPileStatus == 2) { //充电中,继续轮训
  247. //console.log(chargingOrder.chargPileStatus == 2);
  248. if (chargingOrder.ljcdsj || chargingOrder.ljcdsj == 0) {
  249. var chargingTimeHour = Math.floor(chargingOrder.ljcdsj / 60);
  250. if (chargingTimeHour <= 9) {
  251. chargingTimeHour = '0' + chargingTimeHour;
  252. }
  253. var chargingTimeMinute = chargingOrder.ljcdsj % 60;
  254. if (chargingTimeMinute <= 9) {
  255. chargingTimeMinute = '0' + chargingTimeMinute
  256. }
  257. var chargingTime = chargingTimeHour + ":" + chargingTimeMinute + ":00";
  258. }
  259. var totalMoney = (parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)).toFixed(2);
  260. var cdscdl = parseFloat(chargingOrder.cdscdl).toFixed(2);
  261. var cdscdy = parseFloat(chargingOrder.cdscdy).toFixed(2);
  262. var yczds = parseFloat(chargingOrder.yczds).toFixed(2);
  263. that.setData({
  264. chargingOrder,
  265. chargPileId,
  266. chargingTime,
  267. orderid: orderid_r,
  268. totalMoney,
  269. cdscdl,
  270. cdscdy,
  271. yczds
  272. });
  273. that.showChargingPng();
  274. } else if (chargingOrder.chargPileStatus == 3) { //充电完成,适用于主动拔枪
  275. clearInterval(chargingStatus);
  276. log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  277. let {
  278. orderid,
  279. userId,
  280. chargPileId
  281. } = that.data;
  282. let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`;
  283. wx.redirectTo({
  284. url
  285. });
  286. } else if (chargingOrder.chargPileStatus == 4) { //启动异常,回退界面
  287. clearInterval(chargingStatus);
  288. log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态4启动异常删除订单]', data);
  289. wx.showModal({
  290. showCancel: false,
  291. content: '开启充电失败'
  292. });
  293. that.delOrder(orderid_r);
  294. console.log(orderid_r);
  295. }
  296. } else if (data && data.code == 500) {
  297. console.info("ddddddddddddddddddddddddddd")
  298. console.info(orderid)
  299. console.info(userId)
  300. console.info(chargPileId)
  301. console.info("ddddddddddddddddddddddddddd")
  302. clearInterval(chargingStatus);
  303. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  304. let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`;
  305. wx.redirectTo({
  306. url
  307. });
  308. }else{
  309. console.log(res);
  310. }
  311. },
  312. fail(err) {
  313. // var chargingOrder = {chargStatus:1};
  314. // that.setData({
  315. // chargingOrder
  316. // });
  317. }
  318. });
  319. },
  320. delOrder(orderId){
  321. if (orderId){
  322. log.info('[充电中]', '[删除订单]', '[请求]', { "orderid": orderId });
  323. wx.request({
  324. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/exceptOrder',
  325. data: {"orderid":orderId},
  326. method: 'POST',
  327. success(res1) {
  328. console.log(res1.data);
  329. log.info('[充电中]', '[删除订单]', '[响应]', res1.data);
  330. //if (res1.data ) {
  331. //}
  332. wx.navigateBack();
  333. }
  334. });
  335. }
  336. },
  337. /**
  338. * 生命周期函数--监听页面初次渲染完成
  339. */
  340. onReady: function() {},
  341. /**
  342. * 生命周期函数--监听页面显示
  343. */
  344. onShow: function(e) {
  345. clearInterval(chargingStatus);
  346. this.showChargingPng();
  347. let {
  348. orderid,
  349. userId,
  350. chargPileId
  351. } = this.data;
  352. if (!orderid || orderid == "null") {
  353. orderid = undefined;
  354. }
  355. let that = this;
  356. chargingStatus = setInterval(function() {
  357. let chargPileIdCache = chargPileId;
  358. let userIdCache = userId;
  359. let orderidCache = orderid;
  360. wx.request({
  361. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  362. data: {
  363. chargPileId,
  364. userId,
  365. orderid
  366. },
  367. method: 'POST',
  368. success(res) {
  369. let {
  370. data
  371. } = res;
  372. if (data && data.code == 200) {
  373. let {
  374. result: chargingOrder
  375. } = data;
  376. let {
  377. chargPileId,
  378. soc: chargingRate
  379. } = chargingOrder;
  380. let orderid_r = chargingOrder.orderid;
  381. //console.log(chargingOrder.chargPileStatus);
  382. if (chargingOrder.chargPileStatus == 1) { //启动中,继续轮训
  383. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态1启动中,继续轮训]', data);
  384. that.setData({
  385. chargingOrder,
  386. chargPileId,
  387. orderid: orderid_r
  388. });
  389. } else if (chargingOrder.chargPileStatus == 2) { //充电中,继续轮训
  390. if (chargingOrder.ljcdsj || chargingOrder.ljcdsj == 0) {
  391. var chargingTimeHour = Math.floor(chargingOrder.ljcdsj / 60);
  392. if (chargingTimeHour <= 9) {
  393. chargingTimeHour = '0' + chargingTimeHour;
  394. }
  395. var chargingTimeMinute = chargingOrder.ljcdsj % 60;
  396. if (chargingTimeMinute <= 9) {
  397. chargingTimeMinute = '0' + chargingTimeMinute
  398. }
  399. var chargingTime = chargingTimeHour + ":" + chargingTimeMinute + ":00";
  400. }
  401. var cdscdl = parseFloat(chargingOrder.cdscdl).toFixed(2);
  402. var cdscdy = parseFloat(chargingOrder.cdscdy).toFixed(2);
  403. var totalMoney = (parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)).toFixed(2);
  404. var yczds = parseFloat(chargingOrder.yczds).toFixed(2);
  405. // var orderid = orderid_r;
  406. that.setData({
  407. chargingOrder,
  408. chargPileId,
  409. chargingTime,
  410. chargingRate,
  411. orderid:orderid_r,
  412. cdscdl,
  413. cdscdy,
  414. totalMoney,
  415. yczds
  416. });
  417. that.drawCircle(chargingRate);
  418. console.info("-----------")
  419. console.info(that.data.orderid)
  420. console.info(orderid)
  421. console.info(orderid_r)
  422. console.info("-----------")
  423. } else if (chargingOrder.chargPileStatus == 3) { //充电完成,适用于主动拔枪
  424. clearInterval(chargingStatus);
  425. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  426. let {
  427. orderid,
  428. userId,
  429. chargPileId
  430. } = that.data;
  431. let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`;
  432. wx.redirectTo({
  433. url
  434. });
  435. } else if (chargingOrder.chargPileStatus == 4) { //启动异常,回退界面
  436. clearInterval(chargingStatus);
  437. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态4启动异常删除订单]', data);
  438. wx.showModal({
  439. showCancel: false,
  440. content: '开启充电失败'
  441. });
  442. console.log(orderid_r);
  443. that.delOrder(orderid_r);
  444. }
  445. } else if (data && data.code == 500) {
  446. console.info("ddddddddddddddddddddddddddd")
  447. console.info(that.data.orderid)
  448. console.info(userIdCache)
  449. console.info(chargPileIdCache)
  450. console.info("ddddddddddddddddddddddddddd")
  451. clearInterval(chargingStatus);
  452. log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
  453. let url = `/pages/order/order?orderid=${that.data.orderid}&userId=${userIdCache}&chargPileId=${chargPileIdCache}`;
  454. wx.redirectTo({
  455. url
  456. });
  457. }else{
  458. console.log("2222222222222222222222222222");
  459. console.log(res);
  460. console.log(data);
  461. console.log(data.code);
  462. console.log(data && data.code == 500);
  463. console.log("2222222222222222222222222222");
  464. }
  465. }
  466. });
  467. }, 5000);
  468. },
  469. /**
  470. * 生命周期函数--监听页面隐藏
  471. */
  472. onHide: function() {
  473. clearInterval(chargingStatus);
  474. },
  475. /**
  476. * 生命周期函数--监听页面卸载
  477. */
  478. onUnload: function() {
  479. clearInterval(chargingStatus);
  480. },
  481. /**
  482. * 页面相关事件处理函数--监听用户下拉动作
  483. */
  484. onPullDownRefresh: function() {
  485. },
  486. /**
  487. * 页面上拉触底事件的处理函数
  488. */
  489. onReachBottom: function() {
  490. },
  491. /**
  492. * 用户点击右上角分享
  493. */
  494. onShareAppMessage: function() {
  495. }
  496. })