|
@@ -22,7 +22,7 @@ Component({
|
|
|
let isLogin = wx.getStorageSync('isLogin');
|
|
|
if (isLogin) {
|
|
|
this.loadOccupyOrder().then(data => {
|
|
|
- this.startPolling();
|
|
|
+ this.fetchData();
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error("数据加载失败", error);
|
|
@@ -38,8 +38,29 @@ Component({
|
|
|
pageLifetimes:{
|
|
|
// 组件所在页面的生命周期函数
|
|
|
show: function () {
|
|
|
+ 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();
|
|
@@ -59,79 +80,53 @@ Component({
|
|
|
* 组件的方法列表
|
|
|
*/
|
|
|
methods: {
|
|
|
- // 第一版
|
|
|
- // startPolling: function() {
|
|
|
- // let that = this
|
|
|
- // // Set up interval for subsequent loads
|
|
|
- // this.data.pollingInterval = setInterval(() => {
|
|
|
- // let occupyFeeOrder = this.data.occupyFeeOrderList[0];
|
|
|
- // // 如果 occupyFeeOrder 不存在,直接返回
|
|
|
- // if (!occupyFeeOrder) {
|
|
|
- // console.warn("occupyFeeOrder 不存在,跳过本次轮询");
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // wx.request({
|
|
|
- // url: 'https://jqcs.pjnes.com/cloud/occupyfee/evcs/occupyfee/template',
|
|
|
- // data: occupyFeeOrder.chargpileids,
|
|
|
- // method: 'POST',
|
|
|
- // success(res) {
|
|
|
- // that.calculate(occupyFeeOrder,res.data)
|
|
|
- // }})
|
|
|
- // }, 30000);
|
|
|
- // },
|
|
|
- startPolling: function() {
|
|
|
- let that = this;
|
|
|
-
|
|
|
- function fetchData() {
|
|
|
- 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);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // **立即执行一次**
|
|
|
- fetchData();
|
|
|
-
|
|
|
- // **设置轮询**
|
|
|
- this.data.pollingInterval = setInterval(fetchData, 30000);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
calculate(occupyFeeOrder,data) {
|
|
|
- let { occupyBeginTime ="" ,occupyTime =""} = occupyFeeOrder;
|
|
|
+ // let { occupyBeginTime ="" ,occupyTime =""} = occupyFeeOrder;
|
|
|
// 将时间字符串转换为 Date 对象
|
|
|
- occupyBeginTime = new Date(occupyBeginTime.replace(/-/g, "/")); // 替换为兼容 iOS 的格式
|
|
|
+ // occupyBeginTime = new Date(occupyBeginTime.replace(/-/g, "/")); // 替换为兼容 iOS 的格式
|
|
|
|
|
|
- let currentTime = new Date();
|
|
|
+ // 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.maxFeeTime);
|
|
|
+ console.log("封顶费用:", data.maxFee);
|
|
|
console.log("data:", data);
|
|
|
console.log("分钟:", minutesDifference);
|
|
|
if (minutesDifference >= freeTime +1) {
|
|
|
- if (minutesDifference <= data.maxFeeTime) {
|
|
|
- console.log("未达到最大时长");
|
|
|
- let Nocycle = Math.floor(minutesDifference / data.costCycle)
|
|
|
- occupyFeeOrder.occupyFee = (Nocycle * data.costCycleFee).toFixed(2);
|
|
|
+ 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.maxFeeTime / data.costCycle)
|
|
|
- occupyFeeOrder.occupyFee = (cycle * data.costCycleFee).toFixed(2);
|
|
|
+ // let cycle = Math.floor(data.maxFee / data.costCycle)
|
|
|
+ // occupyFeeOrder.occupyFee = (cycle * data.costCycleFee).toFixed(2);
|
|
|
+ occupyFeeOrder.occupyFee = data.maxFee
|
|
|
occupyFeeOrder.occupyTime =minutesDifference;
|
|
|
}
|
|
|
} else {
|
|
@@ -172,13 +167,12 @@ Component({
|
|
|
if (res.data.result) {
|
|
|
let { rows: occupyFeeOrderList } = res.data.result;
|
|
|
that.setData({
|
|
|
- occupyFeeOrderList: that.data.occupyFeeOrderList.concat(occupyFeeOrderList),
|
|
|
+ occupyFeeOrderList: occupyFeeOrderList,
|
|
|
});
|
|
|
resolve(res.data.result);
|
|
|
- }
|
|
|
- // else {
|
|
|
- // reject(new Error("No result data"));
|
|
|
- // }
|
|
|
+ } else {
|
|
|
+ resolve(res.data);
|
|
|
+ }
|
|
|
},
|
|
|
fail(err) {
|
|
|
reject(err);
|
|
@@ -201,10 +195,14 @@ Component({
|
|
|
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('用户点击了取消按钮');
|