76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
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' }
|
|
};
|
|
|
|
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' };
|
|
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) : '-'
|
|
};
|
|
},
|
|
|
|
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' })
|
|
});
|
|
}
|
|
}); |