2026-02-27 16:44:41 +08:00
|
|
|
|
<template>
|
2026-03-19 20:19:41 +08:00
|
|
|
|
<div class="page">
|
2026-02-27 16:44:41 +08:00
|
|
|
|
<header class="header">
|
2026-03-19 20:19:41 +08:00
|
|
|
|
<a-button type="text" @click="router.back()">
|
2026-02-27 16:44:41 +08:00
|
|
|
|
<LeftOutlined :style="{ fontSize: '20px' }" />
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<h1>我的订单</h1>
|
2026-03-19 20:19:41 +08:00
|
|
|
|
<div class="placeholder" />
|
2026-02-27 16:44:41 +08:00
|
|
|
|
</header>
|
|
|
|
|
|
|
2026-03-19 20:19:41 +08:00
|
|
|
|
<main class="content">
|
|
|
|
|
|
<a-empty v-if="!orders.length" description="暂无订单">
|
|
|
|
|
|
<a-button type="primary" @click="router.push('/products')">去逛逛</a-button>
|
2026-02-27 16:44:41 +08:00
|
|
|
|
</a-empty>
|
2026-03-19 20:19:41 +08:00
|
|
|
|
|
|
|
|
|
|
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
|
|
|
|
|
<div class="order-head">
|
|
|
|
|
|
<span>订单号:{{ order.orderNo }}</span>
|
|
|
|
|
|
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<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>
|
2026-02-27 16:44:41 +08:00
|
|
|
|
</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-02-27 16:44:41 +08:00
|
|
|
|
</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-02-27 16:44:41 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-03-19 20:19:41 +08:00
|
|
|
|
import { onMounted, ref } from 'vue'
|
2026-02-27 16:44:41 +08:00
|
|
|
|
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-02-27 16:44:41 +08:00
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const orders = ref<any[]>([])
|
|
|
|
|
|
const imageIdCache = ref<Record<string, string>>({})
|
|
|
|
|
|
|
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-02-27 16:44:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-19 20:19:41 +08:00
|
|
|
|
const loadOrders = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
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 {
|
|
|
|
|
|
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
|
|
|
|
|
|
item.productImage = imageIdCache.value[imageId]
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
item.productImage = ''
|
2026-02-27 16:44:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-19 20:19:41 +08:00
|
|
|
|
} catch {
|
|
|
|
|
|
message.error('获取订单列表失败')
|
2026-02-27 16:44:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-19 20:19:41 +08:00
|
|
|
|
const cancelOrder = (orderId: number) => {
|
2026-02-27 16:44:41 +08:00
|
|
|
|
Modal.confirm({
|
|
|
|
|
|
title: '确认取消订单',
|
|
|
|
|
|
content: '确定要取消这个订单吗?',
|
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await orderApi.cancelOrder(orderId)
|
|
|
|
|
|
message.success('订单已取消')
|
2026-03-19 20:19:41 +08:00
|
|
|
|
await loadOrders()
|
|
|
|
|
|
} catch {
|
2026-02-27 16:44:41 +08:00
|
|
|
|
message.error('取消订单失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-19 20:19:41 +08:00
|
|
|
|
onMounted(loadOrders)
|
2026-02-27 16:44:41 +08:00
|
|
|
|
</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; }
|
|
|
|
|
|
.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; }
|
|
|
|
|
|
.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; }
|
|
|
|
|
|
</style>
|