Files
JMApp/pages/washing/washing.js
XiaoMo d098203c87 refactor: 统一API路径前缀并更新静态资源域名
- 将所有API路径从'/v2/miniprogram'统一为'/miniprogram'
- 更新静态资源域名从'http://jm.v0750.com'到'https://jm-static.v0750.com'
- 在utils/login.js中设置统一的baseUrl为'https://t-jm.v0750.com/v3'
- 移除不再使用的initial_url和baseUrl配置项
2025-12-15 23:27:34 +08:00

179 lines
3.9 KiB
JavaScript

var t = getApp(), e = require("../../utils/login.js");
Page({
/**
* 页面的初始数据
*/
data: {
countdown: '',
agentname: '',
devicecode: '',
remainingTime: 0,
orderid: '',
title: getApp().globalData.deviceData.title || getApp().globalData.deviceData.devicecode
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var a = this;
e.request('/miniprogram/index/balance', getApp().globalData.deviceData, !0).then(function (res) {
if (!res.data || !res.data.progressorder) {
wx.showToast({
title: '没有进行中的订单',
icon: 'none',
duration: 3000
});
setTimeout(() => {
// 跳转到首页
wx.redirectTo({
url: '/pages/index/index'
});
}, 1000);
return;
}
const orderInfo = res.data.progressorder;
const currentTime = Math.floor(Date.now() / 1000);
const remainingTime = Math.max(0, orderInfo.timestamp + orderInfo.siteoccupationTime * 60 - currentTime);
a.setData({
agentname: orderInfo.agentname,
devicecode: orderInfo.devicecode,
remainingTime: remainingTime,
orderid: orderInfo.id
});
if (remainingTime > 0) {
a.countdown();
}
}).catch(function (err) {
wx.showToast({
title: '获取订单信息失败',
icon: 'none',
duration: 2000
});
setTimeout(() => {
wx.redirectTo({
url: '/pages/index/index'
});
}, 1000);
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
handleSettlement() {
wx.showModal({
title: '确认结算',
content: '确定要结算此次洗车订单吗?',
success: (res) => {
if (res.confirm) {
e.request('/miniprogram/' + getApp().globalData.deviceData.type + '/shutdown', {
orderid: this.data.orderid
}, true).then((res) => {
if (res.code === 200) {
wx.showToast({
title: res.message || '结算成功',
icon: 'success',
duration: 2000
});
setTimeout(() => {
wx.removeStorageSync('progressorder');
wx.redirectTo({
url: '/pages/index/index'
});
}, 2000);
}
}).catch((err) => {
// setTimeout(() => {
// wx.removeStorageSync('progressorder');
// wx.reLaunch({
// url: '/pages/index/index'
// });
// }, 2000);
})
}
}
});
},
countdown() {
// 没有 Cannot read property 'remainingTime' of undefined
if (!this.data.remainingTime) {
this.setData({
countdown: '00:00'
});
return;
}
if (this.data.remainingTime <= 0) {
this.setData({
countdown: '00:00'
});
return;
}
const minute = Math.floor(this.data.remainingTime / 60);
const second = this.data.remainingTime % 60;
const formattedMinute = minute < 10 ? '0' + minute : minute;
const formattedSecond = second < 10 ? '0' + second : second;
this.setData({
countdown: formattedMinute + ':' + formattedSecond,
remainingTime: this.data.remainingTime - 1
});
setTimeout(this.countdown, 1000);
},
})