charging.js 16 KB

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