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

480 lines
20 KiB
Vue
Raw Normal View History

<template>
2026-03-19 20:19:41 +08:00
<div class="page">
<header class="header">
2026-03-19 20:19:41 +08:00
<a-button type="text" @click="router.back()">
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>我的订单</h1>
2026-03-19 20:19:41 +08:00
<div class="placeholder" />
</header>
2026-03-19 20:19:41 +08:00
<main class="content">
<section v-if="orders.length" class="filter-panel">
<a-input v-model:value="filters.keyword" allow-clear placeholder="搜索订单号、作品、美甲师" />
<div class="filter-row">
<a-select v-model:value="filters.status" class="filter-select" placeholder="订单状态">
<a-select-option value="all">全部状态</a-select-option>
<a-select-option :value="1">待使用</a-select-option>
<a-select-option :value="2">已完成</a-select-option>
<a-select-option :value="3">已取消</a-select-option>
</a-select>
<a-date-picker v-model:value="filters.date" class="filter-date" popup-class-name="yumi-date-picker-panel" placeholder="预约日期" />
</div>
<div class="filter-row">
<a-input-number v-model:value="filters.minAmount" class="filter-number" :min="0" placeholder="最低金额" />
<a-input-number v-model:value="filters.maxAmount" class="filter-number" :min="0" placeholder="最高金额" />
<a-button @click="resetFilters">重置</a-button>
</div>
<div class="filter-summary">共 {{ filteredOrders.length }} / {{ orders.length }} 个订单</div>
</section>
2026-03-19 20:19:41 +08:00
<a-empty v-if="!orders.length" description="暂无订单">
<a-button type="primary" @click="router.push('/products')">去逛逛</a-button>
</a-empty>
<a-empty v-else-if="!filteredOrders.length" description="没有符合条件的订单">
<a-button @click="resetFilters">清空筛选</a-button>
</a-empty>
2026-03-19 20:19:41 +08:00
<a-card v-for="order in filteredOrders" :key="order.id" class="order-card">
2026-03-19 20:19:41 +08:00
<div class="order-head">
<span class="order-no">订单号:{{ order.orderNo }}</span>
<a-button size="small" type="link" @click="copyOrderNo(order.orderNo)">复制</a-button>
2026-03-19 20:19:41 +08:00
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
</div>
<div v-if="order.shopName" class="order-shop">所属店铺:{{ order.shopName }}</div>
2026-03-19 20:19:41 +08:00
<div v-for="item in order.items" :key="item.id" class="item">
<div class="thumb">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" />
<span v-else>{{ item.productTitle[0] }}</span>
</div>
2026-03-19 20:19:41 +08:00
<div class="main">
<div class="title">{{ item.productTitle }}</div>
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div v-if="item.artistName" class="line">美甲师:{{ item.artistName }}</div>
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
2026-05-23 15:16:40 +08:00
<div v-if="submittedReviewForItem(order, item)" class="review-summary">
已评价:{{ formatRating(submittedReviewForItem(order, item)?.rating) }} 分
<span v-if="submittedReviewForItem(order, item)?.content"> · {{ submittedReviewForItem(order, item)?.content }}</span>
</div>
<div v-else-if="pendingReviewForItem(order, item)" class="review-action">
<span>待评价:{{ pendingReviewForItem(order, item)?.artistName || item.artistName || '美甲师' }}</span>
<a-button size="small" type="primary" @click="openReviewModal(pendingReviewForItem(order, item))">评价美甲师</a-button>
</div>
<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 v-if="pendingChangeRequestForItem(order, item)?.reason">原因:{{ pendingChangeRequestForItem(order, item)?.reason }}</span>
</div>
<div class="change-actions">
<a-button size="small" type="primary" @click="approveArtistChange(pendingChangeRequestForItem(order, item))">同意</a-button>
<a-button size="small" danger @click="openRejectArtistChange(pendingChangeRequestForItem(order, item))">拒绝</a-button>
</div>
</div>
</div>
2026-03-19 20:19:41 +08:00
</div>
<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>
</a-card>
</main>
2026-05-23 15:16:40 +08:00
<a-modal
v-model:open="reviewModalOpen"
title="评价美甲师"
:confirm-loading="reviewSubmitting"
@ok="submitReview"
@cancel="closeReviewModal"
>
<a-form layout="vertical">
<a-form-item label="评分" required>
<a-input-number
v-model:value="reviewForm.rating"
class="rating-input"
:min="0.5"
:max="5"
:step="0.5"
placeholder="0.5-5 分"
/>
</a-form-item>
<a-form-item label="评价内容">
<a-textarea v-model:value="reviewForm.content" :rows="4" :maxlength="500" placeholder="写下这次服务体验" />
</a-form-item>
</a-form>
</a-modal>
<a-modal
v-model:open="rejectModalOpen"
title="拒绝改派申请"
:confirm-loading="changeProcessing"
@ok="submitRejectArtistChange"
@cancel="closeRejectArtistChange"
>
<a-form layout="vertical">
<a-form-item label="拒绝原因">
<a-textarea v-model:value="rejectForm.rejectReason" :rows="3" :maxlength="300" placeholder="可选,请填写拒绝原因" />
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* 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 { LeftOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { fileApi } from '../api/index'
2026-03-19 20:19:41 +08:00
import { orderApi } from '../api/order'
2026-05-23 15:16:40 +08:00
import type { OrderArtistChangeRequestVO, OrderArtistReviewVO } from '../api/order'
import { userApi } from '@/api/user'
2026-03-27 14:55:41 +08:00
import type { IdType } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
const router = useRouter()
const orders = ref<any[]>([])
const imageIdCache = ref<Record<string, string>>({})
2026-05-23 15:16:40 +08:00
const pendingReviews = ref<OrderArtistReviewVO[]>([])
const orderReviews = ref<Record<string, OrderArtistReviewVO[]>>({})
const pendingChangeRequests = ref<OrderArtistChangeRequestVO[]>([])
const reviewModalOpen = ref(false)
const reviewSubmitting = ref(false)
const activeReview = ref<OrderArtistReviewVO | null>(null)
const rejectModalOpen = ref(false)
const changeProcessing = ref(false)
const activeChangeRequest = ref<OrderArtistChangeRequestVO | null>(null)
const filters = reactive({
keyword: '',
status: 'all' as 'all' | number,
date: null as any,
minAmount: undefined as number | undefined,
maxAmount: undefined as number | undefined
})
2026-05-23 15:16:40 +08:00
const reviewForm = reactive({
rating: undefined as number | undefined,
content: ''
})
const rejectForm = reactive({
rejectReason: ''
})
/** filteredOrders is a reactive state variable used by the template and event handlers. */
const filteredOrders = computed(() => {
const keyword = filters.keyword.trim().toLowerCase()
const targetDate = filters.date?.format?.('YYYY-MM-DD')
return orders.value.filter(order => {
if (filters.status !== 'all' && order.status !== filters.status) return false
const amount = Number(order.actualAmount || 0)
if (filters.minAmount !== undefined && amount < filters.minAmount) return false
if (filters.maxAmount !== undefined && amount > filters.maxAmount) return false
const items = order.items || []
if (targetDate && !items.some((item: any) => String(item.appointmentTime || '').slice(0, 10) === targetDate)) {
return false
}
if (keyword) {
const haystack = [
order.orderNo,
order.shopName,
order.statusText,
...items.flatMap((item: any) => [item.productTitle, item.artistName, item.appointmentTime])
].filter(Boolean).join(' ').toLowerCase()
if (!haystack.includes(keyword)) return false
}
return true
})
})
/** statusClass is a local helper used by this page script. */
2026-03-19 20:19:41 +08:00
const statusClass = (status: number) => {
if (status === 1) return 'pending'
if (status === 2) return 'completed'
return 'cancelled'
}
2026-05-23 15:16:40 +08:00
const sameId = (left: unknown, right: unknown) => {
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
}
const embeddedForItem = <T extends { orderItemId?: IdType }>(order: any, item: any, field: string): T | undefined => {
const itemValue = item?.[field] as T | undefined
if (itemValue) return itemValue
const orderValue = order?.[field] as T | undefined
if (!orderValue) return undefined
return sameId(orderValue.orderItemId, item.id) || (order.items || []).length === 1 ? orderValue : undefined
}
const pendingReviewForItem = (order: any, item: any): OrderArtistReviewVO | undefined => {
const embedded = embeddedForItem<OrderArtistReviewVO>(order, item, 'pendingReview')
if (embedded) return embedded
return pendingReviews.value.find(review => sameId(review.orderId, order.id) && sameId(review.orderItemId, item.id))
}
const submittedReviewForItem = (order: any, item: any): OrderArtistReviewVO | undefined => {
const embedded = embeddedForItem<OrderArtistReviewVO>(order, item, 'reviewSummary')
if (embedded) return embedded
return (orderReviews.value[String(order.id)] || []).find(review => sameId(review.orderItemId, item.id) && Number(review.status) === 1)
}
const pendingChangeRequestForItem = (order: any, item: any): OrderArtistChangeRequestVO | undefined => {
const embedded = embeddedForItem<OrderArtistChangeRequestVO>(order, item, 'pendingArtistChangeRequest')
if (embedded) return embedded
return pendingChangeRequests.value.find(request => sameId(request.orderId, order.id) && sameId(request.orderItemId, item.id))
}
const formatRating = (rating?: number) => {
return Number(rating || 0).toFixed(1)
}
/** resetFilters is a local helper used by this page script. */
const resetFilters = () => {
filters.keyword = ''
filters.status = 'all'
filters.date = null
filters.minAmount = undefined
filters.maxAmount = undefined
}
const copyOrderNo = async (orderNo: string) => {
try {
await navigator.clipboard.writeText(orderNo)
message.success('订单号已复制')
} catch {
message.warning('复制失败,请手动复制订单号')
}
}
2026-05-23 15:16:40 +08:00
const loadPendingReviews = async () => {
try {
pendingReviews.value = (await orderApi.getMyPendingReviews()) || []
} catch {
pendingReviews.value = []
}
}
const loadOrderReviews = 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.getOrderReviews(orderId)] as const
} catch {
return [String(orderId), []] as const
}
}))
orderReviews.value = Object.fromEntries(entries)
}
const loadPendingArtistChangeRequests = async () => {
try {
pendingChangeRequests.value = (await orderApi.getMyPendingArtistChangeRequests()) || []
} catch {
pendingChangeRequests.value = []
}
}
const refreshOrderExtensions = async () => {
await Promise.all([
loadPendingReviews(),
loadOrderReviews(),
loadPendingArtistChangeRequests()
])
}
/** loadOrders is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-19 20:19:41 +08:00
const loadOrders = async () => {
try {
const userInfo = await userApi.getUserInfo()
if (userInfo.type === 2 || userInfo.type === 3) {
router.replace('/artist-orders')
2026-05-23 15:16:40 +08:00
return false
}
2026-03-19 20:19:41 +08:00
orders.value = (await orderApi.getOrderList() as unknown as any[]) || []
for (const order of orders.value) {
for (const item of order.items || []) {
const match = item.productImage?.replace(/<[^>]*>/g, '').match(/\/api\/file\/get\/(\d+)/)
if (!match?.[1]) continue
const imageId = match[1]
try {
2026-03-27 14:55:41 +08:00
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(imageId) as any
2026-03-19 20:19:41 +08:00
item.productImage = imageIdCache.value[imageId]
} catch {
item.productImage = ''
}
}
}
2026-05-23 15:16:40 +08:00
await refreshOrderExtensions()
return true
2026-03-19 20:19:41 +08:00
} catch {
message.error('获取订单列表失败')
2026-05-23 15:16:40 +08:00
return false
}
}
const openReviewModal = (review?: OrderArtistReviewVO) => {
if (!review) return
activeReview.value = review
reviewForm.rating = review.rating ? Number(review.rating) : undefined
reviewForm.content = review.content || ''
reviewModalOpen.value = true
}
const closeReviewModal = () => {
reviewModalOpen.value = false
activeReview.value = null
reviewForm.rating = undefined
reviewForm.content = ''
}
const submitReview = async () => {
if (!activeReview.value) return
const rating = Number(reviewForm.rating)
if (!rating || rating < 0.5 || rating > 5) {
message.warning('请填写 0.5-5 分的评分')
return
}
const normalizedRating = Math.round(rating * 2) / 2
if (Math.abs(normalizedRating - rating) > 0.001) {
message.warning('评分请按 0.5 分递增')
return
}
reviewSubmitting.value = true
try {
await orderApi.submitArtistReview(activeReview.value.id, {
rating: normalizedRating,
content: reviewForm.content.trim() || undefined,
imageFileIds: []
})
message.success('评价已提交')
closeReviewModal()
await Promise.all([loadPendingReviews(), loadOrderReviews()])
} catch {
message.error('提交评价失败')
} finally {
reviewSubmitting.value = false
}
}
const approveArtistChange = (request?: OrderArtistChangeRequestVO) => {
if (!request) return
Modal.confirm({
title: '同意改派申请',
content: `确定同意改派给「${request.requestedArtistName || '新美甲师'}」吗?`,
onOk: async () => {
try {
await runWithGlobalLoading(async () => {
await orderApi.approveArtistChange(request.id)
await loadOrders()
})
message.success('已同意改派')
} catch {
message.error('处理改派申请失败')
}
}
})
}
const openRejectArtistChange = (request?: OrderArtistChangeRequestVO) => {
if (!request) return
activeChangeRequest.value = request
rejectForm.rejectReason = ''
rejectModalOpen.value = true
}
const closeRejectArtistChange = () => {
rejectModalOpen.value = false
activeChangeRequest.value = null
rejectForm.rejectReason = ''
}
const submitRejectArtistChange = async () => {
if (!activeChangeRequest.value) return
changeProcessing.value = true
try {
await orderApi.rejectArtistChange(activeChangeRequest.value.id, {
rejectReason: rejectForm.rejectReason.trim() || undefined
})
message.success('已拒绝改派')
closeRejectArtistChange()
await loadOrders()
} catch {
message.error('拒绝改派申请失败')
} finally {
changeProcessing.value = false
}
}
/** cancelOrder is a local helper used by this page script. */
2026-03-27 14:55:41 +08:00
const cancelOrder = (orderId: IdType) => {
Modal.confirm({
title: '确认取消订单',
content: '确定要取消这个订单吗?',
onOk: async () => {
try {
await runWithGlobalLoading(() => orderApi.cancelOrder(orderId))
message.success('订单已取消')
2026-03-19 20:19:41 +08:00
await loadOrders()
} catch {
message.error('取消订单失败')
}
}
})
}
2026-03-19 20:19:41 +08:00
onMounted(loadOrders)
</script>
<style scoped>
.page { min-height: 100vh; padding-top: 60px; background: linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.92)), var(--theme-background-image), var(--theme-page-bg); background-size: cover, cover, auto; background-position: center top; 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 15px; background: rgba(255, 255, 255, 0.92); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
.header h1 { margin: 0; font-size: 18px; color: var(--text-primary); }
2026-03-19 20:19:41 +08:00
.placeholder { width: 40px; height: 40px; }
.content { padding: 15px; }
.filter-panel { display: grid; gap: 10px; margin-bottom: 12px; padding: 12px; border-radius: 14px; background: var(--theme-card-bg); border: 1px solid var(--theme-border); box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08); }
.filter-row { display: flex; gap: 8px; align-items: center; }
.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 :deep(.ant-card-body) { padding: 16px; }
2026-03-19 20:19:41 +08:00
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
.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; }
2026-03-19 20:19:41 +08:00
.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); }
2026-03-19 20:19:41 +08:00
.item { display: flex; gap: 12px; margin-bottom: 12px; }
.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); }
2026-03-19 20:19:41 +08:00
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.main { flex: 1; }
.title { font-weight: 600; color: var(--text-primary); }
.line { margin-top: 4px; color: var(--text-secondary); font-size: 13px; }
.appointment { color: var(--theme-primary); }
2026-05-23 15:16:40 +08:00
.review-summary { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
.review-action { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
.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); }
.change-actions { display: flex; gap: 8px; justify-content: flex-end; }
.rating-input { width: 100%; }
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
:deep(.ant-btn-link) { color: var(--theme-primary); }
2026-03-24 09:50:55 +08:00
@media (min-width: 992px) {
.content {
max-width: 980px;
margin: 0 auto;
padding: 24px;
2026-03-24 09:50:55 +08:00
}
}
2026-03-19 20:19:41 +08:00
</style>