Files
JayuCloud/JC-Salon-Frontend/src/views/OrderDetailView.vue
T
xiaowang 19ca9e2965
自动发布开发环境 Nacos 配置 / publish (push) Successful in 20s
接入微信订阅消息并完善预约通知
2026-11-02 12:11:23 +08:00

417 lines
22 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, h, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { LeftOutlined } from '@ant-design/icons-vue'
import { Input, message, Modal } from 'ant-design-vue'
import { afterSaleApi, orderApi } from '../api/order'
import type { AfterSaleVO, OrderArtistChangeRequestVO, OrderArtistReviewVO } from '../api/order'
import { userApi, type ContactInfoVO } from '@/api/user'
import type { IdType } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { extractLegacyFileId, getCachedSignedImageUrl, getCachedSignedImageUrlSync } from '@/utils/signed-image-cache'
const route = useRoute()
const router = useRouter()
const loading = ref(false)
const order = ref<any | null>(null)
const reviews = ref<OrderArtistReviewVO[]>([])
const changeRequests = ref<OrderArtistChangeRequestVO[]>([])
const afterSales = ref<AfterSaleVO[]>([])
const contact = ref<ContactInfoVO | null>(null)
const quoteReply = ref('')
const quoteSubmitting = ref(false)
const quoteConfirming = ref(false)
const orderId = computed(() => String(route.params.id || route.query.orderId || ''))
const items = computed(() => Array.isArray(order.value?.items) ? order.value.items : [])
const formatMoney = (value?: number | string) => {
const amount = Number(value)
return Number.isFinite(amount) ? `¥${amount.toFixed(2)}` : '¥0.00'
}
const formatDateTime = (value?: string) => value ? String(value).replace('T', ' ').slice(0, 16) : '--'
const isQuoteStatus = (status?: unknown) => Number(status) === 0
const isQuoteConfirming = computed(() => isQuoteStatus(order.value?.status))
const statusClass = (status?: number) => isQuoteStatus(status) ? 'quote' : status === 2 ? 'done' : status === 3 ? 'cancelled' : status === 4 ? 'in-service' : 'pending'
const canApplyAfterSale = computed(() => !isQuoteConfirming.value && Number(order.value?.status) === 2)
const timeline = computed(() => {
const current = order.value || {}
const firstAppointment = items.value.map((item: any) => item.appointmentTime).find(Boolean)
const status = Number(current.status)
if (status === 0) {
return [
{ key: 'created', title: '已创建', text: formatDateTime(current.createTime), done: true, active: false },
{ key: 'quote', title: '确认价格', text: current.quoteStatusText || '等待双方确认', done: Boolean(current.quoteUserConfirmed && current.quoteShopConfirmed), active: true },
{ key: 'appointment', title: '预约时间', text: firstAppointment ? formatDateTime(firstAppointment) : '价格确认后安排', done: Boolean(firstAppointment), active: false },
{ key: 'service', title: '服务完成', text: '待服务', done: false, active: false },
{ key: 'review', title: '评价', text: '完成后可评价', done: false, active: false }
]
}
return [
{ key: 'created', title: '已创建', text: formatDateTime(current.createTime), done: true, active: false },
{ key: 'appointment', title: '预约时间', text: formatDateTime(firstAppointment), done: Boolean(firstAppointment), active: status === 1 },
{ key: 'service', title: status === 3 ? '已取消' : '服务完成', text: formatDateTime(current.completeTime || current.cancelTime || current.updateTime), done: status === 2 || status === 3, active: status === 2 || status === 3 },
{ key: 'review', title: '评价', text: reviews.value.length ? `${reviews.value.length} 条记录` : '完成后可评价', done: reviews.value.some(item => Number(item.status) === 1 || item.rating), active: reviews.value.some(item => Number(item.status) !== 1 && !item.rating) },
{ key: 'after-sale', title: '售后', text: afterSales.value.length ? `${afterSales.value.length} 条记录` : '暂无售后', done: afterSales.value.length > 0, active: afterSales.value.some(item => item.status === 'PENDING') }
]
})
const hasAmount = (value: unknown) => value !== undefined && value !== null && value !== '' && Number.isFinite(Number(value))
const formatQuoteAmount = (value: unknown, fallback = '--') => hasAmount(value) ? formatMoney(value as number | string) : fallback
const quoteReferencePrice = (item: any) => item?.referencePrice ?? item?.price
const quoteMessages = computed(() => Array.isArray(order.value?.quoteMessages) ? order.value.quoteMessages : [])
const quoteStatusText = computed(() => order.value?.quoteStatusText || order.value?.statusText || '确认价格中')
const quoteExpireText = computed(() => {
const expireTime = formatDateTime(order.value?.quoteExpireTime)
return expireTime !== '--' ? `有效期至 ${expireTime}` : '等待门店报价'
})
const quoteMessageItems = (quoteMessage: any) => Array.isArray(quoteMessage?.items) ? quoteMessage.items : []
const quoteActorText = (quoteMessage: any) => {
if (quoteMessage?.actorTypeText) return quoteMessage.actorTypeText
if (String(quoteMessage?.actorType || '').toUpperCase() === 'USER') return '用户'
if (String(quoteMessage?.actorType || '').toUpperCase() === 'SHOP') return '门店'
return '系统'
}
const quoteActionText = (quoteMessage: any) => quoteMessage?.actionText || quoteMessage?.action || '报价更新'
const quoteMessageKey = (quoteMessage: any, index: string | number) => {
return String(quoteMessage?.id ?? `${quoteMessage?.createTime || 'quote'}-${quoteMessage?.action || index}`)
}
const quoteMessageItemKey = (quoteItem: any) => {
return String(quoteItem?.orderItemId ?? quoteItem?.productId ?? quoteItem?.id ?? JSON.stringify(quoteItem))
}
const quoteMessageItemText = (quoteItem: any) => {
const sourceItem = items.value.find((item: any) => String(item.id) === String(quoteItem?.orderItemId) || String(item.productId) === String(quoteItem?.productId))
const title = quoteItem?.productTitle || sourceItem?.productTitle || '预约项目'
const amount = quoteItem?.confirmedPrice ?? quoteItem?.quotedPrice ?? quoteItem?.price
return hasAmount(amount) ? `${title}:${formatMoney(amount)}` : title
}
const orderHasCurrentQuote = computed(() => {
return items.value.some((item: any) => hasAmount(item?.quotedPrice ?? item?.confirmedPrice))
})
const resolveOrderImages = async () => {
for (const item of items.value) {
const imageId = extractLegacyFileId(item.productImage)
if (!imageId) continue
const cachedUrl = getCachedSignedImageUrlSync(imageId)
if (cachedUrl) item.productImage = cachedUrl
item.productImage = await getCachedSignedImageUrl(imageId)
}
}
const loadRelated = async () => {
if (!orderId.value) return
const [reviewList, changeList, afterSalePage, contactInfo] = await Promise.all([
orderApi.getOrderReviews(orderId.value).catch(() => []),
orderApi.getOrderArtistChangeRequests(orderId.value).catch(() => []),
afterSaleApi.listMy({ page: 1, size: 50 }).catch(() => ({ list: [] })),
userApi.getOrderArtistContact(orderId.value).catch(() => null)
])
reviews.value = reviewList || []
changeRequests.value = changeList || []
afterSales.value = ((afterSalePage as any)?.list || []).filter((item: AfterSaleVO) => String(item.orderId) === orderId.value)
contact.value = contactInfo
}
const loadOrder = async () => {
if (!orderId.value) {
order.value = null
return
}
loading.value = true
try {
order.value = await orderApi.getOrderDetail(orderId.value)
await resolveOrderImages()
await loadRelated()
} catch (error: any) {
order.value = null
message.error(error?.message || '订单详情加载失败')
} finally {
loading.value = false
}
}
const submitQuoteReply = async () => {
if (!order.value?.id) return
const remark = quoteReply.value.trim()
if (!remark) {
message.warning('请先填写回复内容')
return
}
quoteSubmitting.value = true
try {
await runWithGlobalLoading(async () => {
await orderApi.replyQuote(order.value.id, { remark })
await loadOrder()
})
quoteReply.value = ''
message.success('报价回复已发送')
} catch (error: any) {
message.error(error?.message || '发送报价回复失败')
} finally {
quoteSubmitting.value = false
}
}
const confirmQuote = () => {
if (!order.value?.id) return
if (!orderHasCurrentQuote.value) {
message.warning('当前暂无可确认报价')
return
}
Modal.confirm({
title: '确认当前报价',
content: '确认后门店会继续处理预约,请确认当前报价无误。',
onOk: async () => {
quoteConfirming.value = true
try {
await runWithGlobalLoading(async () => {
await orderApi.confirmUserQuote(order.value.id)
await loadOrder()
})
message.success('已确认当前报价')
} catch (error: any) {
message.error(error?.message || '确认报价失败')
} finally {
quoteConfirming.value = false
}
}
})
}
const cancelOrder = () => {
if (!order.value?.id) return
const cancelReason = ref('')
Modal.confirm({
title: '取消订单',
content: h('div', [
h('p', { style: 'margin-bottom: 12px' }, '确认取消这笔订单吗?'),
h(Input.TextArea, {
rows: 3,
maxlength: 255,
showCount: true,
placeholder: '可填写取消原因',
'onUpdate:value': (value: string) => { cancelReason.value = value }
})
]),
onOk: async () => {
await runWithGlobalLoading(() => orderApi.cancelOrder(order.value.id as IdType, cancelReason.value.trim()))
message.success('订单已取消')
await loadOrder()
}
})
}
onMounted(loadOrder)
</script>
<template>
<div class="detail-page">
<header class="header">
<a-button type="text" @click="router.back()">
<LeftOutlined />
</a-button>
<h1>订单详情</h1>
<a-button type="link" @click="router.push('/orders')">列表</a-button>
</header>
<main class="content">
<a-spin :spinning="loading">
<a-empty v-if="!order" description="未找到订单">
<a-button type="primary" @click="router.push('/orders')">查看订单中心</a-button>
</a-empty>
<template v-else>
<section class="hero-card">
<span class="eyebrow">{{ isQuoteConfirming ? '询价预约' : '预约订单' }}</span>
<h2>{{ order.orderNo || `订单 ${order.id}` }}</h2>
<p>{{ order.shopName || '当前门店' }}</p>
<div class="hero-meta">
<strong>{{ formatMoney(order.actualAmount || order.totalAmount) }}</strong>
<span :class="['status-pill', statusClass(order.status)]">{{ isQuoteConfirming ? quoteStatusText : (order.statusText || '处理中') }}</span>
</div>
</section>
<section class="timeline-card">
<article v-for="node in timeline" :key="node.key" :class="{ done: node.done, active: node.active }">
<strong>{{ node.title }}</strong>
<span>{{ node.text }}</span>
</article>
</section>
<section v-if="isQuoteConfirming" class="section-card quote-detail-panel">
<div class="section-head">
<div>
<h3>报价确认</h3>
<p>{{ quoteStatusText }} · {{ quoteExpireText }}</p>
</div>
</div>
<p>客户备注:{{ order.customerRemark || '暂无备注' }}</p>
<div class="quote-flags">
<span :class="{ active: order.quoteUserConfirmed }">用户{{ order.quoteUserConfirmed ? '已确认' : '待确认' }}</span>
<span :class="{ active: order.quoteShopConfirmed }">门店{{ order.quoteShopConfirmed ? '已确认' : '待确认' }}</span>
</div>
<div class="quote-items">
<article v-for="item in items" :key="item.id || item.productId" class="quote-item">
<strong>{{ item.productTitle || '预约项目' }}</strong>
<span>参考价 {{ formatQuoteAmount(quoteReferencePrice(item), '待确认') }}</span>
<span>当前报价 {{ formatQuoteAmount(item.quotedPrice, '待报价') }}</span>
<span>最终价 {{ formatQuoteAmount(item.confirmedPrice, '待确认') }}</span>
</article>
</div>
<div class="quote-history">
<strong>报价历史</strong>
<div v-if="quoteMessages.length" class="quote-history__list">
<article v-for="(quoteMessage, index) in quoteMessages" :key="quoteMessageKey(quoteMessage, index)" class="quote-history__item">
<div>
<span>{{ quoteActorText(quoteMessage) }}</span>
<em>{{ quoteActionText(quoteMessage) }}</em>
<small>{{ formatDateTime(quoteMessage.createTime) }}</small>
</div>
<p v-if="quoteMessage.remark">{{ quoteMessage.remark }}</p>
<div v-if="quoteMessageItems(quoteMessage).length" class="quote-history__prices">
<span v-for="quoteItem in quoteMessageItems(quoteMessage)" :key="quoteMessageItemKey(quoteItem)">
{{ quoteMessageItemText(quoteItem) }}
</span>
</div>
</article>
</div>
<p v-else>暂无报价历史</p>
</div>
<div class="quote-reply">
<a-textarea v-model:value="quoteReply" :rows="3" :maxlength="300" placeholder="给门店补充说明或回复当前报价" />
<div class="quote-reply__actions">
<a-button :loading="quoteSubmitting" @click="submitQuoteReply">发送回复</a-button>
<a-button
v-if="!order.quoteUserConfirmed"
type="primary"
:loading="quoteConfirming"
:disabled="!orderHasCurrentQuote"
@click="confirmQuote"
>
确认当前报价
</a-button>
<span v-else class="quote-confirmed">你已确认当前报价</span>
</div>
</div>
</section>
<section class="section-card">
<div class="section-head">
<h3>预约项目</h3>
<a-button type="link" @click="router.push({ path: '/service-progress', query: { orderId } })">服务进度</a-button>
</div>
<article v-for="item in items" :key="item.id" class="item-row">
<div class="thumb">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" loading="lazy" decoding="async" />
<span v-else>{{ String(item.productTitle || '项').slice(0, 1) }}</span>
</div>
<div class="item-main">
<strong>{{ item.productTitle || '预约项目' }}</strong>
<span>{{ isQuoteConfirming ? '参考价 ' : '' }}{{ formatMoney(item.price) }} x {{ item.quantity || 1 }}</span>
<span v-if="item.artistName">美甲师:{{ item.artistName }}</span>
<span v-if="item.appointmentTime">预约:{{ formatDateTime(item.appointmentTime) }}</span>
</div>
</article>
</section>
<section v-if="contact" class="section-card">
<h3>联系信息</h3>
<p>{{ contact.contactName || contact.roleLabel || '服务联系人' }}</p>
<p v-if="contact.phoneAvailable && contact.phone">电话:{{ contact.phone }}</p>
<p v-if="contact.wechatAvailable && contact.wechatId">微信:{{ contact.wechatId }}</p>
<p v-if="contact.platformContactText">{{ contact.platformContactText }}</p>
</section>
<section v-if="afterSales.length || changeRequests.length || reviews.length" class="section-card">
<h3>关联记录</h3>
<p v-for="item in afterSales" :key="`as-${item.id}`">售后 {{ item.afterSaleNo || item.id }}:{{ item.status || '-' }}</p>
<p v-for="item in changeRequests" :key="`change-${item.id}`">改派:{{ item.statusText || item.status || '-' }}</p>
<p v-for="item in reviews" :key="`review-${item.id}`">评价:{{ item.statusText || item.rating || '待评价' }}</p>
</section>
<section class="action-bar">
<a-button v-if="canApplyAfterSale" @click="router.push({ path: '/after-sale/apply', query: { orderId } })">申请售后</a-button>
<a-button v-if="order.status === 1" danger @click="cancelOrder">取消订单</a-button>
</section>
</template>
</a-spin>
</main>
</div>
</template>
<style scoped>
.detail-page { min-height: 100vh; padding-top: 60px; background: var(--theme-page-bg); color: var(--text-primary); }
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 9px 14px; background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
.header h1 { margin: 0; font-size: 18px; }
.content { padding: 16px 14px 28px; }
.hero-card, .section-card, .timeline-card { border: 1px solid var(--theme-border); border-radius: 20px; background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent); box-shadow: 0 18px 44px rgba(23, 33, 31, 0.08); }
.hero-card { padding: 22px; background: var(--theme-gradient-soft); }
.eyebrow { display: block; color: var(--theme-primary); font-size: 12px; font-weight: 700; letter-spacing: .05em; }
.hero-card h2 { margin: 10px 0 6px; font-size: 21px; }
.hero-card p { margin: 0; color: var(--text-secondary); }
.hero-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.hero-meta strong { font-size: 20px; }
.status-pill { padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--theme-primary-soft); color: var(--theme-primary); }
.status-pill.quote { color: #6b4600; background: #fff2cc; }
.status-pill.cancelled { color: var(--theme-accent); }
.timeline-card { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; overflow: hidden; margin-top: 14px; background: var(--theme-border); }
.timeline-card article { min-width: 0; padding: 12px 8px; background: var(--theme-card-bg); color: var(--text-secondary); }
.timeline-card article.active { color: var(--theme-primary); }
.timeline-card article.done strong { color: var(--theme-primary); }
.timeline-card strong, .timeline-card span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-card strong { font-size: 12px; }
.timeline-card span { margin-top: 4px; font-size: 11px; }
.section-card { margin-top: 14px; padding: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-card h3 { margin: 0 0 12px; font-size: 17px; }
.section-card p { margin: 8px 0 0; color: var(--text-secondary); line-height: 1.6; }
.section-head p { margin: 4px 0 0; font-size: 13px; }
.quote-detail-panel { display: grid; gap: 12px; }
.quote-flags { display: flex; flex-wrap: wrap; gap: 8px; }
.quote-flags span { padding: 4px 9px; border-radius: 999px; color: var(--text-secondary); background: var(--theme-primary-soft); font-size: 12px; }
.quote-flags span.active { color: var(--theme-primary); font-weight: 700; }
.quote-items, .quote-history, .quote-history__list, .quote-reply { display: grid; gap: 8px; }
.quote-item { display: grid; grid-template-columns: minmax(0, 1.35fr) repeat(3, minmax(82px, auto)); gap: 8px; align-items: center; min-width: 0; padding: 10px; border-radius: 12px; background: color-mix(in srgb, var(--theme-primary-soft) 48%, var(--theme-card-bg)); }
.quote-item strong { min-width: 0; overflow-wrap: anywhere; color: var(--text-primary); font-size: 13px; }
.quote-item span, .quote-history__item small, .quote-confirmed { color: var(--text-secondary); font-size: 12px; }
.quote-history > strong { color: var(--text-primary); font-size: 13px; }
.quote-history__item { display: grid; gap: 6px; padding: 10px; border-radius: 12px; background: color-mix(in srgb, var(--theme-primary-soft) 42%, var(--theme-card-bg)); }
.quote-history__item div { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.quote-history__item span, .quote-history__item em { color: var(--theme-primary); font-size: 12px; font-style: normal; font-weight: 700; }
.quote-history__item p { margin: 0; overflow-wrap: anywhere; font-size: 13px; }
.quote-history__prices { display: flex; flex-wrap: wrap; gap: 6px; }
.quote-history__prices span { padding: 3px 7px; border-radius: 8px; color: var(--text-secondary); background: var(--theme-card-bg); font-size: 12px; }
.quote-reply__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.quote-confirmed { display: inline-flex; align-items: center; min-height: 32px; color: var(--theme-primary); font-weight: 700; }
.item-row { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--theme-border); }
.item-row:first-of-type { border-top: 0; padding-top: 0; }
.thumb { width: 64px; height: 64px; flex: 0 0 auto; border-radius: 14px; overflow: hidden; display: grid; place-items: center; background: var(--theme-primary-soft); color: var(--theme-primary); font-weight: 700; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-main { display: grid; gap: 5px; min-width: 0; color: var(--text-secondary); font-size: 13px; }
.item-main strong { color: var(--text-primary); font-size: 15px; }
.action-bar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 16px; }
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
:deep(.ant-btn-link) { color: var(--theme-primary); }
@media (max-width: 640px) {
.quote-item { grid-template-columns: 1fr; }
.quote-reply__actions { justify-content: stretch; }
.quote-reply__actions :deep(.ant-btn) { flex: 1 1 140px; }
}
</style>