功能:同步小程序流程
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) {
|
||||
|
||||
Reference in New Issue
Block a user