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

216 lines
8.8 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>订单号:{{ order.orderNo }}</span>
<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>
</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>
</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'
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>>({})
const filters = reactive({
keyword: '',
status: 'all' as 'all' | number,
date: null as any,
minAmount: undefined as number | undefined,
maxAmount: 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
})
})
/** 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'
}
/** 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
}
/** 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')
return
}
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-03-19 20:19:41 +08:00
} catch {
message.error('获取订单列表失败')
}
}
/** 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>
2026-03-19 20:19:41 +08:00
.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; }
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; background: #fff; border-bottom: 1px solid #f0f0f0; }
.header h1 { margin: 0; font-size: 18px; }
.placeholder { width: 40px; height: 40px; }
.content { padding: 15px; }
.filter-panel { display: grid; gap: 10px; margin-bottom: 12px; padding: 12px; border-radius: 8px; background: #fff; }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-select, .filter-date, .filter-number { flex: 1; min-width: 0; }
.filter-summary { color: #888; font-size: 12px; text-align: right; }
2026-03-19 20:19:41 +08:00
.order-card { margin-bottom: 12px; border-radius: 12px; }
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; }
.order-shop { margin: -4px 0 12px; color: #7a5262; 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: #fff7e6; color: #fa8c16; }
.completed { background: #f6ffed; color: #52c41a; }
.cancelled { background: #fff1f0; color: #ff4d4f; }
.item { display: flex; gap: 12px; margin-bottom: 12px; }
.thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #eef3ff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.main { flex: 1; }
.title { font-weight: 600; }
.line { margin-top: 4px; color: #666; font-size: 13px; }
.appointment { color: #1890ff; }
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>