diff --git a/subpackages/mine/order-detail/order-detail.js b/subpackages/mine/order-detail/order-detail.js index ad33d0e..34f51d0 100644 --- a/subpackages/mine/order-detail/order-detail.js +++ b/subpackages/mine/order-detail/order-detail.js @@ -1,28 +1,60 @@ +const auth = require('../../../utils/auth'); +const { formatTime } = require('../../../utils/format'); + +const STATUS_MAP = { + Pending: { text: '待支付', key: 'pending' }, + Paid: { text: '交易成功', key: 'success' }, + Cancelled: { text: '已取消', key: 'cancelled' }, + Refunded: { text: '已退款', key: 'refunded' }, + Refunding: { text: '退款中', key: 'pending' } +}; + +const PAYMENT_METHOD_MAP = { + 1: '线上支付', + 2: '线下支付', + 0: '未知' +}; + Page({ data: { - detail: { - eventName: '2024上海市学生运动会跳绳比赛', - statusText: '交易成功', - statusKey: 'success', - payMethod: '线上支付', - actualAmount: '689', - payTimeStr: '2025-08-05 16:26', - refundAmount: '689', - refundTimeStr: '2025-08-05 16:26', - orderNo: '13123421516216512515 1', - items: [ - { id: 1, projectName: '30秒单摇', groupName: '少年儿童组', fee: 23 }, - { id: 2, projectName: '交互绳', groupName: '成年组', fee: 411 }, - { id: 3, projectName: '交互绳', groupName: '少年儿童组', fee: 32 }, - { id: 4, projectName: '交互绳', groupName: '成年组', fee: 12 } - ] + 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 }); } }, - onLoad(options) { - const id = options && options.id; - // TODO: 根据 id 调用接口获取订单详情 - // this.loadDetail(id); + 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() { @@ -34,10 +66,10 @@ Page({ }, onCopyOrderNo() { - const orderNo = this.data.detail.orderNo || ''; + const orderNo = this.data.detail?.orderNo || ''; wx.setClipboardData({ data: orderNo, success: () => wx.showToast({ title: '已复制', icon: 'success' }) }); } -}); +}); \ No newline at end of file diff --git a/subpackages/mine/records/records.js b/subpackages/mine/records/records.js index 3a46bc2..81884d0 100644 --- a/subpackages/mine/records/records.js +++ b/subpackages/mine/records/records.js @@ -1,6 +1,14 @@ const auth = require('../../../utils/auth'); const { formatDateTime } = require('../../../utils/format'); +const STATUS_MAP = { + 0: '待支付', + 1: '已支付', + 2: '支付失败', + 3: '已退款', + 4: '已取消' +}; + Page({ data: { registrations: [], @@ -55,7 +63,8 @@ Page({ const rows = (page && Array.isArray(page.rows) ? page.rows : []).map((r) => { return { ...r, - registrationTimeText: formatDateTime(r.registrationTime) + registrationTimeText: formatDateTime(r.registrationTime), + statusText: STATUS_MAP[r.status] || r.status }; }); diff --git a/subpackages/mine/records/records.wxml b/subpackages/mine/records/records.wxml index b0244a9..f38ecd3 100644 --- a/subpackages/mine/records/records.wxml +++ b/subpackages/mine/records/records.wxml @@ -14,7 +14,7 @@ {{item.eventName || '-'}} 团队/联系人:{{item.teamName}} 项目:{{item.projectNames}} - 状态:{{item.status}} + 状态:{{item.statusText}} 报名时间:{{item.registrationTimeText}} diff --git a/utils/auth.js b/utils/auth.js index ecf538b..57a7c6c 100644 --- a/utils/auth.js +++ b/utils/auth.js @@ -362,6 +362,15 @@ async function fetchMyOrders({ pageNo = 1, pageSize = 10 } = {}) { }); } +async function fetchMyOrderDetail(id) { + if (id == null || id === '') throw new Error('缺少订单ID'); + return request({ + path: `${API.myOrders}/${id}`, + method: 'GET', + needAuth: true + }); +} + async function fetchMyCertificates({ pageNo = 1, pageSize = 10, type } = {}) { const data = { PageNo: pageNo, @@ -392,6 +401,7 @@ module.exports = { fetchMyTeams, fetchMyTeamDetail, fetchMyOrders, + fetchMyOrderDetail, fetchMyCertificates, refreshAccessToken, uploadFile,