功能(网页):新增客户体验流程

This commit is contained in:
xiaowang
2026-05-23 21:56:18 +08:00
parent c2c985b2f8
commit 861eea933b
28 changed files with 2236 additions and 108 deletions
+267 -13
View File
@@ -35,15 +35,35 @@
<a-button @click="resetFilters">清空筛选</a-button>
</a-empty>
<a-card v-for="order in filteredOrders" :key="order.id" class="order-card">
<a-card
v-for="order in filteredOrders"
:key="order.id"
class="order-card"
:class="{ focused: sameId(focusedOrderId, order.id) }"
>
<div class="order-head">
<span class="order-no">订单号:{{ order.orderNo }}</span>
<a-button size="small" type="link" @click="copyOrderNo(order.orderNo)">复制</a-button>
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
</div>
<div v-if="order.shopName" class="order-shop">所属店铺:{{ order.shopName }}</div>
<ol class="order-timeline">
<li
v-for="node in buildOrderTimeline(order)"
:key="`${order.id}-${node.key}`"
:class="{ active: node.active, done: node.done }"
>
<strong>{{ node.title }}</strong>
<span>{{ node.time || node.desc }}</span>
</li>
</ol>
<div v-for="item in order.items" :key="item.id" class="item">
<div
v-for="item in order.items"
:key="item.id"
class="item"
:class="{ focused: sameId(focusedOrderItemId, item.id) }"
>
<div class="thumb">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" />
<span v-else>{{ item.productTitle[0] }}</span>
@@ -64,11 +84,12 @@
<div v-if="pendingChangeRequestForItem(order, item)" class="change-request">
<div class="change-info">
<strong>待处理改派申请</strong>
<span>
{{ pendingChangeRequestForItem(order, item)?.originalArtistName || item.artistName || '原美甲师' }}
→ {{ pendingChangeRequestForItem(order, item)?.requestedArtistName || '新美甲师' }}
</span>
<span>原美甲师:{{ artistChangeDisplay(pendingChangeRequestForItem(order, item), item).originalArtistName }}</span>
<span>新美甲师:{{ artistChangeDisplay(pendingChangeRequestForItem(order, item), item).requestedArtistName }}</span>
<span v-if="pendingChangeRequestForItem(order, item)?.reason">原因:{{ pendingChangeRequestForItem(order, item)?.reason }}</span>
<div class="impact-list">
<span v-for="line in artistChangeDisplay(pendingChangeRequestForItem(order, item), item).impactLines" :key="line">{{ line }}</span>
</div>
</div>
<div class="change-actions">
<a-button size="small" type="primary" @click="approveArtistChange(pendingChangeRequestForItem(order, item))">同意</a-button>
@@ -80,7 +101,10 @@
<div class="footer">
<span>总计:¥{{ order.actualAmount.toFixed(2) }}</span>
<a-button v-if="order.status === 1" size="small" danger @click="cancelOrder(order.id)">取消订单</a-button>
<div class="footer-actions">
<a-button v-if="hasRebookableItems(order)" size="small" type="primary" @click="rebookOrder(order)">复刻同款</a-button>
<a-button v-if="order.status === 1" size="small" danger @click="cancelOrder(order.id)">取消订单</a-button>
</div>
</div>
</a-card>
</main>
@@ -117,6 +141,12 @@
@cancel="closeRejectArtistChange"
>
<a-form layout="vertical">
<div v-if="activeChangeRequest" class="reject-change-summary">
<span>原美甲师:{{ artistChangeDisplay(activeChangeRequest).originalArtistName }}</span>
<span>新美甲师:{{ artistChangeDisplay(activeChangeRequest).requestedArtistName }}</span>
<span v-if="activeChangeRequest.reason">原因:{{ activeChangeRequest.reason }}</span>
<span v-for="line in artistChangeDisplay(activeChangeRequest).impactLines" :key="line">{{ line }}</span>
</div>
<a-form-item label="拒绝原因">
<a-textarea v-model:value="rejectForm.rejectReason" :rows="3" :maxlength="300" placeholder="可选,请填写拒绝原因" />
</a-form-item>
@@ -130,22 +160,27 @@
* OrderView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { computed, inject, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { LeftOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { fileApi } from '../api/index'
import { cartApi } from '../api/cart'
import { orderApi } from '../api/order'
import type { OrderArtistChangeRequestVO, OrderArtistReviewVO } from '../api/order'
import { userApi } from '@/api/user'
import type { IdType } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { buildRecoveryActions, getRecoveryMessage } from '@/utils/recovery'
import { resolveOrderReviewFocus } from '@/utils/order-review-focus'
/**
* Purpose: router supports OrderView.vue by holding or executing the router 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 router = useRouter()
const route = useRoute()
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
/**
* Purpose: orders supports OrderView.vue by holding or executing the orders 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.
@@ -171,6 +206,8 @@ const orderReviews = ref<Record<string, OrderArtistReviewVO[]>>({})
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const pendingChangeRequests = ref<OrderArtistChangeRequestVO[]>([])
/** historicalChangeRequests stores handled change requests for order timelines. */
const historicalChangeRequests = ref<Record<string, OrderArtistChangeRequestVO[]>>({})
/**
* Purpose: reviewModalOpen supports OrderView.vue by holding or executing the review modal open 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.
@@ -254,6 +291,13 @@ const filteredOrders = computed(() => {
})
})
/** focusedOrderId stores message/deep-link focus for reviews or artist-change cards. */
const focusedOrderId = ref('')
/** focusedOrderItemId stores message/deep-link item focus. */
const focusedOrderItemId = ref('')
/** focusedReviewId stores message/deep-link review focus. */
const focusedReviewId = ref('')
/** statusClass is a local helper used by this page script. */
const statusClass = (status: number) => {
if (status === 1) return 'pending'
@@ -311,6 +355,108 @@ const pendingChangeRequestForItem = (order: any, item: any): OrderArtistChangeRe
return pendingChangeRequests.value.find(request => sameId(request.orderId, order.id) && sameId(request.orderItemId, item.id))
}
/**
* Purpose: formatChangePrice supports OrderView.vue by turning optional impact prices into stable customer-facing copy.
* Usage: call it when rendering artist-change impact cards and confirmation dialogs.
*/
const formatChangePrice = (price?: number | string) => {
const value = Number(price)
return Number.isFinite(value) ? `¥${value.toFixed(2)}` : ''
}
/**
* Purpose: formatChangeTime supports OrderView.vue by normalizing backend or order-item appointment values for impact copy.
* Usage: call it when rendering artist-change impact cards and confirmation dialogs.
*/
const formatChangeTime = (time?: string) => {
return String(time || '').replace('T', ' ').slice(0, 16)
}
/**
* Purpose: artistChangeDisplay supports OrderView.vue by deriving visible impact text from a pending artist-change request.
* Usage: use it in cards and confirmation dialogs so the user sees the same time and price impact.
*/
const artistChangeDisplay = (request?: OrderArtistChangeRequestVO, item?: any) => {
const originalArtistName = request?.originalArtistName || request?.fromArtistName || item?.artistName || '原美甲师'
const requestedArtistName = request?.requestedArtistName || request?.toArtistName || '新美甲师'
const appointmentTime = formatChangeTime(request?.appointmentTime || item?.appointmentTime)
const timeImpactText = request?.timeImpactText || (request?.timeAffected ? '预约时间可能调整' : '预约时间不变')
const priceImpactText = request?.priceImpactText || (request?.priceAffected ? '订单价格可能调整' : '价格不变')
const priceValue = request?.priceAffected ? request?.newPrice : (request?.newPrice ?? request?.originalPrice ?? item?.price)
const priceText = formatChangePrice(priceValue)
const impactLines = [
appointmentTime ? `${timeImpactText}:${appointmentTime}` : timeImpactText,
priceText ? `${priceImpactText}:${priceText}` : priceImpactText
].filter(Boolean)
return {
originalArtistName,
requestedArtistName,
impactLines
}
}
/** formatTimelineTime normalizes backend timestamps for the compact order timeline. */
const formatTimelineTime = (value?: string) => {
return String(value || '').replace('T', ' ').slice(0, 16)
}
/** buildOrderTimeline creates a customer-facing status path for one order. */
const buildOrderTimeline = (order: any) => {
const items = order.items || []
const firstAppointment = items.map((item: any) => item.appointmentTime).find(Boolean)
const changes = historicalChangeRequests.value[String(order.id)] || []
const latestHandledChange = changes.find(request => String(request.status || '').toUpperCase() !== 'PENDING')
const nodes = [
{
key: 'created',
title: '已下单',
time: formatTimelineTime(order.createTime),
desc: '订单已创建',
done: true,
active: Number(order.status) === 1
},
{
key: 'appointment',
title: '预约时间',
time: formatTimelineTime(firstAppointment),
desc: firstAppointment ? '' : '待确认',
done: Boolean(firstAppointment),
active: Number(order.status) === 1
}
]
if (changes.length) {
nodes.push({
key: 'artist-change',
title: '改派记录',
time: formatTimelineTime(latestHandledChange?.approvedTime || latestHandledChange?.rejectedTime || changes[0]?.createTime),
desc: `${changes.length} 次申请`,
done: String(latestHandledChange?.status || '').toUpperCase() !== 'PENDING',
active: changes.some(request => String(request.status || '').toUpperCase() === 'PENDING')
})
}
nodes.push({
key: Number(order.status) === 3 ? 'cancelled' : 'completed',
title: Number(order.status) === 3 ? '已取消' : '已完成',
time: formatTimelineTime(order.completeTime || order.cancelTime || order.updateTime),
desc: Number(order.status) === 2 ? '服务已完成' : (Number(order.status) === 3 ? '订单已取消' : '等待服务完成'),
done: Number(order.status) === 2 || Number(order.status) === 3,
active: Number(order.status) === 2 || Number(order.status) === 3
})
const orderReviewsForTimeline = orderReviews.value[String(order.id)] || []
nodes.push({
key: 'review',
title: '评价',
time: formatTimelineTime(orderReviewsForTimeline.find(review => Number(review.status) === 1)?.reviewTime),
desc: orderReviewsForTimeline.some(review => Number(review.status) === 1)
? '已评价'
: (pendingReviews.value.some(review => sameId(review.orderId, order.id)) ? '待评价' : '服务完成后可评价'),
done: orderReviewsForTimeline.some(review => Number(review.status) === 1),
active: pendingReviews.value.some(review => sameId(review.orderId, order.id))
})
return nodes
}
/**
* Purpose: formatRating supports OrderView.vue by holding or executing the format rating 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.
@@ -328,6 +474,47 @@ const resetFilters = () => {
filters.maxAmount = undefined
}
const normalizeRebookQuantity = (quantity: unknown) => {
const value = Number(quantity)
return Number.isFinite(value) && value > 0 ? Math.max(1, Math.floor(value)) : 1
}
const getRebookableOrderItems = (order: any) => {
return (order.items || []).filter((item: any) => item?.productId !== undefined && item?.productId !== null)
}
const hasRebookableItems = (order: any) => {
return Number(order.status) === 2 && getRebookableOrderItems(order).length > 0
}
const rebookOrder = async (order: any) => {
if (Number(order.status) !== 2) {
message.warning('仅已完成订单支持再次预约')
return
}
const items = getRebookableOrderItems(order)
if (!items.length) {
message.warning('这笔订单暂无可复刻作品')
return
}
try {
await runWithGlobalLoading(async () => {
for (const item of items) {
await cartApi.addToCart({
productId: item.productId,
quantity: normalizeRebookQuantity(item.quantity)
})
}
await updateCartCount()
})
message.success('已加入购物车,请重新选择美甲师和时间')
router.push('/cart')
} catch (error: any) {
message.error(error?.message || '复刻同款失败,请稍后重试')
}
}
/**
* Purpose: copyOrderNo supports OrderView.vue by holding or executing the copy order no 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.
@@ -391,6 +578,54 @@ const refreshOrderExtensions = async () => {
loadOrderReviews(),
loadPendingArtistChangeRequests()
])
await loadHistoricalArtistChangeRequests()
resolveRouteFocus()
}
/** loadHistoricalArtistChangeRequests loads handled and pending changes for the order timeline. */
const loadHistoricalArtistChangeRequests = async () => {
const orderIds = orders.value.map(order => order.id).filter(Boolean)
const entries = await Promise.all(orderIds.map(async (orderId) => {
try {
return [String(orderId), await orderApi.getOrderArtistChangeRequests(orderId)] as const
} catch {
return [String(orderId), []] as const
}
}))
historicalChangeRequests.value = Object.fromEntries(entries)
}
/** resolveRouteFocus handles message jumps for review or order focus. */
const resolveRouteFocus = () => {
const focus = resolveOrderReviewFocus({
orders: orders.value,
pendingReviews: pendingReviews.value,
orderReviews: orderReviews.value,
query: route.query
})
focusedOrderId.value = focus.focusOrderId
focusedOrderItemId.value = focus.focusOrderItemId
focusedReviewId.value = focus.focusReviewId
if (focus.message) {
message.info(focus.message)
}
}
const openOrdersRecovery = (error: unknown) => {
const actions = buildRecoveryActions([
{ key: 'retry', text: '重试' },
{ key: 'products', text: '去逛作品' }
])
const retryAction = actions[0]
const productsAction = actions[1]
Modal.confirm({
title: '订单列表加载失败',
content: `${getRecoveryMessage(error, '订单暂时没有加载出来,请重试或稍后再查看。')}。你可以重试,或先去浏览作品。`,
okText: retryAction?.text || '重试',
cancelText: productsAction?.text || '去逛作品',
onOk: () => loadOrders(),
onCancel: () => router.push(productsAction?.route || '/products')
})
}
/** loadOrders is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
@@ -417,8 +652,9 @@ const loadOrders = async () => {
}
await refreshOrderExtensions()
return true
} catch {
message.error('获取订单列表失败')
} catch (error) {
orders.value = []
openOrdersRecovery(error)
return false
}
}
@@ -485,9 +721,15 @@ const submitReview = async () => {
*/
const approveArtistChange = (request?: OrderArtistChangeRequestVO) => {
if (!request) return
const display = artistChangeDisplay(request)
Modal.confirm({
title: '同意改派申请',
content: `确定同意改派给「${request.requestedArtistName || '新美甲师'}」吗?`,
content: [
`原美甲师:${display.originalArtistName}`,
`新美甲师:${display.requestedArtistName}`,
request.reason ? `原因:${request.reason}` : '',
...display.impactLines
].filter(Boolean).join('\n'),
onOk: async () => {
try {
await runWithGlobalLoading(async () => {
@@ -575,15 +817,24 @@ onMounted(loadOrders)
.filter-select, .filter-date, .filter-number { flex: 1; min-width: 0; }
.filter-summary { color: var(--text-secondary); font-size: 12px; text-align: right; }
.order-card { margin-bottom: 12px; border-radius: 14px; border: 1px solid var(--theme-border); background: var(--theme-card-bg); box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08); }
.order-card.focused { border-color: var(--theme-primary); box-shadow: 0 18px 40px rgba(186, 110, 132, 0.2); }
.order-card :deep(.ant-card-body) { padding: 16px; }
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.footer-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--theme-border); }
.order-shop { margin: -4px 0 12px; color: var(--text-secondary); font-size: 13px; }
.order-timeline { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.order-timeline li { display: grid; gap: 3px; min-width: 0; padding: 8px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--text-secondary); }
.order-timeline li.done { color: var(--theme-primary); }
.order-timeline li.active { outline: 1px solid var(--theme-primary); }
.order-timeline strong { font-size: 12px; color: var(--text-primary); }
.order-timeline span { min-width: 0; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pending { background: var(--theme-primary-soft); color: var(--theme-primary); }
.completed { background: var(--theme-primary-soft); color: var(--theme-primary); }
.cancelled { background: var(--theme-primary-soft); color: var(--theme-accent); }
.item { display: flex; gap: 12px; margin-bottom: 12px; }
.item.focused { padding: 8px; border-radius: 10px; background: var(--theme-primary-soft); }
.thumb { width: 60px; height: 60px; border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: var(--theme-primary-soft); color: var(--theme-primary); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.main { flex: 1; }
@@ -595,6 +846,9 @@ onMounted(loadOrders)
.change-request { display: grid; gap: 8px; margin-top: 8px; padding: 10px; border: 1px solid var(--theme-border); border-radius: 8px; background: rgba(255, 255, 255, 0.72); }
.change-info { display: grid; gap: 4px; color: var(--text-secondary); font-size: 13px; }
.change-info strong { color: var(--text-primary); }
.impact-list, .reject-change-summary { display: grid; gap: 4px; }
.impact-list { margin-top: 2px; color: var(--theme-primary); }
.reject-change-summary { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--text-secondary); font-size: 13px; }
.change-actions { display: flex; gap: 8px; justify-content: flex-end; }
.rating-input { width: 100%; }