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

1041 lines
46 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 class="growth-panel">
<div>
<strong>{{ growthSummary.levelName || '成长会员' }}</strong>
<span>成长值 {{ growthSummary.growthValue ?? 0 }} · 预约 {{ growthSummary.appointmentCount ?? 0 }} 次 · 评价 {{ growthSummary.reviewCount ?? 0 }} 次</span>
</div>
<a-button size="small" @click="loadGrowthSummary">刷新</a-button>
</section>
<section v-if="myAfterSales.length" class="after-sale-panel">
<div class="after-sale-panel__title">我的售后</div>
<div v-for="item in myAfterSales.slice(0, 3)" :key="item.id" class="after-sale-row">
<span>{{ item.afterSaleNo || `售后 ${item.id}` }}</span>
<strong>{{ afterSaleStatusText(item.status) }}</strong>
</div>
</section>
<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"
:class="{ focused: sameId(focusedOrderId, order.id) }"
>
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>
<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>
2026-03-19 20:19:41 +08:00
<div
v-for="item in order.items"
:key="item.id"
class="item"
:class="{ focused: sameId(focusedOrderItemId, item.id) }"
>
2026-03-19 20:19:41 +08:00
<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>原美甲师:{{ artistChangeDisplay(pendingChangeRequestForItem(order, item), item).originalArtistName }}</span>
<span>新美甲师:{{ artistChangeDisplay(pendingChangeRequestForItem(order, item), item).requestedArtistName }}</span>
2026-05-23 15:16:40 +08:00
<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>
2026-05-23 15:16:40 +08:00
</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>
<div class="footer-actions">
<a-button v-if="canPreparePayment(order)" size="small" @click="preparePayment(order)">准备支付</a-button>
<a-button v-if="canMockPay(order)" size="small" type="primary" @click="mockPay(order)">模拟支付</a-button>
<a-button v-if="canApplyAfterSale(order)" size="small" @click="openAfterSaleModal(order)">申请售后</a-button>
<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>
2026-03-19 20:19:41 +08:00
</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">
<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>
2026-05-23 15:16:40 +08:00
<a-form-item label="拒绝原因">
<a-textarea v-model:value="rejectForm.rejectReason" :rows="3" :maxlength="300" placeholder="可选,请填写拒绝原因" />
</a-form-item>
</a-form>
</a-modal>
<a-modal
v-model:open="afterSaleModalOpen"
title="申请售后"
:confirm-loading="afterSaleSubmitting"
@ok="submitAfterSale"
@cancel="closeAfterSaleModal"
>
<a-form layout="vertical">
<a-form-item label="订单">
<a-input :value="activeAfterSaleOrder?.orderNo || ''" disabled />
</a-form-item>
<a-form-item label="订单项">
<a-select v-model:value="afterSaleForm.orderItemId" allow-clear placeholder="可选,默认整单">
<a-select-option v-for="item in activeAfterSaleOrder?.items || []" :key="item.id" :value="item.id">
{{ item.productTitle }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="类型" required>
<a-select v-model:value="afterSaleForm.type">
<a-select-option value="REFUND">退款</a-select-option>
<a-select-option value="AFTER_SALE">售后</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="退款金额">
<a-input-number v-model:value="afterSaleForm.refundAmount" :min="0" :step="0.01" style="width: 100%" />
</a-form-item>
<a-form-item label="原因" required>
<a-textarea v-model:value="afterSaleForm.reason" :rows="4" :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, 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 { afterSaleApi, growthApi, orderApi, paymentApi } from '../api/order'
import type { AfterSaleVO, GrowthSummaryVO, 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'
import { buildRecoveryActions, getRecoveryMessage } from '@/utils/recovery'
import { resolveOrderReviewFocus } from '@/utils/order-review-focus'
2026-05-23 18:44:57 +08:00
/**
* 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 () => {})
2026-05-23 18:44:57 +08:00
/**
* 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.
*/
const orders = ref<any[]>([])
const myAfterSales = ref<AfterSaleVO[]>([])
const growthSummary = ref<GrowthSummaryVO>({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: imageIdCache supports OrderView.vue by holding or executing the image id cache 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 imageIdCache = ref<Record<string, string>>({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: pendingReviews supports OrderView.vue by holding or executing the pending reviews 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.
*/
2026-05-23 15:16:40 +08:00
const pendingReviews = ref<OrderArtistReviewVO[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: orderReviews supports OrderView.vue by holding or executing the order reviews 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.
*/
2026-05-23 15:16:40 +08:00
const orderReviews = ref<Record<string, OrderArtistReviewVO[]>>({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: pendingChangeRequests supports OrderView.vue by holding or executing the pending change requests 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.
*/
2026-05-23 15:16:40 +08:00
const pendingChangeRequests = ref<OrderArtistChangeRequestVO[]>([])
/** historicalChangeRequests stores handled change requests for order timelines. */
const historicalChangeRequests = ref<Record<string, OrderArtistChangeRequestVO[]>>({})
2026-05-23 18:44:57 +08:00
/**
* 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.
*/
2026-05-23 15:16:40 +08:00
const reviewModalOpen = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: reviewSubmitting supports OrderView.vue by holding or executing the review submitting 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.
*/
2026-05-23 15:16:40 +08:00
const reviewSubmitting = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: activeReview supports OrderView.vue by holding or executing the active review 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.
*/
2026-05-23 15:16:40 +08:00
const activeReview = ref<OrderArtistReviewVO | null>(null)
2026-05-23 18:44:57 +08:00
/**
* Purpose: rejectModalOpen supports OrderView.vue by holding or executing the reject 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.
*/
2026-05-23 15:16:40 +08:00
const rejectModalOpen = ref(false)
const afterSaleModalOpen = ref(false)
const afterSaleSubmitting = ref(false)
const activeAfterSaleOrder = ref<any | null>(null)
2026-05-23 18:44:57 +08:00
/**
* Purpose: changeProcessing supports OrderView.vue by holding or executing the change processing 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.
*/
2026-05-23 15:16:40 +08:00
const changeProcessing = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: activeChangeRequest supports OrderView.vue by holding or executing the active change request 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.
*/
2026-05-23 15:16:40 +08:00
const activeChangeRequest = ref<OrderArtistChangeRequestVO | null>(null)
2026-05-23 18:44:57 +08:00
/**
* Purpose: filters supports OrderView.vue by holding or executing the filters 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 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 18:44:57 +08:00
/**
* Purpose: reviewForm supports OrderView.vue by holding or executing the review form 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.
*/
2026-05-23 15:16:40 +08:00
const reviewForm = reactive({
rating: undefined as number | undefined,
content: ''
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: rejectForm supports OrderView.vue by holding or executing the reject form 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.
*/
2026-05-23 15:16:40 +08:00
const rejectForm = reactive({
rejectReason: ''
})
const afterSaleForm = reactive({
orderItemId: undefined as IdType | undefined,
type: 'REFUND',
reason: '',
refundAmount: undefined as number | undefined
})
/** 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
})
})
/** 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. */
2026-03-19 20:19:41 +08:00
const statusClass = (status: number) => {
if (status === 1) return 'pending'
if (status === 2) return 'completed'
return 'cancelled'
}
const isOrderPaid = (order: any) => String(order.paymentStatus || '').toUpperCase() === 'PAID'
const canPreparePayment = (order: any) => Number(order.status) === 1 && !isOrderPaid(order)
const canMockPay = (order: any) => Number(order.status) === 1 && String(order.paymentStatus || '').toUpperCase() === 'PAYING'
const canApplyAfterSale = (order: any) => Number(order.status) === 2 || isOrderPaid(order)
const afterSaleStatusText = (status?: string) => {
if (status === 'PENDING') return '待处理'
if (status === 'APPROVED') return '已通过'
if (status === 'REJECTED') return '已驳回'
return status || '-'
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: sameId supports OrderView.vue by holding or executing the same id 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.
*/
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)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: embeddedForItem supports OrderView.vue by holding or executing the embedded for item 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.
*/
2026-05-23 15:16:40 +08:00
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
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: pendingReviewForItem supports OrderView.vue by holding or executing the pending review for item 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.
*/
2026-05-23 15:16:40 +08:00
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))
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: submittedReviewForItem supports OrderView.vue by holding or executing the submitted review for item 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.
*/
2026-05-23 15:16:40 +08:00
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)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: pendingChangeRequestForItem supports OrderView.vue by holding or executing the pending change request for item 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.
*/
2026-05-23 15:16:40 +08:00
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))
}
/**
* 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
}
2026-05-23 18:44:57 +08:00
/**
* 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.
*/
2026-05-23 15:16:40 +08:00
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 loadGrowthSummary = async () => {
try {
growthSummary.value = await growthApi.getSummary()
} catch (error) {
console.error('加载成长摘要失败:', error)
growthSummary.value = {}
}
}
const loadMyAfterSales = async () => {
try {
const result = await afterSaleApi.listMy({ page: 1, size: 20 })
myAfterSales.value = result.list || []
} catch (error) {
console.error('加载售后列表失败:', error)
myAfterSales.value = []
}
}
const preparePayment = async (order: any) => {
try {
await runWithGlobalLoading(async () => {
await paymentApi.prepareOrderPayment(order.id)
await loadOrders()
})
message.success('支付单已准备,可继续模拟支付')
} catch (error: any) {
message.error(error?.message || '准备支付失败')
}
}
const mockPay = async (order: any) => {
try {
await runWithGlobalLoading(async () => {
await paymentApi.mockSuccess(order.id)
await loadOrders()
})
message.success('模拟支付成功')
} catch (error: any) {
message.error(error?.message || '模拟支付失败')
}
}
const openAfterSaleModal = (order: any) => {
activeAfterSaleOrder.value = order
const firstItem = (order.items || [])[0]
afterSaleForm.orderItemId = firstItem?.id
afterSaleForm.type = 'REFUND'
afterSaleForm.reason = ''
afterSaleForm.refundAmount = Number(order.actualAmount || order.totalAmount || 0)
afterSaleModalOpen.value = true
}
const closeAfterSaleModal = () => {
afterSaleModalOpen.value = false
activeAfterSaleOrder.value = null
afterSaleForm.orderItemId = undefined
afterSaleForm.type = 'REFUND'
afterSaleForm.reason = ''
afterSaleForm.refundAmount = undefined
}
const submitAfterSale = async () => {
if (!activeAfterSaleOrder.value) return
if (!afterSaleForm.reason.trim()) {
message.warning('请填写售后原因')
return
}
afterSaleSubmitting.value = true
try {
await runWithGlobalLoading(async () => {
await afterSaleApi.apply({
orderId: activeAfterSaleOrder.value.id,
orderItemId: afterSaleForm.orderItemId,
type: afterSaleForm.type,
reason: afterSaleForm.reason.trim(),
refundAmount: afterSaleForm.refundAmount
})
await loadMyAfterSales()
})
message.success('售后申请已提交')
closeAfterSaleModal()
} catch (error: any) {
message.error(error?.message || '提交售后失败')
} finally {
afterSaleSubmitting.value = false
}
}
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 || '复刻同款失败,请稍后重试')
}
}
2026-05-23 18:44:57 +08:00
/**
* 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.
*/
const copyOrderNo = async (orderNo: string) => {
try {
await navigator.clipboard.writeText(orderNo)
message.success('订单号已复制')
} catch {
message.warning('复制失败,请手动复制订单号')
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: loadPendingReviews supports OrderView.vue by holding or executing the load pending reviews 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.
*/
2026-05-23 15:16:40 +08:00
const loadPendingReviews = async () => {
try {
pendingReviews.value = (await orderApi.getMyPendingReviews()) || []
} catch {
pendingReviews.value = []
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: loadOrderReviews supports OrderView.vue by holding or executing the load order reviews 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.
*/
2026-05-23 15:16:40 +08:00
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)
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: loadPendingArtistChangeRequests supports OrderView.vue by holding or executing the load pending artist change requests 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.
*/
2026-05-23 15:16:40 +08:00
const loadPendingArtistChangeRequests = async () => {
try {
pendingChangeRequests.value = (await orderApi.getMyPendingArtistChangeRequests()) || []
} catch {
pendingChangeRequests.value = []
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: refreshOrderExtensions supports OrderView.vue by holding or executing the refresh order extensions 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.
*/
2026-05-23 15:16:40 +08:00
const refreshOrderExtensions = async () => {
await Promise.all([
loadPendingReviews(),
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')
})
2026-05-23 15:16:40 +08:00
}
/** 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
} catch (error) {
orders.value = []
openOrdersRecovery(error)
2026-05-23 15:16:40 +08:00
return false
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: openReviewModal supports OrderView.vue by holding or executing the open review modal 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.
*/
2026-05-23 15:16:40 +08:00
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
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: closeReviewModal supports OrderView.vue by holding or executing the close review modal 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.
*/
2026-05-23 15:16:40 +08:00
const closeReviewModal = () => {
reviewModalOpen.value = false
activeReview.value = null
reviewForm.rating = undefined
reviewForm.content = ''
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: submitReview supports OrderView.vue by holding or executing the submit review 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.
*/
2026-05-23 15:16:40 +08:00
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
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: approveArtistChange supports OrderView.vue by holding or executing the approve artist change 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.
*/
2026-05-23 15:16:40 +08:00
const approveArtistChange = (request?: OrderArtistChangeRequestVO) => {
if (!request) return
const display = artistChangeDisplay(request)
2026-05-23 15:16:40 +08:00
Modal.confirm({
title: '同意改派申请',
content: [
`原美甲师:${display.originalArtistName}`,
`新美甲师:${display.requestedArtistName}`,
request.reason ? `原因:${request.reason}` : '',
...display.impactLines
].filter(Boolean).join('\n'),
2026-05-23 15:16:40 +08:00
onOk: async () => {
try {
await runWithGlobalLoading(async () => {
await orderApi.approveArtistChange(request.id)
await loadOrders()
})
message.success('已同意改派')
} catch {
message.error('处理改派申请失败')
}
}
})
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: openRejectArtistChange supports OrderView.vue by holding or executing the open reject artist change 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.
*/
2026-05-23 15:16:40 +08:00
const openRejectArtistChange = (request?: OrderArtistChangeRequestVO) => {
if (!request) return
activeChangeRequest.value = request
rejectForm.rejectReason = ''
rejectModalOpen.value = true
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: closeRejectArtistChange supports OrderView.vue by holding or executing the close reject artist change 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.
*/
2026-05-23 15:16:40 +08:00
const closeRejectArtistChange = () => {
rejectModalOpen.value = false
activeChangeRequest.value = null
rejectForm.rejectReason = ''
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: submitRejectArtistChange supports OrderView.vue by holding or executing the submit reject artist change 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.
*/
2026-05-23 15:16:40 +08:00
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('取消订单失败')
}
}
})
}
onMounted(async () => {
await Promise.all([loadGrowthSummary(), loadMyAfterSales()])
await 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; }
.growth-panel, .after-sale-panel { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 12px; border: 1px solid var(--theme-border); border-radius: 14px; background: var(--theme-card-bg); box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08); }
.growth-panel div { display: grid; gap: 4px; min-width: 0; }
.growth-panel strong, .after-sale-panel__title { color: var(--text-primary); font-weight: 700; }
.growth-panel span { color: var(--text-secondary); font-size: 13px; }
.after-sale-panel { display: grid; }
.after-sale-row { display: flex; justify-content: space-between; gap: 8px; color: var(--text-secondary); font-size: 13px; }
.after-sale-row strong { color: var(--theme-primary); }
.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.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; 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; }
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; }
.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); }
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); }
.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; }
2026-05-23 15:16:40 +08:00
.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>