197 lines
4.3 KiB
JavaScript
Raw Normal View History

2024-03-07 16:52:08 +08:00
import Notify from '@vant/weapp/notify/notify';
import {
meetingRoomPayOrderRq,
selectReservationByIdRq,
} from "../../../../api/meeting/meetingRoom.js"
2024-03-19 11:17:53 +08:00
import {
2024-03-19 14:08:25 +08:00
wxPaySignRq,
wxMerchantOrderQueryRq
2024-03-19 11:17:53 +08:00
} from "../../../../api/pay/pay.js"
2024-02-28 13:41:19 +08:00
Page({
2024-02-28 14:14:17 +08:00
/**
* 页面的初始数据
*/
data: {
2024-03-07 16:52:08 +08:00
countdownTime: 0, // 单位毫秒
timeData: {},
showPay: false,
detail: {}
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-03-07 16:52:08 +08:00
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, // 单位毫秒
})
})
},
2024-02-28 13:41:19 +08:00
2024-03-07 16:52:08 +08:00
// 时间改变
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,
});
}
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-03-07 16:52:08 +08:00
// 确认支付
payComplete() {
let _this = this;
2024-03-19 11:17:53 +08:00
wxPaySignRq({
prepayId: _this.data.detail.prepayId
2024-03-07 16:52:08 +08:00
}).then(res => {
2024-03-19 11:17:53 +08:00
console.log('wxPaySignRq', res);
// 唤起支付
_this.callPay(res.data)
})
},
// 唤起支付
callPay(data) {
2024-03-19 14:08:25 +08:00
let _this = this;
2024-03-19 11:17:53 +08:00
wx.requestPayment({
timeStamp: data.timeStamp,
nonceStr: data.nonceStr,
package: data.prepayId,
signType: data.signType,
paySign: data.paySign,
success(res) {
2024-03-19 14:08:25 +08:00
console.log('success', res);
2024-03-19 11:17:53 +08:00
},
fail(res) {
2024-03-19 14:08:25 +08:00
console.log('fail', res);
2024-03-19 11:17:53 +08:00
},
complete(res) {
2024-03-19 14:08:25 +08:00
console.log('complete', res);
// 查询订单详情
_this.wxMerchantOrderQuery()
}
})
},
// 查询订单详情
wxMerchantOrderQuery() {
let _this = this
wxMerchantOrderQueryRq({
outTradeNo: _this.data.detail.oderNumber
}).then(res => {
console.log('wxMerchantOrderQuery', res);
if (res.code == '200') {
Notify({
type: 'primary',
message: res.msg
});
wx.reLaunch({
url: '/pages/meeting/pay/waitComplete/waitComplete',
})
} else {
Notify({
type: 'warning',
message: res.msg
});
2024-03-07 16:52:08 +08:00
}
2024-02-28 14:14:17 +08:00
})
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 生命周期函数--监听页面显示
*/
onShow() {
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
},
2024-02-28 13:41:19 +08:00
2024-02-28 14:14:17 +08:00
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
2024-02-28 13:41:19 +08:00
})