Forráskód Böngészése

Merge branch 'occupy' of http://39.98.84.232:3000/CDZ/wechat-pilelog into V2.0

jiuling 2 hónapja
szülő
commit
3af7453669

+ 14 - 6
components/parking-info/parking-info.js

@@ -5,10 +5,11 @@ Component({
     occupyFee:{
       type: Object,
         value:{
-          cost_cycle:0,
-          max_fee_time:0,
-          cost_time_period:'',
-          free_time:0
+          costCycle:0,
+          maxFee:0,
+          costTimePeriod:'',
+          freeTime:0,
+          // capping:0
         }
     }
   },
@@ -23,8 +24,15 @@ Component({
   methods: {
     // 组件的方法
     initData() {
-      const { cost_cycle, max_fee_time, cost_time_period, free_time } = this.data.occupyFee;
-      console.log("this.occupyFee",this.data);
+      // let occupyFee = this.data.occupyFee;
+
+      // let capping = (Math.floor((occupyFee.maxFeeTime / occupyFee.costCycle)) * occupyFee.costCycleFee);
+
+      // 更新数据
+      // this.setData({
+      //     'occupyFee.capping': capping
+      // });
+      // console.log("this.occupyFee",this.data);
     }
   }
 })

+ 5 - 3
components/parking-info/parking-info.wxml

@@ -8,16 +8,18 @@
     </view>
     <!-- 费用信息 -->
     <view class="fee-info">
-      <view class="fee-rate">{{occupyFee.cost_cycle}}元/分钟 单次封顶{{occupyFee.max_fee_time}}元/次</view>
+      <view class="fee-rate">{{occupyFee.costCycleFee}}元/{{occupyFee.costCycle}}分钟
+          <text style="display: inline; font-size: 22rpx; font-family: none;" wx:if='{{occupyFee.maxFee > 0}}'>单次封顶{{occupyFee.maxFee}}元/次</text>
+      </view>
     </view>
     <!-- 时间信息 -->
     <view class="time-info">
       <view class="time-label">收费时段:</view>
-      <view class="time-value">{{occupyFee.cost_time_period}}</view>
+      <view class="time-value">{{occupyFee.costTimePeriod}}</view>
     </view>
     <!-- 提示信息 -->
     <view class="notice-block">
-      <view class="notice-text">充电结束{{occupyFee.free_time}}分钟未挪车,将按占用时长收取超时占位费</view>
+      <view class="notice-text">充电结束{{occupyFee.freeTime}}分钟未挪车,将按占用时长收取超时占位费</view>
     </view>
   </view>
   <!-- 费用说明 -->

+ 182 - 7
components/parking-order/parking-order.js

@@ -8,28 +8,186 @@ Component({
     occupyOrder:{
       type: Array,
       value: [] 
+    },
+    showPopup:{
+      type: Boolean,
+      value: false 
     }
   },
   lifetimes:{
     attached(){
+      console.log("加载占位中订单组件");
+      // this.loadOccupyOrder();
       // 页面加载时显示弹窗
-      this.setData({
-        showPopup: true
-      });
+      let isLogin = wx.getStorageSync('isLogin');
+      if (isLogin) {
+        this.loadOccupyOrder().then(data => {
+           this.fetchData();
+        })
+        .catch(error => {
+          console.error("数据加载失败", error);
+        });
+        
+      }
+    },
+    detached: function() {
+      // 在组件实例被从页面节点树移除时执行
+      this.stopPolling();
+    },
+  },
+  pageLifetimes:{
+    // 组件所在页面的生命周期函数
+    show: function () {
+      let isLogin = wx.getStorageSync('isLogin');
+      if (isLogin) {
+        if (this.data.pollingInterval) {
+          this.stopPolling();
+      }
+  
+      const executePolling = () => {
+          console.log("执行定时器");
+          this.loadOccupyOrder().then(data => {
+              console.log("hhhh", data);
+              if (data.code === 500) {
+                  // 无占位费订单
+                  this.stopPolling();
+                  return;
+              }
+              this.fetchData();
+          });
+      };
+  
+      // 立即执行一次
+      executePolling();
+  
+      // 设置定时器
+      this.data.pollingInterval = setInterval(executePolling, 30000);
     }
   },
-
+     hide: function() {
+      // 页面被隐藏
+      this.stopPolling();
+    },
+  },
   /**
    * 组件的初始数据
    */
   data: {
-    showPopup: true,
+    showPopup: false,
+    occupyFeeOrderList:[],
+    pollingInterval: null, // 定时器,
+    costCycleFee:0,
+    template:{}
   },
 
   /**
    * 组件的方法列表
    */
   methods: {
+ fetchData() {
+  let that = this;
+  let occupyFeeOrder = that.data.occupyFeeOrderList[0];
+  console.log("occupyFeeOrder",occupyFeeOrder);
+  // 如果 occupyFeeOrder 不存在,直接返回
+  if (!occupyFeeOrder) {
+      console.warn("occupyFeeOrder 不存在,跳过本次轮询");
+      return;
+  }
+  wx.request({
+      url: 'https://jqcs.pjnes.com/cloud/occupyfee/evcs/occupyfee/template',
+      data: occupyFeeOrder.orderId,
+      method: 'POST',
+      success(res) {
+          that.calculate(occupyFeeOrder, res.data);
+          that.setData({
+            template:res.data
+          })
+          console.log("that.data",that.data.template);
+      }
+  });
+},
+  calculate(occupyFeeOrder,data) {
+    // let { occupyBeginTime ="" ,occupyTime =""} = occupyFeeOrder;
+      // 将时间字符串转换为 Date 对象
+      // occupyBeginTime = new Date(occupyBeginTime.replace(/-/g, "/")); // 替换为兼容 iOS 的格式
+  
+      // let currentTime = new Date();
+
+      // 计算时间差(分)
+      // let minutesDifference = Math.floor((currentTime - occupyBeginTime) / (1000 * 60));
+      let minutesDifference = data.params.occupyTime;
+      let freeTime = Number(data.freeTime) || 0;
+      console.log("免费时长:",freeTime);
+      console.log("封顶费用:", data.maxFee);
+      console.log("data:", data);
+      console.log("分钟:", minutesDifference);
+      if (minutesDifference >= freeTime +1) { 
+        let cycle =((Math.floor(minutesDifference / data.costCycle))* data.costCycleFee).toFixed(2)
+        let max = data.maxFee
+        if (cycle <= max || max == null ) {
+          console.log("未达到最大时长",cycle);
+          // let Nocycle = Math.floor(minutesDifference / data.costCycle)
+          // occupyFeeOrder.occupyFee = (Nocycle * data.costCycleFee).toFixed(2);
+          occupyFeeOrder.occupyFee = cycle
+          occupyFeeOrder.occupyTime = minutesDifference;
+        } else {
+          console.log("达到最大时长");
+          // let cycle = Math.floor(data.maxFee / data.costCycle)
+          // occupyFeeOrder.occupyFee = (cycle * data.costCycleFee).toFixed(2);
+          occupyFeeOrder.occupyFee = data.maxFee
+          occupyFeeOrder.occupyTime =minutesDifference;
+        }
+      } else {
+        console.log("处于免费时长");
+        occupyFeeOrder.occupyFee = 0.00;
+        occupyFeeOrder.occupyTime = minutesDifference;
+      }
+      
+      console.log("触发定时器",occupyFeeOrder);
+      // 根据返回的结果去调用微服务查询模版信息接口,根据模版信息 重新动态计算占位费模版
+      this.setData({
+        "occupyFeeOrderList[0]": occupyFeeOrder 
+      });
+  },
+
+  // Stop polling
+  stopPolling: function() {
+    if (this.data.pollingInterval) {
+      console.log('清除占位中定时器');
+      clearInterval(this.data.pollingInterval);
+      this.data.pollingInterval = null;
+    }
+  },
+  loadOccupyOrder() {
+    let that = this;
+    return new Promise((resolve, reject) => {
+      wx.request({
+        url: getApp().globalData.postHeadAgreement + '/restapi/wechat/queryOccupyFeeOrder',
+        data: {
+          userId: wx.getStorageSync('userInfo').userId,
+          searchIndex: 2,
+          pagenum: this.data.pagenum++,
+          pagesize: 10,
+        },
+        method: 'POST',
+        success(res) {
+          console.log("占位费", res);
+          if (res.data.result) {
+            let { rows: occupyFeeOrderList } = res.data.result;
+            that.setData({
+              occupyFeeOrderList: occupyFeeOrderList,
+            });
+            resolve(res.data.result);
+          } else {
+            resolve(res.data);
+          }
+        },
+        fail(err) {
+          reject(err);
+        }
+      });
+    });
+  },
     handleConfirm() {
       // 点击确认按钮
       this.setData({
@@ -39,8 +197,25 @@ Component({
   
     handleContact() {
       // 联系客服
-      wx.makePhoneCall({
-        phoneNumber: '18888888888' // 替换为实际的客服电话
+      // wx.makePhoneCall({
+      //   phoneNumber: '4009608068' // 替换为实际的客服电话
+      // });
+      wx.showModal({
+        title: '提示',
+        confirmColor: '#00AADD',
+        confirmText: '联系客服', 
+        content: '若对当前占位费订单有疑问,请拨打客服电话4009608068,工作时间:08:00-17:00',
+        complete: (res) => {
+          // 可以在这里添加回调逻辑
+          if (res.confirm) {
+            wx.makePhoneCall({
+              phoneNumber: '4009608068' // 替换为实际的客服电话
+            });
+            console.log('用户点击了确认按钮');
+          }else{
+            console.log('用户点击了取消按钮');
+          }
+        }
       });
     },
   }

+ 25 - 10
components/parking-order/parking-order.wxml

@@ -1,5 +1,6 @@
 <!--components/parking-order.wxml-->
-<view class="popup-mask" wx:if="{{showPopup}}" wx:for="{{occupyOrder}}" wx:key="id">
+<view class="popup-mask" wx:if="{{showPopup}}" wx:for="{{occupyFeeOrderList}}" wx:key="id">
+  <!-- <view class="popup-mask" wx:for="{{occupyFeeOrderList}}" wx:key="id"> -->
   <view class="popup-content">
     <!-- 标题 -->
     <view class="popup-title">占位提醒</view>
@@ -9,8 +10,8 @@
           <image src='/images/zhangweifei.png'></image>
         </view>
         <view class='charging_text_title1'>
-          <text class='bold'>{{item.chargstationname}}</text>
-          <text class="chargpile">{{item.chargpileids}} </text>
+          <text class='bold occupyTest'>{{item.brandName || ''}}{{item.chargstationname}}</text>
+          <text class="chargpile occupyTest">{{item.chargpileids}} </text>
         </view>
       </view>
     <!-- 充电桩名称 -->
@@ -18,18 +19,32 @@
     <!-- 时间信息 -->
     <view class="time-info">
       <view class="info-row">
-        <text class="label">占位开始时间:</text>
-        <text class="value">{{item.occupyBeginTime || 0}}</text>
+        <text class="label occupyTest">占位开始时间:</text>
+        <text class="value occupyTest">{{item.occupyBeginTime || 0}}</text>
       </view>
       <view class="info-row">
-        <text class="label">已占位时长:</text>
-        <text class="value">{{item.occupyTime || 0}}</text>
+        <text class="label occupyTest">已占位时长:</text>
+        <text class="value occupyTest">{{item.occupyTime || 0}}</text>
       </view>
     </view>
     <!-- 费用信息 -->
-    <view class="info-row fee-info">
-      <text class="label">已产生占位费:</text>
-      <text class="value">{{item.occupyFee || 0}}</text>
+    <view class="info-row fee-info" style="margin-bottom: 18rpx;">
+      <text class="label occupyTest">已产生占位费:</text>
+      <text class="value occupyTest">{{item.occupyFee || 0}}元</text>
+    </view>
+   <!-- 费用信息 -->
+   <view>
+   <view style="font-weight: 600;font-size: 24rpx;padding: 0 10rpx;">费用说明</view>
+      <view class="info-rows" style="padding: 0 10rpx;">
+        <text class="value occupyTest" style="margin: none;white-space: normal;">收费规则:{{template.costCycleFee || 0}}元/{{template.costCycle|| 0}}分钟,{{template.freeTime || 0}}分钟内免费</text>
+        <text class="value occupyTest" style="white-space: normal;"  wx:if='{{template.maxFee > 0}}'>,单次封顶{{template.maxFee}}元/次
+        </text>
+      </view>
+    </view>
+    <!-- 时间信息 -->
+    <view class="info-row">
+      <text class="value occupyTest">收费时段:</text>
+      <view class="value occupyTest" style="font-size: 24rpx;">{{template.costTimePeriod || '无'}}</view>
     </view>
     <!-- 警告文字 -->
     <view class="warning-text">

+ 26 - 15
components/parking-order/parking-order.wxss

@@ -63,6 +63,7 @@
   color: #333;
   padding: 0 10rpx;
   font-weight: 600;
+  margin-bottom: 8rpx;
 }
 
 .time-info {
@@ -70,10 +71,11 @@
 }
 
 .info-row {
-  font-size: 28rpx;
+  font-size: 24rpx;
   color: #333;
   padding: 0 10rpx;
   text-align: left;
+  margin-bottom: 8rpx;
 }
 
 .label {
@@ -87,7 +89,7 @@
 }
 
 .fee-info {
-  margin-bottom: 10rpx;
+  /* margin-bottom: 10rpx; */
 }
 
 .warning-text {
@@ -124,12 +126,9 @@
   text-align: center;
 }
 .chargpile {
-  font-size: 22rpx;
-  line-height: 42rpx;
-  height: 42rpx;
-  min-height: 42rpx;
-  color: #9d9d9d;
-  /* margin-left: -50rpx; */
+  display: block;
+  font-size: 24rpx;
+  font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
 }
 .charging {
   width: 62rpx;
@@ -156,9 +155,9 @@
   white-space: nowrap;
   overflow: hidden;
 }
-text {
-  margin: 0 0 20rpx 0;
-  display: block;
+.info-rows .occupyTest {
+  /* margin: 0 0 20rpx 0;
+  display: block; */
   font-size: 24rpx;
   font-family: 'Lucida Sans',
                  'Lucida Sans Regular',
@@ -167,15 +166,23 @@ text {
                  Geneva,
                  Verdana,
                  sans-serif;
-  color: #545253;
-  text-overflow: ellipsis;
+  color: #AAAAAA;
+  /* text-overflow: ellipsis;
   white-space: nowrap;
-  overflow: hidden;
+  overflow: hidden;  */
   line-height: 24rpx;
   height: 24rpx;
   min-height: 24rpx;
 }
 text.bold {
+  font-family: 'Lucida Sans',
+                 'Lucida Sans Regular',
+                 'Lucida Grande',
+                 'Lucida Sans Unicode',
+                 Geneva,
+                 Verdana,
+                 sans-serif;
+  color: #545253;
   font-weight: bold;
   line-height: 50rpx;
   height: 50rpx;
@@ -195,4 +202,8 @@ text.inline{
   min-height: 42rpx;
   color: #9d9d9d;
   margin: 0;
-}
+}
+.fee-infos {
+  /* margin-bottom: 12rpx; */
+  /* padding: 0 10rpx; */
+ }

+ 134 - 18
pages/charginfo/charginfo.js

@@ -3,7 +3,7 @@ import * as lf from '../../ec-canvas/echarts-liquidfill';
 
 
 let log = require('../../utils/log.js');
-
+let wechat = require("../../utils/wechat");
 Page({
 
   /**
@@ -49,7 +49,7 @@ Page({
     activeTab: '0',
     scrollTop:0,
     occupyFee:{},
-    showOccupyFee:false
+    showOccupyFee:false,
   },
   execParking(that,stationId){
     wx.request({
@@ -218,20 +218,76 @@ Page({
     }
   },
   getOccupyFee(){
-    // test对象对接后端服务传递过来的数据
-    var test = {
-      cost_cycle:2,
-      max_fee_time:120,
-      cost_time_period:'00:00-08:00,12:00-14:00,18:00-21:00,22:00-23:00,22:00-23:00',
-      free_time:10
+    this.selectStationOccupyFee()
+    .then(result => {
+      console.log("查询结果:", result);
+        this.setData({
+          occupyFee:result[0],
+          showOccupyFee:true
+        })
+    })
+    .catch(error => {
+      console.error("查询失败:", error);
+    });
+  },
+  async selectStationOccupyFee() {
+    try {
+      const res = await new Promise((resolve, reject) => {
+        wx.request({
+          url: `${getApp().globalData.postHeadAgreement}/restapi/wechat/queryStationOccupyFee`,
+          data: {
+            chargStation: {
+              id:this.data.chargid
+            }
+          },
+          method: 'POST',
+          success: (response) => {          
+            resolve(response.data);
+          },
+          fail: (error) => {
+            reject(error);
+          }
+        });
+      });
+      if (res.code == 200) {
+        return res.result;
+      } else {
+        throw new Error(`Error: ${res.code}`);
+      }
+    } catch (e) {
+      console.log("查询占位费模版信息异常", e);
+      log.info('[扫码]', '[查询占位费模版信息]', '[fail]', e);
+      throw e;
+    }
+  },
+  async selectPileOccupyFee(chargPileId) {
+    console.log("启动chargPileId",chargPileId);
+    try {
+      const res = await new Promise((resolve, reject) => {
+        wx.request({
+          url: `${getApp().globalData.postHeadAgreement}/restapi/wechat/queryOccupyFee`,
+          data: {
+             chargPileId: chargPileId
+          },            
+          method: 'POST',
+          success: (response) => {          
+            resolve(response.data);
+          },
+          fail: (error) => {
+            reject(error);
+          }
+        });
+      });
+      if (res.code == 200) {
+        return res.result;
+      } else {
+        throw new Error(`Error: ${res.code}`);
+      }
+    } catch (e) {
+      console.log("查询充电桩占位费模版信息异常", e);
+      log.info( '[查询充电桩占位费模版信息]', '[fail]', e);
+      throw e;
     }
-    if (Object.keys(test).length > 0) { // 判断对象数据是否为空
-      this.setData({
-        occupyFee:test,
-        showOccupyFee:true
-      })
-    }  
-    console.log("occupyFee",Object.keys(this.data.occupyFee).length > 0);
   },
 
   ori_getPage(){
@@ -442,9 +498,9 @@ Page({
         url
     });
   },
-  goScanResult(e){
+  async goScanResult(e){
     // scan_result
-
+    
   console.info('xxxxxxxxxxxxxx')
     let {
       keywords
@@ -485,6 +541,66 @@ Page({
       });
       // return;
     } else {
+    let api = getApp().globalData.postHeadAgreement
+    let path = 'restapi/wechat/queryOccupyFeeOrder'
+    let params = {
+      userId: wx.getStorageSync('userInfo').userId,
+      searchIndex: 2,
+      pagenum: this.data.pagenum++,
+      pagesize: 10,
+  }
+  let paramsNew = {
+    userId: wx.getStorageSync('userInfo').userId,
+    searchIndex: 3,
+    pagenum: this.data.pagenum++,
+    pagesize: 10,
+}
+  try{
+    const resultOrder = await wechat.request(api, path, paramsNew);
+      if (resultOrder.data.code == 200) {
+        wx.hideLoading();
+          if (resultOrder.data.result.total > 0) {
+            wx.showModal({
+              showCancel: false,
+              confirmText: '去支付',
+              content: '您有未支付的占位费订单,请先支付',
+              confirmColor:'#00AADD',
+              success: function (res) {
+                if (!res.cancel) {
+                  //点击确定
+                  let url = `/pages/ucenter/zhanw/zhanw`;
+                  wx.navigateTo({
+                    url
+                  })                 
+                }
+              }
+            });
+            return;
+      }
+    }
+    const result = await wechat.request(api, path, params);
+    if (result.data.code == 200) {
+      wx.hideLoading();
+      if (result.data.result.total > 0) { // 有占位费订单不启动扫码充电
+        this.setData({
+          showPopup:true
+        })
+        return;
+      }
+    } 
+  }catch (error) {
+    console.error('查询占位费订单失败', error);
+    wx.showModal({
+      showCancel: false,
+      content: '查询占位费订单失败',
+      confirmColor:'#00AADD',
+      success: function (res) {
+        if (!res.cancel) {
+          //点击确定
+        }
+      }
+    });
+  }
       log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId });
       wx.request({
         url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
@@ -565,7 +681,7 @@ Page({
                       data: res.data
                     });
                     log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
-                    let url = `/pages/scan_result/scan_result`;
+                    let url = `/pages/scan_result/scan_result?chargPileId=` + chargid;
                     wx.hideLoading();
                     wx.navigateTo({
                       url

+ 2 - 1
pages/charginfo/charginfo.json

@@ -1,6 +1,7 @@
 {
   "usingComponents": {
-    "parking-info": "/components/parking-info/parking-info"
+    "parking-info": "/components/parking-info/parking-info",
+    "parking-order": "/components/parking-order/parking-order"
   },
   "navigationBarTitleText": "充电站详情"
 }

+ 2 - 2
pages/charginfo/charginfo.wxml

@@ -75,7 +75,7 @@
     </view>
 --> <text class="parkingfee" wx:if="{{carParkingRate}}">充电即减免 <text>{{parkTime}}</text> 小时停车费</text>
 <!-- 占位费模版信息 -->
-<!-- <parking-info wx:if="{{showOccupyFee}}"  occupyFee="{{occupyFee}}"></parking-info> -->
+<parking-info wx:if="{{showOccupyFee}}"  occupyFee="{{occupyFee}}"></parking-info>
     <scroll-view class='pictureScroll' scroll-x='true'>
       <view wx:for="{{chargfeatureList}}" wx:key="unique" data-index="{{index}}" bindtap="previewImage" class="chargfeatureImage">
       <image src="{{item}}" ></image>
@@ -147,6 +147,6 @@
 
     <view class = "bottomm"></view>
   </scroll-view>
-
+  <parking-order showPopup="{{showPopup}}"></parking-order> 
 </view>
 </view >

+ 148 - 41
pages/index/index.js

@@ -80,7 +80,8 @@ Page({
     notice: null,
     carParkingRate: false,
     showPrivacy:false,
-    occupyFeeOrderList:[]
+    occupyFeeOrderList:[],
+    load:-1
   },
   howtouse(){
     wx.navigateTo({
@@ -556,39 +557,39 @@ Page({
           getApp().showNetworkError();
         }
       });
+    //   this.queryParkOrder(3).then(res=>{
+    //     console.log("查询未支付成功",res);
+    //     if (res.total > 0) {
+    //       wx.showModal({
+    //         showCancel: false,
+    //         confirmText: '去支付',
+    //         content: '您有未支付的占位费订单,请先支付',
+    //         confirmColor:'#00AADD',
+    //         success: function (res) {
+    //           if (!res.cancel) {
+    //             console.log("res",res);
+    //             //点击确定
+    //             let url = `/pages/ucenter/zhanw/zhanw`;
+    //             wx.navigateTo({
+    //               url
+    //             })
+    //             return;
+    //           }
+    //         }
+    //       });
+    //     }
+    //   })
+    //   // 查询占位中订单
+    // this.queryParkOrder(2).then(res=>{
+    //   // console.log("我被调用了");
+    //   if (res.total > 0) { // 有占位费订单不启动扫码充电
+    //     this.setData({
+    //       showPopup:true
+    //     })
+    //     return;
+    //   }
+    // });
     }
-    // 占位费查询
-    // that.loadOccupyOrder()
-
-  },
-  loadOccupyOrder(){
-    let that = this;
-    wx.request({
-      url: getApp().globalData.postHeadAgreement +'/restapi/wechat/queryOccupyFeeOrder',
-      data: {
-        userId: wx.getStorageSync('userInfo').userId,
-        searchIndex: 2,
-        pagenum: this.data.pagenum++,
-        pagesize: 10,
-      },
-      method: 'POST',
-      success(res) {
-        console.log("占位费",res);
-        if (res.data.result.rows) {
-          let {
-            rows: occupyFeeOrderList
-          } = res.data.result;
-          // that.startTimeOrder(charginglogs);
-          // that.formatCharginglogs(occupyFeeOrderList);
-          // wx.hideLoading()
-          that.setData({
-            occupyFeeOrderList: that.data.occupyFeeOrderList.concat(occupyFeeOrderList),
-            // total: res.data.result.total,
-            // dataLoading: false
-          });
-        }
-      }
-    });
   },
   //跳转个人中心
   bindUserAvatarUrl() {
@@ -776,8 +777,8 @@ Page({
         let that = this
         item.resultList.forEach(item=>{
           item["sumPrice"] = that.resetResultListSumPrice(item)
-          item.elecPrice = item.elecPrice.toFixed(8).replace(/\.?0+$/, "")
-          item.servicePrice = item.servicePrice.toFixed(8).replace(/\.?0+$/, "")
+          item.elecPrice = item.elecPrice || item.elecPrice.toFixed(8).replace(/\.?0+$/, "")
+          item.servicePrice = item.elecPrice||  item.servicePrice.toFixed(8).replace(/\.?0+$/, "")
         })
         let {
           name: latitude2,
@@ -804,9 +805,18 @@ Page({
     if(!item.servicePrice && item.servicePrice!=0){
       return '暂无费用'
     }
-    return (Number(item.elecPrice || 0) + Number(item.servicePrice || 0))
-    .toFixed(8)
-    .replace(/\.?0+$/, "");
+    // return (Number(item.elecPrice || 0) + Number(item.servicePrice || 0))
+    // .toFixed(8)
+    // .replace(/\.?0+$/, "");修改暂无费用报错问题
+    const elecPrice = Number(item.elecPrice);
+    const servicePrice = Number(item.servicePrice);
+
+    if (isNaN(elecPrice) || isNaN(servicePrice)) {
+      return '暂无费用';
+    }
+    return (elecPrice + servicePrice)
+      .toFixed(8)
+      .replace(/\.?0+$/, '');
   },
   //导航
   getRoute(e) {
@@ -855,7 +865,38 @@ Page({
     this.click_scan_control("",true)
   },
 
-  click_scan_control(scanResult,inner) {
+  async click_scan_control(scanResult,inner) {
+    if (this.data.isLogin) {
+      const resultOrder = await this.queryParkOrder(3);
+        console.log("查询未支付成功",resultOrder);
+        if (resultOrder.code == 0) {
+          if(resultOrder.total > 0){
+            wx.showModal({
+              showCancel: false,
+              confirmText: '去支付',
+              content: '您有未支付的占位费订单,请先支付',
+              confirmColor:'#00AADD',
+              success: function (res) {
+                if (!res.cancel) {
+                  //点击确定
+                  let url = `/pages/ucenter/zhanw/zhanw`;
+                  wx.navigateTo({
+                    url
+                  })
+                }
+              }
+            });
+            return;
+          }
+        }
+      const result = await this.queryParkOrder(2);
+      if (result.total > 0) { // 有占位费订单不启动扫码充电
+        this.setData({
+          showPopup:true
+        })
+        return;
+      }
+    }
     if(this.data.scanFlag){
       return;
     }
@@ -1081,7 +1122,7 @@ Page({
               data: res.data
             });
             log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
-            let url = `/pages/scan_result/scan_result`;
+            let url = `/pages/scan_result/scan_result?chargPileId=${scanResult}`;
             that.data.scanFlag = false;
             wx.hideLoading();
             wx.navigateTo({
@@ -1249,6 +1290,40 @@ Page({
       return true;
     }
   },
+  // 根据状态查询占位费订单
+  async queryParkOrder(status) {
+    let that = this;
+    let userId = wx.getStorageSync('userInfo').userId;
+    let pagenum = that.data.pagenum; // 先取值,防止影响下一次请求
+    that.data.pagenum++; // 递增页码
+
+    try {
+        let res = await new Promise((resolve, reject) => {
+            wx.request({
+                url: getApp().globalData.postHeadAgreement + '/restapi/wechat/queryOccupyFeeOrder',
+                method: 'POST',
+                data: {
+                    userId,
+                    searchIndex: status,
+                    pagenum,
+                    pagesize: 10
+                },
+                success: resolve,
+                fail: reject 
+            });
+        });
+
+        console.log('请求成功,处理数据');
+        if (res.data && res.data.code === 200) {
+            return res.data.result.total > 0 ? res.data.result : res.data;
+        } else {
+            return res.data || {}; // 确保返回的是对象,防止 undefined
+        }
+    } catch (err) {
+        console.error('请求失败', err);
+        throw err;
+    }
+},
 
   /**
    * 生命周期函数--监听页面显示
@@ -1356,7 +1431,39 @@ Page({
             getApp().showNetworkError();
         }
     });
-
+            this.queryParkOrder(3).then(res=>{
+              console.log("查询未支付成功",res);
+              if (res.total > 0) {
+                wx.showModal({
+                  showCancel: false,
+                  confirmText: '去支付',
+                  content: '您有未支付的占位费订单,请先支付',
+                  confirmColor:'#00AADD',
+                  success: function (res) {
+                    if (!res.cancel) {
+                      console.log("res",res);
+                      //点击确定
+                      let url = `/pages/ucenter/zhanw/zhanw`;
+                      wx.navigateTo({
+                        url
+                      })
+                      return;
+                    }
+                  }
+                });
+              }
+            })
+            // 查询占位中订单
+          this.queryParkOrder(2).then(res=>{
+            // 30s查询一次,动态返回数据
+            // console.log("我被调用了");
+            if (res.total > 0) { // 有占位费订单不启动扫码充电
+              this.setData({
+                showPopup:true
+              })
+              return;
+            }
+          });     
     } else {
       //未登录信息
       this.setData({

+ 1 - 1
pages/index/index.wxml

@@ -71,7 +71,7 @@
   </view>
 </view>
 <!-- 占位费订单 -->
-<!-- <parking-order occupyOrder="{{occupyFeeOrderList}}"></parking-order>  -->
+<parking-order showPopup="{{showPopup}}"></parking-order> 
 <!-- 通知 -->
 <van-dialog custom-class="privacy_box" 
 use-slot

+ 1 - 1
pages/outmoney/outmoney.js

@@ -143,7 +143,7 @@ Page({
                   confirmColor:'#00AADD',
                 });
                 log.info('[提现]', '[服务端提现]', '[提现成功]', data);
-              } else {
+              } else {// 查询用户是否有占位中的占位费订单
                 wx.showModal({
                   showCancel: false,
                   content: data.msg,

+ 40 - 13
pages/scan_result/scan_result.js

@@ -111,22 +111,49 @@ Page({
 
       }
     });
+    this.getOccupyFee(options.chargPileId);
   },
-  getOccupyFee(){
+  getOccupyFee(chargPileId){
     // test对象对接后端服务传递过来的数据
-    var test = {
-      // cost_cycle:2,
-      // max_fee_time:120,
-      // cost_time_period:'00:00-08:00,12:00-14:00,18:00-21:00,22:00-23:00,22:00-23:00',
-      // free_time:10
+    this.selectOccupyFee(chargPileId)
+    .then(result => {
+      console.log("查询结果:", result);
+        this.setData({
+          occupyFee:result,
+          showOccupyFee:true
+        })
+    })
+    .catch(error => {
+      console.error("查询失败:", error);
+    });
+  },
+  async selectOccupyFee(chargPileId) {
+    try {
+      const res = await new Promise((resolve, reject) => {
+        wx.request({
+          url: `${getApp().globalData.postHeadAgreement}/restapi/wechat/queryOccupyFee`,
+          data: {
+            chargPileId: chargPileId
+          },
+          method: 'POST',
+          success: (response) => {          
+            resolve(response.data);
+          },
+          fail: (error) => {
+            reject(error);
+          }
+        });
+      });
+      if (res.code == 200) {
+        return res.result;
+      } else {
+        throw new Error(`Error: ${res.code}`);
+      }
+    } catch (e) {
+      console.log("查询占位费模版信息异常", e);
+      log.info('[扫码]', '[查询占位费模版信息]', '[fail]', e);
+      throw e;
     }
-    if (Object.keys(test).length > 0) { // 判断对象数据是否为空
-      this.setData({
-        occupyFee:test,
-        showOccupyFee:true
-      })
-    }  
-    console.log("occupyFee我草",Object.keys(this.data.occupyFee).length > 0);
   },
   execParking(that,chargPile){
     let stationId = chargPile.chargStationId;

+ 1 - 1
pages/scan_result/scan_result.wxml

@@ -90,7 +90,7 @@
     <rich-text style='line-height:36rpx;color:#1D9BF7;font-size:30rpx;word-break:break-all;font-weight: bold;'>充电即减免 <text class="richHourNum">{{parkTime}}</text>小时停车费。请您确认入场车辆与启动充电时录入的车牌信息保持一致,如录入不一致将无法享受充电减免停车费优惠。</rich-text>
   </view>
   <!-- 占位费模版信息 -->
-<!-- <parking-info wx:if="{{showOccupyFee}}"  occupyFee="{{occupyFee}}"></parking-info> -->
+<parking-info wx:if="{{showOccupyFee}}"  occupyFee="{{occupyFee}}"></parking-info>
   <!-- <block wx:if="{{authStatus==0}}"> -->
   <block wx:if="{{false}}">
   <image class="scan_img" src="{{url}}" data-src="{{url}}" bindtap="previewImage"></image>

+ 2 - 2
pages/search_result/search_result.js

@@ -170,7 +170,7 @@ Page({
                   slowfreenum: item.slowfreenum,
                   breaknum: item.breaknum,
                   /** 电费 */
-                  chargprice: item.chargprice.toFixed(8).replace(/\.?0+$/, ""),
+                  chargprice: item.chargprice || item.chargprice.toFixed(8).replace(/\.?0+$/, ""),
                   /** 服务费 */
                   serviceprice: item.serviceprice,
                   /** 停车费 */
@@ -237,7 +237,7 @@ Page({
               slowfreenum: item.slowfreenum,
               breaknum: item.breaknum,
               /** 电费 */
-              chargprice: item.chargprice.toFixed(8).replace(/\.?0+$/, ""),
+              chargprice: item.chargprice || item.chargprice.toFixed(8).replace(/\.?0+$/, ""),
               /** 服务费 */
               serviceprice: item.serviceprice,
               /** 停车费 */

+ 3 - 3
pages/ucenter/index/index.wxml

@@ -82,9 +82,9 @@
           <image src='/images/enter.png'></image>
         </view>
       </view>   
-      <!-- <view class="zan-cell" wx:if='{{!userInfo.flag}}' hover-class="active" bindtap="gozhanw">
+      <view class="zan-cell" wx:if='{{!userInfo.flag}}' hover-class="active" bindtap="gozhanw">
         <view class="zan-icon">
-          <!-- <image src='/images/purse.png'></image>
+          <!-- <image src='/images/purse.png'></image> -->
           <image src='/images/column.png'></image>
         </view>
         <view class="zan-text">
@@ -93,7 +93,7 @@
         <view class="zan-ft">
           <image src='/images/enter.png'></image>
         </view>
-      </view>    -->
+      </view>   
       <view class="zan-cell" wx:if='{{!userInfo.flag}}' hover-class="active" bindtap="goPurse">
         <view class="zan-icon">
           <!-- <image src='/images/purse.png'></image> -->

+ 181 - 52
pages/ucenter/zhanw/zhanw.js

@@ -1,5 +1,6 @@
 // pages/ucenter/zhanw/zhanw.js
 let Util = require("../../../utils/util");
+let log = require('../../../utils/log.js');
 Page({
 
   /**
@@ -15,13 +16,12 @@ Page({
     dataLoading: false,
     finishedLoadTap: 0,
     finishedLoadShowTimes: 0,
-    chongdianzhuangmingcheng: false,
-    chongdianzhuangbianhao: false,
-    chongdianshichang: false,
-    chongdiankaishijieshu: false,
     customerServiceFlag: false,
     cancleBtnFlag: false,
     servicetel: getApp().globalData.helpPhoneNum,
+    orderid: null,
+    userId: null,
+    order: {},
   },
   switchBar(e){
     let searchIndex = e.currentTarget.dataset.idx;
@@ -94,21 +94,23 @@ Page({
     wx.showLoading({
       title: '数据加载中....',
     })
+    this.queryOccupyFeeOrder();
+  },
 
-  let that = this;
-
+  queryOccupyFeeOrder(){
+    let that = this;
     wx.request({
       url: getApp().globalData.postHeadAgreement +'/restapi/wechat/queryOccupyFeeOrder',
       data: {
         userId: wx.getStorageSync('userInfo').userId,
-        searchIndex: that.data.searchIndex<0?null:that.data.searchIndex,
+        searchIndex: that.data.searchIndex<0?-1:that.data.searchIndex,
         pagenum: this.data.pagenum++,
         pagesize: 10,
       },
       method: 'POST',
       success(res) {
         console.log("占位费",res);
-        if (res.data.result.rows) {
+        if (res.data.code == 200) {
           let {
             rows: occupyFeeOrderList
           } = res.data.result;
@@ -120,19 +122,21 @@ Page({
             total: res.data.result.total,
             dataLoading: false
           });
+        }else{
+          wx.hideLoading()
         }
       }
     });
   },
-
-
   formatCharginglogs(formatCharginglogs) {
     formatCharginglogs.forEach((item, index) => {
       try {
-        console.log("item",item);
+        // console.log("item",item);
           // 时间截取
-          item.occupyBeginTime = item.occupyBeginTime.substr(0,16)
-          item.occupyEndTime = item.occupyEndTime.substr(0,16)
+          if (item.occupyBeginTime != null && item.occupyEndTime != null) {
+            item.occupyBeginTime = item.occupyBeginTime.substr(0,19)
+            item.occupyEndTime = item.occupyEndTime.substr(0,19)
+          }
           // 状态翻译
           if(item.status==3){
             item.occupyStatusCN = '未支付'
@@ -143,12 +147,6 @@ Page({
           }else if(item.status==7){
             item.occupyStatusCN = '已退款'
           };
-          // 判断标记为  chongdianzhuangmingcheng chongdianzhuangbianhao chongdianshichang chongdiankaishijieshu
-          // let chongdianzhuangmingcheng =  false
-          // let chongdianzhuangbianhao =  false
-          // let chongdianshichang =  false
-          // let chongdiankaishijieshu =  false
-          // let chongdianfeiyong =  false
           let customerServiceFlag = false;
           let cancleBtnFlag= false;
           let height= 'h3';
@@ -159,11 +157,6 @@ Page({
           if(item.status==3 || item.status == 4){
             cancleBtnFlag = true;
           }
-          // item.chongdianzhuangmingcheng = chongdianzhuangmingcheng;
-          // item.chongdianzhuangbianhao = chongdianzhuangbianhao;
-          // item.chongdianshichang = chongdianshichang;
-          // item.chongdiankaishijieshu = chongdiankaishijieshu;
-          // item.chongdianfeiyong = chongdianfeiyong;
           item.customerServiceFlag = customerServiceFlag;
           item.cancleBtnFlag = cancleBtnFlag;
           item.height = height;
@@ -171,29 +164,6 @@ Page({
       } catch (err) {
         //在这里处理错误
       }
-      try {
-        let chargePile = item.pileLog;
-        console.info(chargePile)
-        let startDate = Util.parseDate(chargePile.chargstarttime);
-        let endDate = Util.parseDate(chargePile.chargendtime)
-        let totalTime = Math.round((endDate.getTime() - startDate.getTime()) / 60000);
-        let totalTimeHour = Math.floor(totalTime / 60);
-        let totalTimeMinute = totalTime % 60;
-        let startTime = startDate.getFullYear() + "年" + Util.formatNumber(startDate.getMonth() + 1) + '月' + Util.formatNumber(startDate.getDate()) + '日  ' + Util.formatNumber(startDate.getHours()) + ':' + Util.formatNumber(startDate.getMinutes()) + ':' + Util.formatNumber(startDate.getSeconds());
-        let endTime = endDate.getFullYear() + "年" + Util.formatNumber(endDate.getMonth() + 1) + '月' + Util.formatNumber(endDate.getDate()) + '日  ' + Util.formatNumber(endDate.getHours()) + ':' + Util.formatNumber(endDate.getMinutes()) + ':' + Util.formatNumber(endDate.getSeconds());
-        totalTime = Util.formatNumber(totalTimeHour) + "时" + Util.formatNumber(totalTimeMinute) + "分";
-        chargePile.startTime = startTime;
-        chargePile.endTime = endTime;
-        chargePile.totalTime = totalTime;
-        chargePile.chargallmoney = chargePile.chargallmoney.toFixed(2);
-        chargePile.chargservice = chargePile.chargservice.toFixed(2);
-        chargePile.chargmoney = chargePile.chargmoney.toFixed(2);
-        //console.log(chargePile.chargPile);
-      } catch (err) {
-        //在这里处理错误
-      }
-
-
     });
 
   },
@@ -204,11 +174,169 @@ Page({
       });
     }
   },
-  customerServiceBtn(){
+  customerServiceBtn(e){
+    let parkId = e.currentTarget.dataset.idx;
     wx.makePhoneCall({
       phoneNumber: this.data.servicetel
     })
   },
+  payOrder(e) {
+    log.info('[订单支付]', '[用户触发支付订单]');
+    wx.showLoading({
+      title: '支付中...',
+      mask: true
+    });
+    let parkId = e.currentTarget.dataset.idx;
+    let that = this;
+    let userId = wx.getStorageSync('userInfo').userId
+    this.queryOccupyById(userId,parkId).then(res=> {
+      wx.hideLoading();
+      let {
+        order,
+      } = that.data;
+      log.info('[订单支付]', '[用户触发支付订单]', '[wx.login请求]');
+    wx.login({
+      success(res) {
+        console.log(res);
+        log.info('[订单支付]', '[用户触发支付订单]', '[wx.login响应]',res);
+        if (res.code) {
+          // 发起网络请求
+          log.info('[订单支付]', '[服务端订单支付]', '[请求]', {
+            outTradeNo: order.orderId, //订单号
+            totalFee: order.occupyFee, //钱
+            code: res.code,
+            user_id: userId
+          });
+          wx.request({
+            url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/occupyFeeOrderPayfor',
+            data: {
+              outTradeNo: order.orderId, //订单号
+              totalFee: order.occupyFee, //钱
+              code: res.code,
+              user_id: userId
+            },
+            method: 'POST',
+            header: {
+              'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
+            },
+            success(res1) {
+              let {
+                data
+              } = res1;
+              log.info('[订单支付]', '[服务端订单支付]', '[响应]', data);
+              console.log(res1);
+              if (data && data.code == 200) {
+                if (data.result) {
+                  //wx.showModal({
+                  //  showCancel: false,
+                  //  content: '请微信支付'
+                  // });
+                  log.info('[订单支付]', '[余额不足微信支付]','[请求]',{
+                    timeStamp: data.result.timeStamp,
+                    nonceStr: data.result.nonceStr,
+                    package: data.result.package,
+                    signType: data.result.signType,
+                    paySign: data.result.paySign});
+                  wx.requestPayment({
+                    timeStamp: data.result.timeStamp,
+                    nonceStr: data.result.nonceStr,
+                    package: data.result.package,
+                    signType: data.result.signType,
+                    paySign: data.result.paySign,
+                    success(res2) {
+                      log.info('[订单支付]', '[余额不足微信支付成功]', '[响应]', res2);
+                      log.info('[订单支付]', '[微信支付成功回调服务端]', '[请求]', {
+                        //chargPileId,
+                        //userId,
+                        orderid: order.orderId
+                      });
+                      wx.hideLoading();
+                      wx.showModal({
+                        showCancel: false,
+                        content: '支付订单成功',
+                        confirmColor:'#00AADD',
+                        success(res) {
+                          if (res.confirm) {
+                            that.resetListZero(); 
+                            that.getPage();
+                          }
+                        }
+                      });
+                     
+                    },
+                    fail(res3) {
+                      wx.hideLoading();
+                      log.info('[订单支付]', '[余额不足微信支付]', '[fail]', res3);
+                      console.log(res3);
+                    }
+                  });
+                } else {
+                  wx.hideLoading();
+                  that.setData({
+                    orderFlag: true
+                  });
+                  wx.showModal({
+                    showCancel: false,
+                    content: data.msg,
+                    confirmColor:'#00AADD',
+                    success(res) {
+                      if (res.confirm) {
+                        that.resetListZero(); 
+                        that.getPage();
+                      }
+                    }
+                  });
+                }
+                log.info('[订单支付]', '[服务端订单支付]', '[余额支付成功]', data);
+              } else {
+                wx.hideLoading();
+                wx.showModal({
+                  showCancel: false,
+                  content: data.msg,
+                  confirmColor:'#00AADD',
+                });
+                log.info('[订单支付]', '[服务端订单支付]', '[失败data null||data.code<>200]', data);
+              }
+            }
+          });
+        } else {
+          wx.hideLoading();
+          console.log('登录失败!' + res.errMsg);
+          log.info('[订单支付]', '[用户触发支付订单]', '[wx.login响应失败code null]', res);
+        }
+      }
+    });
+    })
+  },
+  queryOccupyById(userId,parkId) {
+    return new Promise((resolve, reject) => {
+      let that = this;
+      wx.request({
+        url: getApp().globalData.postHeadAgreement +'/restapi/wechat/queryOccupyById',
+        data: {
+          userId: userId,
+          id:parkId,
+          searchIndex: 3 // 未支付
+        },
+        method: 'POST',
+        success(res) {
+          if (res.data.code == 200) {
+            console.log("更具订单号插叙",res.data.result);
+            that.setData({
+            order:res.data.result
+          })
+          resolve(res.data.result);
+          }else{
+            resolve(res.data);
+          }
+        },
+        fail(err) {
+          console.error('请求失败', err);
+          reject(err);
+        }   
+      });
+    });
+  },
   cancleBtn(e){
     let  that = this
     let reservId = e.currentTarget.dataset.idx;
@@ -217,10 +345,14 @@ Page({
     wx.showModal({
       title: '提示',
       confirmColor: '#00AADD',
-      content: '若对当前占位费订单有疑问,请拨打客服电话4009608068,工作时间:08:00-18:00',
+      confirmText: '联系客服', 
+      content: '若对当前占位费订单有疑问,请拨打客服电话4009608068,工作时间:08:00-17:00',
       complete: (res) => {
         // 可以在这里添加回调逻辑
         if (res.confirm) {
+          wx.makePhoneCall({
+            phoneNumber: '4009608068' // 替换为实际的客服电话
+          });
           console.log('用户点击了确认按钮');
         }else{
           console.log('用户点击了取消按钮');
@@ -236,9 +368,6 @@ Page({
     })
  },
 
- confirmM: function (e) {
-    console.log("姓名:" + this.data.name + "  电话:" + this.data.phoneNum);
- },
 
  iName: function (e) {
     this.setData({

+ 4 - 4
pages/ucenter/zhanw/zhanw.wxml

@@ -18,7 +18,7 @@
           <image src='/images/zhangweifei.png'></image>
         </view>
         <view class='charging_text_title1'>
-          <text class='bold'>{{item.chargstationname}}</text>
+          <text class='bold'>{{item.brandName || ''}}{{item.chargstationname}}</text>
           <text class="h1">{{item.chargpileids}}</text>
         </view>
       </view>
@@ -26,11 +26,11 @@
       <view  class="inline-view">
         <view class='inlineView' decode='true'>
         <text space="nbsp">占位开始时间: </text>
-        <text class="gray2"> {{item.occupyBeginTime}}</text>
+        <text class="gray2"> {{item.occupyBeginTime || '-'}}</text>
         </view>
       </view>
       <view  class="inline-view">
-        <view class='inlineView' decode='true'><text space="nbsp">占位结束时间: </text>  <text class="gray2">{{item.occupyEndTime}}</text></view>
+        <view class='inlineView' decode='true'><text space="nbsp">占位结束时间: </text>  <text class="gray2">{{item.occupyEndTime || '-'}}</text></view>
       </view>
       <view style='line-height:0;' >
         <text class='inline gray1'>占位时长:</text>
@@ -43,7 +43,7 @@
       </view>
       <view class="button-container">
   <!-- 使用 wx:if 动态控制按钮显示 -->
-  <view  class="downBtn" wx:if="{{item.customerServiceFlag}}" bindtap="customerServiceBtn" data-idx="{{item.id}}">去支付</view>
+  <view  class="downBtn" wx:if="{{item.customerServiceFlag}}" bindtap="payOrder" data-idx="{{item.id}}">去支付</view>
   <view  class="downBtn" wx:if="{{item.cancleBtnFlag}}" bindtap="cancleBtn">联系客服</view>
   <!-- <modal hidden="{{hiddenmodalput}}" title="完善资料" confirm-text="提交" cancel-text="取消" bindcancel="cancelM" bindconfirm="confirmM">
       <input bindinput='iName' type='text' placeholder="请输入姓名..." auto-focus/>

+ 1 - 1
project.private.config.json

@@ -4,5 +4,5 @@
   "setting": {
     "compileHotReLoad": true
   },
-  "libVersion": "3.3.5"
+  "libVersion": "3.6.6"
 }