127 lines
5.0 KiB
JavaScript
127 lines
5.0 KiB
JavaScript
/**
|
|
* Purpose: orderApi loads full backend order detail so direct entry and message navigation can render complete data.
|
|
* Usage: call getOrderDetail with the current route id before displaying the order detail page.
|
|
*/
|
|
const orderApi = require('../../api/order')
|
|
/**
|
|
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const navigation = require('../../utils/navigation')
|
|
/**
|
|
* Purpose: format supports index.js by holding or executing the format page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const format = require('../../utils/format')
|
|
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
|
|
|
Page({
|
|
/**
|
|
* Purpose: data supports index.js by holding or executing the data page or API role.
|
|
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
data: {
|
|
/**
|
|
* Purpose: loading marks whether the detail endpoint is currently fetching order data.
|
|
* Usage: bind it to loading and retry states while preserving any cached order shown on screen.
|
|
*/
|
|
loading: false,
|
|
/**
|
|
* Purpose: orderId keeps the backend order id used by reload and direct-entry flows.
|
|
* Usage: set it from route options or cached list data before calling loadOrderDetail.
|
|
*/
|
|
orderId: '',
|
|
/**
|
|
* Purpose: order supports index.js by holding or executing the order page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
order: null
|
|
},
|
|
|
|
/**
|
|
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
onLoad(options) {
|
|
const cachedOrder = getTempRecord('currentOrder', null)
|
|
const orderId = (options && options.id) || (cachedOrder && cachedOrder.id) || ''
|
|
this.setData({
|
|
orderId,
|
|
order: cachedOrder ? this.formatOrder(cachedOrder) : null
|
|
})
|
|
|
|
if (orderId) {
|
|
this.loadOrderDetail(orderId)
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Purpose: loadOrderDetail replaces list-row summary data with the authoritative admin order-detail response.
|
|
* Usage: call it from onLoad and retry buttons with the backend order id; failures leave cached data visible.
|
|
*/
|
|
async loadOrderDetail(orderId) {
|
|
this.setData({ loading: true })
|
|
try {
|
|
const detail = await orderApi.getOrderDetail(orderId)
|
|
this.setData({
|
|
order: this.formatOrder(detail)
|
|
})
|
|
} catch (error) {
|
|
wx.showToast({
|
|
title: error.message || '订单详情加载失败',
|
|
icon: 'none'
|
|
})
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Purpose: formatOrder prepares order and item fields for WXML, including review and change-request summaries.
|
|
* Usage: run every cached or fetched order object through this method before assigning it to data.order.
|
|
*/
|
|
formatOrder(order) {
|
|
const items = Array.isArray(order && order.items) ? order.items : []
|
|
return order ? {
|
|
...order,
|
|
displayStatusText: format.getOrderStatusText(order),
|
|
displayCreateTime: format.formatDateTime(order.createTime),
|
|
displayPayAmount: format.formatPrice(order.payAmount),
|
|
items: items.map(item => ({
|
|
...item,
|
|
displayAppointmentTime: item.appointmentTime ? format.formatDateTime(item.appointmentTime) : '',
|
|
reviewStatusText: item.reviewStatusText || (item.reviewSummary ? '已评价' : '待评价'),
|
|
changeStatusText: item.pendingArtistChangeRequest ? item.pendingArtistChangeRequest.displayText : ''
|
|
}))
|
|
} : null
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleRetry reloads backend detail when direct entry failed or no cached data exists.
|
|
* Usage: bind it to the empty state action so operators can recover without returning to the list.
|
|
*/
|
|
handleRetry() {
|
|
if (!this.data.orderId) {
|
|
navigation.goBack('/pages/orders/index')
|
|
return
|
|
}
|
|
this.loadOrderDetail(this.data.orderId)
|
|
},
|
|
|
|
/**
|
|
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
onUnload() {
|
|
clearTempRecord('currentOrder')
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleBack supports index.js by holding or executing the handle back page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
handleBack() {
|
|
navigation.goBack('/pages/orders/index')
|
|
}
|
|
})
|