|
@@ -171,9 +171,159 @@ Page({
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
+ // // 抽取的核心逻辑,封装Promise
|
|
|
+ // fetchOrderStatus(chargPileId, userId, orderid) {
|
|
|
+ // const 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);
|
|
|
+ // // data.code = 500
|
|
|
+ // if (data && data.code === 200) {
|
|
|
+ // let { result: chargingOrder } = data;
|
|
|
+ // let { chargPileId } = chargingOrder;
|
|
|
+ // let orderid_r = chargingOrder.orderid;
|
|
|
+
|
|
|
+ // // 顺序执行:先获取充电桩信息再处理订单状态
|
|
|
+ // that.fetchChargPile(chargPileId, userId)
|
|
|
+ // .then((chargPile) => {
|
|
|
+ // log.info('[充电中]', '[获取充电桩完成,开始处理订单状态]', { chargPile });
|
|
|
+ // that.handleOrderStatus(chargingOrder, orderid_r, chargPileId, chargPile);
|
|
|
+ // })
|
|
|
+ // .catch((err) => {
|
|
|
+ // log.error('[充电中]', '[获取充电桩失败]', err);
|
|
|
+ // });
|
|
|
+ // } else if (data && data.code === 500) {
|
|
|
+ // console.log("data.code为500",data.code);
|
|
|
+ // // clearInterval(chargingStatus);
|
|
|
+ // log.info('[充电中]', '[充电轮训]', '[再次尝试获取订单状态]', data);
|
|
|
+
|
|
|
+ // // 再次调用 fetchOrderStatus
|
|
|
+ // // that.fetchOrderStatus(chargPileId, userId, orderid);
|
|
|
+ // } else {
|
|
|
+ // console.log(res);
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // log.error('[充电中]', '[获取订单状态失败]', err);
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ // // 获取充电桩信息(返回 Promise)
|
|
|
+ // fetchChargPile(chargPileId, userId) {
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // log.info('[充电中]', '[获取充电桩]', '[请求]', { chargPileId, userId });
|
|
|
+ // wx.request({
|
|
|
+ // url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
|
|
|
+ // data: { chargPileId, userId },
|
|
|
+ // method: 'POST',
|
|
|
+ // success(res) {
|
|
|
+ // let chargPile = res.data.result;
|
|
|
+ // if (chargPile) {
|
|
|
+ // log.info('[充电中]', '[获取充电桩]', '[响应]', chargPile);
|
|
|
+ // resolve(chargPile);
|
|
|
+ // } else {
|
|
|
+ // reject(new Error('获取充电桩数据失败'));
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // reject(err);
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ // // 根据订单状态处理逻辑(返回 Promise)
|
|
|
+ // handleOrderStatus(chargingOrder, orderid_r, chargPileId, chargPile) {
|
|
|
+ // const that = this;
|
|
|
+
|
|
|
+ // return new Promise((resolve) => {
|
|
|
+ // if (chargingOrder.chargPileStatus === 1) {
|
|
|
+ // log.info('[充电中]', '[订单状态]', '[状态1:启动中,继续轮训]', chargingOrder);
|
|
|
+ // that.setData({
|
|
|
+ // chargingOrder,
|
|
|
+ // chargPileId,
|
|
|
+ // orderid: orderid_r,
|
|
|
+ // chargPile,
|
|
|
+ // });
|
|
|
+ // resolve();
|
|
|
+ // } else if (chargingOrder.chargPileStatus === 2) {
|
|
|
+ // let chargingTime = that.formatChargingTime(chargingOrder.ljcdsj);
|
|
|
+ // let totalMoney = (
|
|
|
+ // parseFloat(chargingOrder.ycdfje) + parseFloat(chargingOrder.ycfwfje)
|
|
|
+ // ).toFixed(2);
|
|
|
+ // let cdscdl = parseFloat(chargingOrder.cdscdl).toFixed(2);
|
|
|
+ // let cdscdy = parseFloat(chargingOrder.cdscdy).toFixed(2);
|
|
|
+ // let yczds = parseFloat(chargingOrder.yczds).toFixed(2);
|
|
|
+
|
|
|
+ // that.setData({
|
|
|
+ // chargingOrder,
|
|
|
+ // chargPileId,
|
|
|
+ // chargingTime,
|
|
|
+ // orderid: orderid_r,
|
|
|
+ // totalMoney,
|
|
|
+ // cdscdl,
|
|
|
+ // cdscdy,
|
|
|
+ // yczds,
|
|
|
+ // chargPile,
|
|
|
+ // });
|
|
|
+ // that.showChargingPng();
|
|
|
+ // resolve();
|
|
|
+ // } else if (chargingOrder.chargPileStatus === 3) {
|
|
|
+ // clearInterval(chargingStatus);
|
|
|
+ // log.info('[充电中]', '[订单状态]', '[状态3:跳转到订单支付界面]', chargingOrder);
|
|
|
+
|
|
|
+ // let { userId } = that.data;
|
|
|
+ // let url = `/pages/order/order?orderid=${orderid_r}&userId=${userId}&chargPileId=${chargPileId}`;
|
|
|
+ // wx.redirectTo({ url });
|
|
|
+ // resolve();
|
|
|
+ // } else if (chargingOrder.chargPileStatus === 4) {
|
|
|
+ // clearInterval(chargingStatus);
|
|
|
+ // log.info('[充电中]', '[订单状态]', '[状态4:启动异常,删除订单]', chargingOrder);
|
|
|
+
|
|
|
+ // wx.showModal({
|
|
|
+ // showCancel: false,
|
|
|
+ // content: '开启充电失败',
|
|
|
+ // confirmColor: '#00AADD',
|
|
|
+ // });
|
|
|
+ // that.delOrder(orderid_r);
|
|
|
+ // resolve();
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ // // 格式化充电时间
|
|
|
+ // formatChargingTime(minutes) {
|
|
|
+ // let chargingTimeHour = Math.floor(minutes / 60);
|
|
|
+ // if (chargingTimeHour <= 9) {
|
|
|
+ // chargingTimeHour = '0' + chargingTimeHour;
|
|
|
+ // }
|
|
|
+ // let chargingTimeMinute = minutes % 60;
|
|
|
+ // if (chargingTimeMinute <= 9) {
|
|
|
+ // chargingTimeMinute = '0' + chargingTimeMinute;
|
|
|
+ // }
|
|
|
+ // return `${chargingTimeHour}:${chargingTimeMinute}:00`;
|
|
|
+ // },
|
|
|
+ // onLoad: function(options) {
|
|
|
+ // let { orderid, userId, chargPileId } = options;
|
|
|
+ // log.info('[充电中]', '[加载完成]', '[参数]', { orderid, userId, chargPileId });
|
|
|
+
|
|
|
+ // this.setData({ orderid, userId, chargPileId });
|
|
|
+ // if (!orderid || orderid === "null") {
|
|
|
+ // orderid = undefined;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // this.fetchOrderStatus(chargPileId, userId, orderid);
|
|
|
+ // },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
+ */
|
|
|
onLoad: function(options) {
|
|
|
//console.log(options);
|
|
|
let {
|
|
@@ -213,7 +363,7 @@ Page({
|
|
|
let {
|
|
|
data
|
|
|
} = res;
|
|
|
-
|
|
|
+ // data.code = 500
|
|
|
log.info('[充电中]', '[获取订单状态]', '[响应]', data);
|
|
|
if (data && data.code == 200) {
|
|
|
let {
|
|
@@ -309,17 +459,52 @@ Page({
|
|
|
console.log(orderid_r);
|
|
|
}
|
|
|
} else if (data && data.code == 500) {
|
|
|
+ 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,
|
|
|
+ data:{
|
|
|
+ chargPileId:chargPileId,
|
|
|
+ userId: userId
|
|
|
+ },
|
|
|
+ method: 'POST',
|
|
|
+ success(res1) {
|
|
|
+ //console.log(res1.data);
|
|
|
+ res1.data = res1.data.result
|
|
|
+ if (res1.data) {
|
|
|
+ let {
|
|
|
+ data: chargPile
|
|
|
+ } = res1;
|
|
|
+ log.info('[充电中]', '[获取充电桩]', '[响应]', chargPile);
|
|
|
+ that.setData({
|
|
|
+ chargPile
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log("进入");
|
|
|
// console.info("ddddddddddddddddddddddddddd")
|
|
|
// console.info(orderid)
|
|
|
// console.info(userId)
|
|
|
// console.info(chargPileId)
|
|
|
// console.info("ddddddddddddddddddddddddddd")
|
|
|
- clearInterval(chargingStatus);
|
|
|
+ // 取消跳转逻辑
|
|
|
+ // clearInterval(chargingStatus);
|
|
|
log.info('[充电中]', '[充电轮训]', '[chargPileStatus状态3跳转到订单支付界面]', data);
|
|
|
- let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`;
|
|
|
- wx.redirectTo({
|
|
|
- url
|
|
|
- });
|
|
|
+ // let url = `/pages/order/order?orderid=${orderid}&userId=${userId}&chargPileId=${chargPileId}`;
|
|
|
+ // wx.redirectTo({
|
|
|
+ // url
|
|
|
+ // });
|
|
|
}else{
|
|
|
console.log(res);
|
|
|
}
|
|
@@ -332,6 +517,7 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
delOrder(orderId){
|
|
|
// if (orderId){
|
|
|
if (false){
|