charging.js 14 KB

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