2026-05-14 15:28:37 +08:00

81 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const auth = require('../../../utils/auth');
const { formatTime } = require('../../../utils/format');
const STATUS_MAP = {
0: { text: '待支付', key: 'pending' },
1: { text: '已支付', key: 'success' },
2: { text: '已取消', key: 'cancelled' },
3: { text: '已退款', key: 'refunded' },
4: { text: '已发货', key: 'success' },
5: { text: '已完成', key: 'success' },
6: { text: '报名失败', key: 'cancelled' }
};
const PAYMENT_METHOD_MAP = {
1: '线上支付',
2: '线下支付',
0: '未知'
};
Page({
data: {
detail: null,
loading: true
},
async onLoad(options) {
const id = options && options.id;
if (!id) {
wx.showToast({ title: '缺少订单ID', icon: 'none' });
setTimeout(() => wx.navigateBack(), 1500);
return;
}
await this.loadDetail(id);
},
async loadDetail(id) {
this.setData({ loading: true });
try {
const detail = await auth.fetchMyOrderDetail(id);
const formatted = this.formatDetail(detail);
this.setData({ detail: formatted, loading: false });
} catch (err) {
wx.showToast({ title: err?.message || '加载失败', icon: 'none' });
this.setData({ loading: false });
}
},
formatDetail(item) {
const statusInfo = STATUS_MAP[item.orderStatus] || { text: item.orderStatus || '-', key: 'default' };
// ChargeMode 枚举:0=免费,1=定价,2=单价(赛事),3=单价(项目)
// 只有 3(单价项目)显示费用列
const shouldShowFee = item.chargeMode === 3;
return {
...item,
statusText: statusInfo.text,
statusKey: statusInfo.key,
payMethod: PAYMENT_METHOD_MAP[item.paymentMethod] || '未知',
actualAmount: item.actualAmount != null ? item.actualAmount : '-',
refundAmount: item.refundAmount != null && item.refundAmount > 0 ? item.refundAmount : '',
payTimeStr: item.paymentTime ? formatTime(item.paymentTime) : '-',
refundTimeStr: item.refundTime ? formatTime(item.refundTime) : '-',
shouldShowFee: shouldShowFee
};
},
onBack() {
if (getCurrentPages().length > 1) {
wx.navigateBack();
} else {
wx.navigateTo({ url: '/subpackages/mine/order/order' });
}
},
onCopyOrderNo() {
const orderNo = this.data.detail?.orderNo || '';
wx.setClipboardData({
data: orderNo,
success: () => wx.showToast({ title: '已复制', icon: 'success' })
});
}
});