SelfRidicule a8fc49b797 1
2024-03-07 16:52:08 +08:00

154 lines
3.3 KiB
JavaScript

import Notify from '@vant/weapp/notify/notify';
import {
meetingRoomPayOrderRq,
selectReservationByIdRq,
} from "../../../../api/meeting/meetingRoom.js"
Page({
/**
* 页面的初始数据
*/
data: {
countdownTime: 0, // 单位毫秒
timeData: {},
showPay: false,
detail: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let _this = this;
_this.setData({
...options
})
// 获取详细信息
_this.getDetail();
},
// 获取详细信息
getDetail() {
let _this = this;
selectReservationByIdRq(_this.data.id).then(res => {
let detail = res.data;
// 支付时间 = 订单创建时间 + 5分钟
let payTime = new Date(detail.createTime).getTime() + 5 * 60 * 1000
// 当前时间
let nowTime = new Date().getTime();
// 还剩多长时间
let residueTime = payTime - nowTime;
// 订单时间过期
if (residueTime < 0) {
residueTime = 1
}
_this.setData({
detail,
countdownTime: residueTime, // 单位毫秒
})
})
},
// 时间改变
changeTime(e) {
let _this = this;
this.setData({
timeData: e.detail,
});
// 倒计时
let hours = e.detail.hours
let minutes = e.detail.minutes
let seconds = e.detail.seconds
// 倒计时结束
if (hours <= 0 && minutes <= 0 && seconds <= 0) {
// 消息提示
Notify({
message: '订单已过期!',
color: '#FB4B4B',
background: '#FBE9E9',
duration: 5000,
});
_this.setData({
showPay: false,
});
} else {
_this.setData({
showPay: true,
});
}
},
// 确认支付
payComplete() {
let _this = this;
meetingRoomPayOrderRq({
id: _this.data.id
}).then(res => {
console.log('meetingRoomPayOrderRq', res);
if (res.code == 0) {
wx.reLaunch({
url: '/pages/meeting/pay/waitComplete/waitComplete',
})
} else {
// 消息提示
Notify({
message: res.msg,
color: '#FB4B4B',
background: '#FBE9E9',
duration: 3000,
});
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})