功能:同步小程序流程
This commit is contained in:
@@ -1,32 +1,76 @@
|
||||
/**
|
||||
* Purpose: orderApi supports index.js by holding or executing the order api 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 orderApi = require('../../api/order')
|
||||
/**
|
||||
* Purpose: auth supports index.js by holding or executing the auth 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 auth = require('../../utils/auth')
|
||||
/**
|
||||
* 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: actionGuard supports index.js by holding or executing the action guard 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 actionGuard = require('../../utils/action-guard')
|
||||
/**
|
||||
* Purpose: theme supports index.js by holding or executing the theme 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 theme = require('../../utils/theme')
|
||||
const { resolveLegacyImage } = require('../../utils/file')
|
||||
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
/**
|
||||
* Purpose: REVIEW_SCORE_OPTIONS supports index.js by holding or executing the review score options 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 REVIEW_SCORE_OPTIONS = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
|
||||
|
||||
/**
|
||||
* Purpose: toId supports index.js by holding or executing the to id page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function toId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sameId supports index.js by holding or executing the same id page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function sameId(left, right) {
|
||||
const leftId = toId(left)
|
||||
const rightId = toId(right)
|
||||
return leftId !== '' && leftId === rightId
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: safeList supports index.js by holding or executing the safe list page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function safeList(value) {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: trimText supports index.js by holding or executing the trim text page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function trimText(value) {
|
||||
return String(value || '').trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: formatRating supports index.js by holding or executing the format rating page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function formatRating(value) {
|
||||
const rating = Number(value)
|
||||
if (!isFinite(rating) || rating <= 0) {
|
||||
@@ -35,6 +79,10 @@ function formatRating(value) {
|
||||
return rating % 1 === 0 ? String(rating) : rating.toFixed(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isSubmittedReview supports index.js by holding or executing the is submitted review page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function isSubmittedReview(review) {
|
||||
if (!review) {
|
||||
return false
|
||||
@@ -45,6 +93,10 @@ function isSubmittedReview(review) {
|
||||
return Boolean(review.rating)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resolveRelatedRecord supports index.js by holding or executing the resolve related record page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function resolveRelatedRecord(source, orderItemId) {
|
||||
if (Array.isArray(source)) {
|
||||
return source.find(item => sameId(item && item.orderItemId, orderItemId)) || null
|
||||
@@ -57,6 +109,10 @@ function resolveRelatedRecord(source, orderItemId) {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildReviewSummary supports index.js by holding or executing the build review summary page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildReviewSummary(review) {
|
||||
if (!review || !isSubmittedReview(review)) {
|
||||
return null
|
||||
@@ -70,6 +126,10 @@ function buildReviewSummary(review) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildPendingReview supports index.js by holding or executing the build pending review page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildPendingReview(review) {
|
||||
if (!review || isSubmittedReview(review)) {
|
||||
return null
|
||||
@@ -77,6 +137,10 @@ function buildPendingReview(review) {
|
||||
return review
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildArtistChangeSummary supports index.js by holding or executing the build artist change summary page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildArtistChangeSummary(request) {
|
||||
if (!request) {
|
||||
return null
|
||||
@@ -90,6 +154,10 @@ function buildArtistChangeSummary(request) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: indexByOrderItemId supports index.js by holding or executing the index by order item id page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function indexByOrderItemId(list) {
|
||||
return safeList(list).reduce((result, item) => {
|
||||
if (item && item.orderItemId) {
|
||||
@@ -99,6 +167,10 @@ function indexByOrderItemId(list) {
|
||||
}, {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: safeCall supports index.js by holding or executing the safe call page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
async function safeCall(factory, fallbackValue) {
|
||||
try {
|
||||
const result = await factory()
|
||||
@@ -108,6 +180,10 @@ async function safeCall(factory, fallbackValue) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: loadAssistData supports index.js by holding or executing the load assist data page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
async function loadAssistData(orders) {
|
||||
const pendingReviewsPromise = safeCall(() => orderApi.listMyPendingReviews(), [])
|
||||
const pendingChangesPromise = safeCall(() => orderApi.listMyPendingArtistChangeRequests(), [])
|
||||
@@ -136,6 +212,10 @@ async function loadAssistData(orders) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: findReviewDraft supports index.js by holding or executing the find review draft page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function findReviewDraft(orders, reviewId) {
|
||||
const reviewIdText = toId(reviewId)
|
||||
for (let i = 0; i < orders.length; i += 1) {
|
||||
@@ -155,9 +235,28 @@ Page({
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
orders: [],
|
||||
/**
|
||||
* Purpose: focusOrderId stores an optional order id from message navigation so the target order can be surfaced.
|
||||
* Usage: set it from onLoad route options and compare it while formatting order cards.
|
||||
*/
|
||||
focusOrderId: '',
|
||||
reviewScoreOptions: REVIEW_SCORE_OPTIONS
|
||||
}),
|
||||
|
||||
/**
|
||||
* Purpose: onLoad captures message or deep-link order ids before the order list is loaded.
|
||||
* Usage: mini-program runtime passes route options; store orderId for highlighting after loadOrders.
|
||||
*/
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
focusOrderId: (options && options.orderId) || ''
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: onShow supports index.js by holding or executing the on show 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.
|
||||
*/
|
||||
onShow() {
|
||||
this.loadOrders()
|
||||
},
|
||||
@@ -183,6 +282,7 @@ Page({
|
||||
const assistData = await loadAssistData(list)
|
||||
const formattedOrders = await Promise.all(list.map(async order => ({
|
||||
...order,
|
||||
focusTarget: sameId(order.id, this.data.focusOrderId),
|
||||
statusText: getOrderStatusText(order),
|
||||
statusClass: getOrderStatusClass(order),
|
||||
shopNameText: order.shopName ? `所属店铺:${order.shopName}` : '',
|
||||
@@ -227,14 +327,26 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleOpenAuth supports index.js by holding or executing the handle open auth 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.
|
||||
*/
|
||||
handleOpenAuth() {
|
||||
navigation.openAuth('/pages/orders/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* 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/profile/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: updateReviewDraft supports index.js by holding or executing the update review draft 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.
|
||||
*/
|
||||
updateReviewDraft(reviewId, patch) {
|
||||
const reviewIdText = toId(reviewId)
|
||||
const orders = this.data.orders.map(order => ({
|
||||
@@ -258,6 +370,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleSelectReviewScore supports index.js by holding or executing the handle select review score 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.
|
||||
*/
|
||||
handleSelectReviewScore(event) {
|
||||
const reviewId = event.currentTarget.dataset.reviewId
|
||||
const score = Number(event.currentTarget.dataset.score)
|
||||
@@ -266,6 +382,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleReviewContentInput supports index.js by holding or executing the handle review content input 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.
|
||||
*/
|
||||
handleReviewContentInput(event) {
|
||||
const reviewId = event.currentTarget.dataset.reviewId
|
||||
this.updateReviewDraft(reviewId, {
|
||||
@@ -365,7 +485,7 @@ Page({
|
||||
const confirmed = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '拒绝改派',
|
||||
content: '确认拒绝这次美甲师改派申请吗?',
|
||||
content: '确认拒绝这次美甲师改派申请吗?拒绝后可在下一步补充原因。',
|
||||
confirmText: '拒绝',
|
||||
success: modalRes => resolve(Boolean(modalRes.confirm))
|
||||
})
|
||||
@@ -374,8 +494,10 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
const rejectReason = await this.promptRejectReason()
|
||||
|
||||
await runWithLoading(() => orderApi.rejectArtistChange(requestId, {
|
||||
rejectReason: ''
|
||||
rejectReason
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '已拒绝改派',
|
||||
@@ -396,6 +518,29 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: promptRejectReason collects an optional customer reason before rejecting an artist-change request.
|
||||
* Usage: call it after the confirmation dialog and pass the returned text to rejectArtistChange.
|
||||
*/
|
||||
promptRejectReason() {
|
||||
return new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '拒绝原因',
|
||||
editable: true,
|
||||
placeholderText: '可选,告诉美甲师原因',
|
||||
confirmText: '提交',
|
||||
success: res => {
|
||||
if (!res.confirm) {
|
||||
resolve('')
|
||||
return
|
||||
}
|
||||
resolve(trimText(res.content))
|
||||
},
|
||||
fail: () => resolve('')
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
async handleCancelOrder(event) {
|
||||
const orderId = event.currentTarget.dataset.orderId
|
||||
if (!orderId) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<text class="hero-desc">查看订单状态和预约时间。</text>
|
||||
</view>
|
||||
|
||||
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card">
|
||||
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card {{item.focusTarget ? 'focus-target' : ''}}">
|
||||
<view class="order-head">
|
||||
<view class="order-head-copy">
|
||||
<text class="order-label">订单号</text>
|
||||
@@ -32,50 +32,50 @@
|
||||
<view class="order-line">{{orderItem.priceText}} x {{orderItem.quantity}}</view>
|
||||
<view wx:if="{{orderItem.artistName}}" class="order-line">美甲师:{{orderItem.artistName}}</view>
|
||||
<view wx:if="{{orderItem.appointmentText}}" class="order-line">预约时间:{{orderItem.appointmentText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{orderItem.reviewSummary}}" class="review-summary">
|
||||
<text class="assist-label">评价状态</text>
|
||||
<text class="assist-main">{{orderItem.reviewSummary.displayText}}</text>
|
||||
<text wx:if="{{orderItem.reviewSummary.contentText}}" class="assist-desc">{{orderItem.reviewSummary.contentText}}</text>
|
||||
</view>
|
||||
<view wx:if="{{orderItem.reviewSummary}}" class="review-summary">
|
||||
<text class="assist-label">评价状态</text>
|
||||
<text class="assist-main">{{orderItem.reviewSummary.displayText}}</text>
|
||||
<text wx:if="{{orderItem.reviewSummary.contentText}}" class="assist-desc">{{orderItem.reviewSummary.contentText}}</text>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{orderItem.pendingReview}}" class="review-panel">
|
||||
<view class="review-panel-head">
|
||||
<text class="assist-label">评价美甲师</text>
|
||||
<text class="assist-desc">评分必填,文字可选</text>
|
||||
</view>
|
||||
<view class="score-row">
|
||||
<view
|
||||
wx:for="{{reviewScoreOptions}}"
|
||||
wx:key="*this"
|
||||
wx:for-item="score"
|
||||
class="score-chip {{orderItem.reviewDraft.rating == score ? 'active' : ''}}"
|
||||
data-review-id="{{orderItem.pendingReview.id}}"
|
||||
data-score="{{score}}"
|
||||
bindtap="handleSelectReviewScore"
|
||||
>{{score}}</view>
|
||||
</view>
|
||||
<textarea
|
||||
class="review-textarea"
|
||||
maxlength="200"
|
||||
placeholder="写下这次服务体验,可不填"
|
||||
placeholder-class="textarea-placeholder"
|
||||
value="{{orderItem.reviewDraft.content}}"
|
||||
data-review-id="{{orderItem.pendingReview.id}}"
|
||||
bindinput="handleReviewContentInput"
|
||||
></textarea>
|
||||
<view class="review-submit-btn" data-review-id="{{orderItem.pendingReview.id}}" bindtap="handleSubmitReview">提交评价</view>
|
||||
</view>
|
||||
<view wx:elif="{{orderItem.pendingReview}}" class="review-panel">
|
||||
<view class="review-panel-head">
|
||||
<text class="assist-label">评价美甲师</text>
|
||||
<text class="assist-desc">评分必填,文字可选</text>
|
||||
</view>
|
||||
<view class="score-row">
|
||||
<view
|
||||
wx:for="{{reviewScoreOptions}}"
|
||||
wx:key="*this"
|
||||
wx:for-item="score"
|
||||
class="score-chip {{orderItem.reviewDraft.rating == score ? 'active' : ''}}"
|
||||
data-review-id="{{orderItem.pendingReview.id}}"
|
||||
data-score="{{score}}"
|
||||
bindtap="handleSelectReviewScore"
|
||||
>{{score}}</view>
|
||||
</view>
|
||||
<textarea
|
||||
class="review-textarea"
|
||||
maxlength="200"
|
||||
placeholder="写下这次服务体验,可不填"
|
||||
placeholder-class="textarea-placeholder"
|
||||
value="{{orderItem.reviewDraft.content}}"
|
||||
data-review-id="{{orderItem.pendingReview.id}}"
|
||||
bindinput="handleReviewContentInput"
|
||||
></textarea>
|
||||
<view class="review-submit-btn" data-review-id="{{orderItem.pendingReview.id}}" bindtap="handleSubmitReview">提交评价</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-panel">
|
||||
<text class="assist-label">待确认改派</text>
|
||||
<text class="assist-main">{{orderItem.pendingArtistChangeRequest.displayText}}</text>
|
||||
<text wx:if="{{orderItem.pendingArtistChangeRequest.reasonText}}" class="assist-desc">原因:{{orderItem.pendingArtistChangeRequest.reasonText}}</text>
|
||||
<view class="change-actions">
|
||||
<view class="change-btn primary" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" bindtap="handleApproveArtistChange">同意改派</view>
|
||||
<view class="change-btn" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" bindtap="handleRejectArtistChange">拒绝</view>
|
||||
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-panel">
|
||||
<text class="assist-label">待确认改派</text>
|
||||
<text class="assist-main">{{orderItem.pendingArtistChangeRequest.displayText}}</text>
|
||||
<text wx:if="{{orderItem.pendingArtistChangeRequest.reasonText}}" class="assist-desc">原因:{{orderItem.pendingArtistChangeRequest.reasonText}}</text>
|
||||
<view class="change-actions">
|
||||
<view class="change-btn primary" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" bindtap="handleApproveArtistChange">同意改派</view>
|
||||
<view class="change-btn" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" bindtap="handleRejectArtistChange">拒绝</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
padding: 26rpx;
|
||||
}
|
||||
|
||||
.order-card.focus-target {
|
||||
border-color: var(--theme-primary);
|
||||
box-shadow: 0 18rpx 48rpx rgba(224, 105, 92, 0.18);
|
||||
}
|
||||
|
||||
.order-head,
|
||||
.order-foot {
|
||||
display: flex;
|
||||
@@ -91,6 +96,7 @@
|
||||
|
||||
.order-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.order-title {
|
||||
|
||||
Reference in New Issue
Block a user