模拟了微信支付功能
This commit is contained in:
@ -5,6 +5,7 @@ Page({
|
||||
data: {
|
||||
orderList: [], // 后端返回的订单列表
|
||||
hasModalShown: false, // 弹框只显示一次
|
||||
isMaskVisible: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
@ -35,7 +36,7 @@ Page({
|
||||
let list = res.data.data.map(item => {
|
||||
// 计算从 createTime 到 now 剩余秒数
|
||||
const createMs = new Date(item.createTime.replace(/-/g,'/')).getTime();
|
||||
let diff = Math.floor((createMs + 30*60*1000 - now) / 1000);
|
||||
let diff = Math.floor((createMs + 15*60*1000 - now) / 1000);
|
||||
|
||||
// 只有“待支付”才需要倒计时、过期置“交易取消”
|
||||
if (item.orderStatus === '待支付') {
|
||||
@ -80,6 +81,10 @@ Page({
|
||||
|
||||
// 每秒更新所有待支付订单的倒计时
|
||||
startTimer() {
|
||||
// ← 新增:如果已有定时器,先清掉它
|
||||
if (this._timer) {
|
||||
clearInterval(this._timer);
|
||||
}
|
||||
this._timer = setInterval(() => {
|
||||
const updated = this.data.orderList.map(item => {
|
||||
if (item.orderStatus === '待支付' && item.countDown > 0) {
|
||||
@ -108,6 +113,62 @@ Page({
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
showIsPayModal(e) {
|
||||
const orderId = e.currentTarget.dataset.orderId;
|
||||
wx.showModal({
|
||||
title: '下单成功',
|
||||
content: '您确定要支付吗?',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.payOrder(orderId);
|
||||
} else if (res.cancel) {
|
||||
this.setData({ isMaskVisible: false });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '网络错误,下单失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
payOrder(orderId) {
|
||||
// 同样先显示遮罩
|
||||
this.setData({ isMaskVisible: true });
|
||||
wx.showLoading({ title: '支付中...'});
|
||||
wx.request({
|
||||
url: baseUrl + '/courseOrder/payment',
|
||||
method: 'POST',
|
||||
header: { Authorization: wx.getStorageSync('token') },
|
||||
data: { id: orderId},
|
||||
success: res => {
|
||||
wx.hideLoading();
|
||||
if (res.data.code === 1) {
|
||||
// 支付成功,跳转详情页
|
||||
wx.redirectTo({
|
||||
url: `/pages/course/orderDetail/orderDetail?id=${orderId}`,
|
||||
success: res => {
|
||||
// 先把遮罩关掉
|
||||
this.setData({ isMaskVisible: false });
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.setData({ isMaskVisible: false });
|
||||
wx.showToast({ title: res.data.message || '支付失败', icon: 'none' });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
this.setData({ isMaskVisible: false });
|
||||
wx.showToast({ title: '网络错误,支付失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 跳转订单详情
|
||||
gotoOrderDetail(e) {
|
||||
const orderId = e.currentTarget.dataset.id;
|
||||
@ -135,11 +196,6 @@ Page({
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
// 支付订单
|
||||
payOrder() {
|
||||
// wx.navigateTo({ url: `/pages/pay/pay?orderId=${this.data.orderId}` });
|
||||
wx.showToast({ title: '支付功能稍后开放', icon: 'none' });
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user