Переглянути джерело

优化启动充电逻辑;增加回收电池包按钮

jiuling 3 тижнів тому
батько
коміт
bd7dd8f169

+ 2 - 1
pages/charginfo/charginfo.wxml

@@ -126,7 +126,8 @@
     <view wx:if="{{activeTab=='1'}}" class="charg"  hover-class='active' wx:key='{{key}}' wx:for="{{ele_chargList}}" data-idx="{{item}}" bindtap="{{userInfo.flag ?'chargingLog':''}}">
     -->
     <view wx:if="{{activeTab=='1'}}" class="charg"  hover-class='active' wx:key='{{key}}' wx:for="{{ele_chargList}}" data-idx="{{item}}" bindtap="goEleCarMap"> 
-    <!-- <view wx:if="{{activeTab=='1'}}" class="charg"  hover-class='active' wx:key='{{key}}' wx:for="{{ele_chargList}}" data-idx="{{item}}"> 取消机器人详情点击事件 -->
+    <!-- 取消机器人详情点击事件 -->
+    <!-- <view wx:if="{{activeTab=='1'}}" class="charg"  hover-class='active' wx:key='{{key}}' wx:for="{{ele_chargList}}" data-idx="{{item}}">  -->
       <view class="runstatus {{item.chargstatusclass}}">
       <view class="runstatus_inner ">{{item.chargstatusname}}</view>
       </view>

+ 193 - 7
pages/charging/charging.js

@@ -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){

+ 2 - 0
pages/register/register.js

@@ -135,6 +135,8 @@ Page({
             wx.request({
               url: getApp().globalData.postHeadAgreement + '/restapi/wechat/register',
               data: {
+                multipleOrders:0,
+                refund:1,
                 userName,
                 sex:"0",
                 avatar:'http://cdglyy.pjnes.com/web/profile/avatar/c134f314cbbe985a8aae1787b45e6d6a.jpg',

+ 39 - 0
pages/ucenter/control/batteryControl.js

@@ -575,6 +575,45 @@ Page({
         }
       });
 },
+goToRecycle(){
+  wx.showModal({
+    title: '提示', 
+    content: '是否进行电池包回收?',
+    showCancel: true, 
+    cancelText: '取消',
+    confirmText: '确认',
+    confirmColor: '#00AADD',
+    success (res) {
+      if (res.confirm) {
+        console.log('用户点击了确认');
+     wx.request({
+      url: getApp().globalData.postHeadAgreement + '/restapi/wechat/callCarRequirementJob',
+      data:{},
+      method: 'POST',
+      success(res) {
+        console.log("返回结果res:",res);
+        if (!res.data || res.data.code == 1) {
+          wx.showModal({
+            showCancel: false,
+            content: res && res.data && res.data.msg ? res.data.msg :'暂无电池包需要回归补电',
+            confirmColor:'#00AADD',
+          });
+        } else {   
+          wx.showModal({
+            showCancel: false,
+            content: res && res.data && res.data.msg ? res.data.msg :'调用成功',
+            confirmColor:'#00AADD',
+          });
+        }
+      },
+    });
+    }
+    },
+    fail(err) {
+      getApp().showNetworkError();
+    }
+  });
+},
 
 
 

+ 4 - 1
pages/ucenter/control/batteryControl.wxml

@@ -57,6 +57,9 @@
     <view class="vbtn v1" style="margin-top: 20rpx;">
         <button class='btn b1 active' bindtap="goToScanResult" >启动充电</button>
     </view>
-    <view class="vbtn v1"></view>
+    <text class="stitle" >回收电池包</text>
+    <view class="vbtn v1" style="margin-top: 20rpx;">
+      <button class='btn b1 active' bindtap="goToRecycle" >回收电池包</button>
+    </view>
     
 </view>