import * as echarts from '../../ec-canvas/echarts'; import * as lf from '../../ec-canvas/echarts-liquidfill'; let chart = null; function initChart(canvas, width, height, dpr) { chart = echarts.init(canvas, lf, { width: width, height: height, devicePixelRatio: dpr // new }); canvas.setChart(chart); var options111 = { series: [{ type: 'liquidFill', data: [], color: ['#128cec'],//主体填充颜色 center: ['50%', '50%'],//中心位置 radius: '72%',//大小 outline: { show: false }, backgroundStyle: { color: '#cceaff' }, label: { show: true, color: '#128cec', insideColor: '#ffffff', fontSize: 20, fontWeight: 'bold', align: 'center', baseline: 'middle', position: 'inside', formatter: function (p) { //console.log(p); if (isNaN(p.value)) { return '启动充电中'; } return (p.value * 100).toFixed(2) + '%' + '\n' + '当前电量'; } } }] }; chart.setOption(options111); return chart; } let log = require('../../utils/log.js'); var chargingPng; var chargingStatus; Page({ /** * 页面的初始数据 */ data: { orderid: null, userId: null, chargPileId: null, chargingRate: 0, chargingTime: '', yczds:'', totalMoney:'', chargingOrder: null, chargPile: null, ec: { onInit: initChart } }, drawCircle: function(step) { var newoption = chart.getOption(); newoption.series[0].data[0] = parseFloat(step / 100.0).toFixed(2); chart.setOption(newoption, true); }, stopCharging(e) { wx.showLoading({ title: '结束充电中...', mask: true }); clearInterval(chargingStatus); let { orderid, userId, chargPileId } = this.data; log.info('[充电中]', '[结束充电]', '[请求]', { chargPileId, userId, orderid }); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/chargstop', data: { chargPileId, userId, orderid }, method: 'POST', success(res) { wx.hideLoading(); let { data } = res; log.info('[充电中]', '[结束充电]', '[响应]', data); if (data && data.code == 200) { //wx.showModal({ //showCancel: false, //content: '结束充电成功' //}); log.info('[充电中]', '[结束充电]', '[成功跳转订单支付界面]', data); let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`; wx.redirectTo({ url }); } else { log.info('[充电中]', '[结束充电]', '[失败data null||data.code<>200]', data); wx.showModal({ showCancel: false, content: '结束充电失败' }); } }, fail(err){ wx.hideLoading(); wx.showModal({ showCancel: false, content: '结束充电失败' }); log.info('[充电中]', '[结束充电]', '[fail]', err ); } }); }, showChargingPng1() { var i = 0; let that = this; if (that.data.chargingOrder && that.data.chargingOrder.soc && that.data.chargingOrder.soc != 0) { chargingPng = setInterval(function() { if (i <= that.data.chargingOrder.soc) { that.drawCircle(i); that.setData({ chargingRate: i }); i++; } else { //console.log(chargingPng); clearInterval(chargingPng); } }, 20); } }, showChargingPng() { if (this.data.chargingOrder && this.data.chargingOrder.soc && this.data.chargingOrder.soc != 0) { this.drawCircle(this.data.chargingOrder.soc); this.setData({ chargingRate: this.data.chargingOrder.soc }); } }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { //console.log(options); let { orderid, userId, chargPileId } = options; log.info('[充电中]', '[加载完成]', '[参数]', { orderid, userId, chargPileId }); this.setData({ orderid, userId, chargPileId }); if (!orderid||orderid=="null"){ orderid=undefined; } let that = this; log.info('[充电中]', '[获取订单状态]', '[请求]', { chargPileId, userId, orderid }); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus', data: { chargPileId, userId, orderid }, method: 'POST', success(res) { let { data } = res; log.info('[充电中]', '[获取订单状态]', '[响应]', data); if (data && data.code == 200) { let { result: chargingOrder } = data; let { chargPileId, soc: chargingRate } = chargingOrder; let orderid_r = chargingOrder.orderid; //console.log(chargingOrder); log.info('[充电中]', '[获取充电桩]', '[请求]', chargPileId); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile', data: chargPileId, method: 'POST', success(res1) { //console.log(res1.data); if (res1.data) { let { data: chargPile } = res1; log.info('[充电中]', '[获取充电桩]', '[响应]', chargPile); that.setData({ chargPile }); } } }); console.log("chargingOrder.chargPileStatus " + chargingOrder.chargPileStatus); if (chargingOrder.chargPileStatus == 1) { //启动中,继续轮训 log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态1启动中,继续轮训]', data) that.setData({ chargingOrder, chargPileId, orderid: orderid_r }); } else if (chargingOrder.chargPileStatus == 2) { //充电中,继续轮训 //console.log(chargingOrder.chargPileStatus == 2); if (chargingOrder.ljcdsj || chargingOrder.ljcdsj == 0) { var chargingTimeHour = Math.floor(chargingOrder.ljcdsj / 60); if (chargingTimeHour <= 9) { chargingTimeHour = '0' + chargingTimeHour; } var chargingTimeMinute = chargingOrder.ljcdsj % 60; if (chargingTimeMinute <= 9) { chargingTimeMinute = '0' + chargingTimeMinute } var chargingTime = chargingTimeHour + ":" + chargingTimeMinute + ":00"; } var totalMoney = (parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)).toFixed(2); var yczds = parseFloat(chargingOrder.yczds).toFixed(2); that.setData({ chargingOrder, chargPileId, chargingTime, orderid: orderid_r, totalMoney, yczds }); that.showChargingPng(); } else if (chargingOrder.chargPileStatus == 3) { //充电完成,适用于主动拔枪 clearInterval(chargingStatus); log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态3跳转到订单支付界面]', data); let { orderid, userId, chargPileId } = that.data; let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`; wx.redirectTo({ url }); } else if (chargingOrder.chargPileStatus == 4) { //启动异常,回退界面 clearInterval(chargingStatus); log.info('[充电中]', '[初次订单状态判定]', '[chargPileStatus状态4启动异常删除订单]', data); wx.showModal({ showCancel: false, content: '开启充电失败' }); that.delOrder(orderid_r); console.log(orderid_r); } } else { console.log(res); } }, fail(err) { // var chargingOrder = {chargStatus:1}; // that.setData({ // chargingOrder // }); } }); }, delOrder(orderId){ if (orderId){ log.info('[充电中]', '[删除订单]', '[请求]', { "orderid": orderId }); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/exceptOrder', data: {"orderid":orderId}, method: 'POST', success(res1) { console.log(res1.data); log.info('[充电中]', '[删除订单]', '[响应]', res1.data); //if (res1.data ) { //} wx.navigateBack(); } }); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() {}, /** * 生命周期函数--监听页面显示 */ onShow: function(e) { clearInterval(chargingStatus); this.showChargingPng(); let { orderid, userId, chargPileId } = this.data; if (!orderid || orderid == "null") { orderid = undefined; } let that = this; chargingStatus = setInterval(function() { wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus', data: { chargPileId, userId, orderid }, method: 'POST', success(res) { let { data } = res; if (data && data.code == 200) { let { result: chargingOrder } = data; let { chargPileId, soc: chargingRate } = chargingOrder; let orderid_r = chargingOrder.orderid; //console.log(chargingOrder.chargPileStatus); if (chargingOrder.chargPileStatus == 1) { //启动中,继续轮训 log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态1启动中,继续轮训]', data); that.setData({ chargingOrder, chargPileId, orderid: orderid_r }); } else if (chargingOrder.chargPileStatus == 2) { //充电中,继续轮训 if (chargingOrder.ljcdsj || chargingOrder.ljcdsj == 0) { var chargingTimeHour = Math.floor(chargingOrder.ljcdsj / 60); if (chargingTimeHour <= 9) { chargingTimeHour = '0' + chargingTimeHour; } var chargingTimeMinute = chargingOrder.ljcdsj % 60; if (chargingTimeMinute <= 9) { chargingTimeMinute = '0' + chargingTimeMinute } var chargingTime = chargingTimeHour + ":" + chargingTimeMinute + ":00"; } var totalMoney = (parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)).toFixed(2); var yczds = parseFloat(chargingOrder.yczds).toFixed(2); that.setData({ chargingOrder, chargPileId, chargingTime, chargingRate, orderid: orderid_r, totalMoney, yczds }); that.drawCircle(chargingRate); } else if (chargingOrder.chargPileStatus == 3) { //充电完成,适用于主动拔枪 clearInterval(chargingStatus); log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data); let { orderid, userId, chargPileId } = that.data; let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`; wx.redirectTo({ url }); } else if (chargingOrder.chargPileStatus == 4) { //启动异常,回退界面 clearInterval(chargingStatus); log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态4启动异常删除订单]', data); wx.showModal({ showCancel: false, content: '开启充电失败' }); console.log(orderid_r); that.delOrder(orderid_r); } } else { console.log(res); } } }); }, 20000); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { clearInterval(chargingStatus); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { clearInterval(chargingStatus); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })