功能:同步小程序流程

This commit is contained in:
xiaowang
2026-05-23 18:45:41 +08:00
parent 844516988b
commit 30ae763e18
117 changed files with 8823 additions and 76 deletions
@@ -1,27 +1,125 @@
/**
* 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
},
onLoad() {
const order = getTempRecord('currentOrder', 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({
order: order ? {
...order,
displayStatusText: format.getOrderStatusText(order),
displayCreateTime: format.formatDateTime(order.createTime)
} : null
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')
}
@@ -24,7 +24,7 @@
</view>
<view class="meta-item">
<text class="meta-label">应付金额</text>
<text class="meta-value">¥{{order.payAmount || '--'}}</text>
<text class="meta-value">¥{{order.displayPayAmount || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">备注</text>
@@ -33,9 +33,30 @@
</view>
</view>
<view wx:else class="empty-state">
<view wx:if="{{order && order.items && order.items.length}}" class="surface-card">
<text class="section-title">服务项目</text>
<block wx:for="{{order.items}}" wx:key="id">
<view class="detail-item">
<view class="detail-item-head">
<text class="detail-item-title">{{item.productTitle || '订单项目'}}</text>
<text class="badge">{{item.reviewStatusText}}</text>
</view>
<text class="detail-item-line">美甲师:{{item.artistName || '--'}}</text>
<text wx:if="{{item.displayAppointmentTime}}" class="detail-item-line">预约时间:{{item.displayAppointmentTime}}</text>
<text wx:if="{{item.reviewSummary && item.reviewSummary.contentText}}" class="detail-item-line">评价内容:{{item.reviewSummary.contentText}}</text>
<view wx:if="{{item.pendingArtistChangeRequest}}" class="change-box">
<text class="change-title">改派申请</text>
<text class="change-line">{{item.pendingArtistChangeRequest.displayText}}</text>
<text wx:if="{{item.pendingArtistChangeRequest.reasonText}}" class="change-line">原因:{{item.pendingArtistChangeRequest.reasonText}}</text>
</view>
</view>
</block>
</view>
<view wx:if="{{!order}}" class="empty-state">
<text class="empty-title">订单详情暂不可用</text>
<text class="empty-desc">当前详情页优先复用列表页已拉取的数据。如果你是直接打开该页面,请先回到订单列表重新进入。</text>
<text class="empty-desc">当前详情页可通过列表、消息或订单 id 打开;加载失败时可重试。</text>
<button class="primary-btn" loading="{{loading}}" bindtap="handleRetry">重新加载</button>
</view>
</view>
</view>
@@ -1,3 +1,55 @@
.page-shell {
background: transparent;
}
.detail-item {
display: flex;
flex-direction: column;
gap: 12rpx;
padding: 20rpx 0;
border-top: 1rpx solid rgba(255, 255, 255, 0.08);
}
.detail-item:first-of-type {
border-top: 0;
}
.detail-item-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.detail-item-title {
color: #f6efe7;
font-size: 30rpx;
font-weight: 700;
}
.detail-item-line {
color: #9fb3ad;
font-size: 24rpx;
line-height: 1.6;
}
.change-box {
display: flex;
flex-direction: column;
gap: 8rpx;
padding: 16rpx;
border-radius: 8rpx;
background: rgba(240, 126, 87, 0.1);
}
.change-title {
color: #f6efe7;
font-size: 24rpx;
font-weight: 700;
}
.change-line {
color: #f4c7b8;
font-size: 24rpx;
line-height: 1.5;
}