123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- // pages/charging/charging.js
- 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
- },
- drawCircle: function(step) {
- var context = wx.createCanvasContext('canvasProgress');
- context.setLineWidth(4); // 设置圆环的宽度
- // 设置渐变
- //var gradient = context.createLinearGradient(200, 100, 100, 200);
- //gradient.addColorStop("0", "#2661DD");
- //gradient.addColorStop("0.5", "#40ED94");
- //gradient.addColorStop("1.0", "#5956CC");
- context.setLineWidth(this.getSize(20));
- context.setStrokeStyle('#24e383');
- context.setLineCap('round')
- context.beginPath();
- // 参数step 为绘制的圆环周长,从0到2为一周 。 -Math.PI / 2 将起始角设在12点钟位置 ,结束角 通过改变 step 的值确定
- context.arc(this.getSize(100) - 1, this.getSize(100) - 1, this.getSize(90) - 1, -Math.PI / 2, step / (100 / 2) * Math.PI - Math.PI / 2, false);
- context.stroke();
- context.draw()
- },
- getSize: function(v) {
- //console.log(wx.getSystemInfoSync().windowWidth);
- //console.log(v * (wx.getSystemInfoSync().windowWidth / 375));
- return v * (wx.getSystemInfoSync().windowWidth / 375)
- },
- 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 );
- }
- });
- },
- showChargingPng() {
- 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);
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- 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);
- 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;
- 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() {
- }
- })
|