charging.js 13 KB

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