Files
JayuCloud/YumiNail-Frontend/src/views/OrderDetailView.vue
T

242 lines
12 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, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { LeftOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { afterSaleApi, orderApi, paymentApi } 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 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 statusClass = (status?: number) => status === 2 ? 'done' : status === 3 ? 'cancelled' : 'pending'
const isOrderPaid = (target: any) => String(target?.paymentStatus || '').toUpperCase() === 'PAID'
const canPreparePayment = computed(() => Number(order.value?.status) === 1 && !isOrderPaid(order.value))
const canMockPay = computed(() => Number(order.value?.status) === 1 && String(order.value?.paymentStatus || '').toUpperCase() === 'PAYING')
const canApplyAfterSale = computed(() => Number(order.value?.status) === 2 || isOrderPaid(order.value))
const timeline = computed(() => {
const current = order.value || {}
const firstAppointment = items.value.map((item: any) => item.appointmentTime).find(Boolean)
const status = Number(current.status)
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 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 preparePayment = async () => {
if (!order.value?.id) return
await runWithGlobalLoading(async () => {
await paymentApi.prepareOrderPayment(order.value.id)
await loadOrder()
})
message.success('支付单已准备')
}
const mockPay = async () => {
if (!order.value?.id) return
await runWithGlobalLoading(async () => {
await paymentApi.mockSuccess(order.value.id)
await loadOrder()
})
message.success('模拟支付成功')
}
const cancelOrder = () => {
if (!order.value?.id) return
Modal.confirm({
title: '取消订单',
content: '确认取消这笔订单吗?',
onOk: async () => {
await runWithGlobalLoading(() => orderApi.cancelOrder(order.value.id as IdType))
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">预约订单</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)]">{{ 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 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>{{ 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="canPreparePayment" @click="preparePayment">准备支付</a-button>
<a-button v-if="canMockPay" type="primary" @click="mockPay">模拟支付</a-button>
<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(74, 68, 63, 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.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; }
.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); }
</style>