功能:补齐订单预约时间落库
This commit is contained in:
@@ -4,6 +4,7 @@ interface OrderItem {
|
||||
productId: number
|
||||
quantity: number
|
||||
artistId?: number
|
||||
appointmentTime?: string
|
||||
}
|
||||
|
||||
interface CreateOrderRequest {
|
||||
@@ -47,5 +48,9 @@ export const orderApi = {
|
||||
// 美甲师查看自己的订单
|
||||
getArtistOrders: () => {
|
||||
return api.get('/order/artist/list')
|
||||
},
|
||||
|
||||
completeArtistOrder: (orderId: number) => {
|
||||
return api.put(`/order/artist/complete/${orderId}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,333 +1,123 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<div class="page">
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>美甲师订单</h1>
|
||||
<div class="placeholder"></div>
|
||||
<div class="placeholder" />
|
||||
</header>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<div class="order-section">
|
||||
<a-empty v-if="orders.length === 0" description="暂无订单">
|
||||
<a-button type="primary" @click="handleRefresh">刷新</a-button>
|
||||
<main class="content">
|
||||
<a-empty v-if="!orders.length" description="暂无订单">
|
||||
<a-button type="primary" @click="loadOrders">刷新</a-button>
|
||||
</a-empty>
|
||||
<div v-else class="order-list">
|
||||
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
||||
<div class="order-header">
|
||||
<span class="order-no">订单号: {{ order.orderNo }}</span>
|
||||
<span :class="['order-status', order.status === 1 ? 'pending' : order.status === 2 ? 'completed' : 'cancelled']">
|
||||
{{ order.statusText }}
|
||||
</span>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
<div class="order-items">
|
||||
<div v-for="item in order.items" :key="item.id" class="order-item">
|
||||
<div class="item-image" v-if="item.productImage">
|
||||
<img :src="item.productImage" :alt="item.productTitle" />
|
||||
</div>
|
||||
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
|
||||
<span>{{ item.productTitle[0] }}</span>
|
||||
</div>
|
||||
<div class="item-info">
|
||||
<div class="item-title">{{ item.productTitle }}</div>
|
||||
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div class="item-customer">
|
||||
<span>客户订单</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">{{ item.productTitle }}</div>
|
||||
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
|
||||
</div>
|
||||
<div class="order-footer">
|
||||
<div class="order-total">
|
||||
总计: <span class="total-price">¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="order-actions">
|
||||
<a-button v-if="order.status === 1" size="small" type="primary" @click="handleCompleteOrder(order.id)">
|
||||
完成服务
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<span>当前项目合计:¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||
<a-button v-if="order.status === 1" size="small" type="primary" @click="completeOrder(order.id)">
|
||||
完成服务
|
||||
</a-button>
|
||||
</div>
|
||||
</a-card>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { orderApi } from '../api/order'
|
||||
import { fileApi } from '../api/index'
|
||||
import { orderApi } from '../api/order'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 订单相关状态
|
||||
const orders = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
// 图片缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
// 加载美甲师订单列表
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await orderApi.getArtistOrders() as any
|
||||
orders.value = response || []
|
||||
|
||||
await loadProductImages(orders.value)
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
const statusClass = (status: number) => {
|
||||
if (status === 1) return 'pending'
|
||||
if (status === 2) return 'completed'
|
||||
return 'cancelled'
|
||||
}
|
||||
|
||||
// 加载作品图片
|
||||
const loadProductImages = async (orders: any[]) => {
|
||||
for (const order of orders) {
|
||||
if (order.items && order.items.length > 0) {
|
||||
for (const item of order.items) {
|
||||
if (item.productImage) {
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const response = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
imageIdCache.value[imageId] = response
|
||||
}
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
item.productImage = ''
|
||||
}
|
||||
const loadOrders = async () => {
|
||||
try {
|
||||
orders.value = (await orderApi.getArtistOrders() 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 = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理完成服务
|
||||
const handleCompleteOrder = async (orderId: number) => {
|
||||
const completeOrder = (orderId: number) => {
|
||||
Modal.confirm({
|
||||
title: '确认完成服务',
|
||||
content: '确定要完成这个订单的服务吗?',
|
||||
content: '确定要完成这个订单吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await orderApi.processOrder(orderId, 2)
|
||||
await orderApi.completeArtistOrder(orderId)
|
||||
message.success('订单已完成')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
await loadOrders()
|
||||
} catch {
|
||||
message.error('完成订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 处理返回按钮点击
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理刷新
|
||||
const handleRefresh = () => {
|
||||
loadOrders()
|
||||
}
|
||||
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 页面加载时获取订单数据
|
||||
onMounted(() => {
|
||||
loadOrders()
|
||||
})
|
||||
onMounted(loadOrders)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
padding-top: 60px;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.placeholder {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.order-section {
|
||||
padding: 15px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.order-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.order-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.order-status.pending {
|
||||
background: #fff7e6;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.order-status.completed {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.order-status.cancelled {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.order-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.item-image {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: rgba(0,0,0,0.1);
|
||||
flex-shrink: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.item-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.item-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item-customer {
|
||||
font-size: 12px;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.order-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.order-total {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.total-price {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.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>
|
||||
|
||||
+297
-1258
File diff suppressed because it is too large
Load Diff
@@ -1,125 +1,86 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<div class="page">
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>我的订单</h1>
|
||||
<div class="placeholder"></div>
|
||||
<div class="placeholder" />
|
||||
</header>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<div class="order-section">
|
||||
<a-empty v-if="orders.length === 0" description="暂无订单">
|
||||
<a-button type="primary" @click="handleBrowseProducts">去购物</a-button>
|
||||
<main class="content">
|
||||
<a-empty v-if="!orders.length" description="暂无订单">
|
||||
<a-button type="primary" @click="router.push('/products')">去逛逛</a-button>
|
||||
</a-empty>
|
||||
<div v-else class="order-list">
|
||||
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
||||
<div class="order-header">
|
||||
<span class="order-no">订单号: {{ order.orderNo }}</span>
|
||||
<span :class="['order-status', order.status === 1 ? 'pending' : order.status === 2 ? 'completed' : 'cancelled']">
|
||||
{{ order.statusText }}
|
||||
</span>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
<div class="order-items">
|
||||
<div v-for="item in order.items" :key="item.id" class="order-item">
|
||||
<div class="item-image" v-if="item.productImage">
|
||||
<img :src="item.productImage" :alt="item.productTitle" />
|
||||
</div>
|
||||
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
|
||||
<span>{{ item.productTitle[0] }}</span>
|
||||
</div>
|
||||
<div class="item-info">
|
||||
<div class="item-title">{{ item.productTitle }}</div>
|
||||
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div v-if="item.artistName" class="item-artist">
|
||||
<img v-if="item.artistAvatar" :src="item.artistAvatar" class="artist-avatar-small" />
|
||||
<span>美甲师: {{ item.artistName }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
<div class="order-footer">
|
||||
<div class="order-total">
|
||||
总计: <span class="total-price">¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="order-actions">
|
||||
<a-button v-if="order.status === 1" size="small" danger @click="handleCancelOrder(order.id)">
|
||||
取消订单
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</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">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { orderApi } from '../api/order'
|
||||
import { fileApi } from '../api/index'
|
||||
import { orderApi } from '../api/order'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 订单相关状态
|
||||
const orders = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
// 图片缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
// 加载订单列表
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await orderApi.getOrderList() as any
|
||||
orders.value = response || []
|
||||
|
||||
await loadProductImages(orders.value)
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
const statusClass = (status: number) => {
|
||||
if (status === 1) return 'pending'
|
||||
if (status === 2) return 'completed'
|
||||
return 'cancelled'
|
||||
}
|
||||
|
||||
// 加载作品图片
|
||||
const loadProductImages = async (orders: any[]) => {
|
||||
for (const order of orders) {
|
||||
if (order.items && order.items.length > 0) {
|
||||
for (const item of order.items) {
|
||||
if (item.productImage) {
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const response = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
imageIdCache.value[imageId] = response
|
||||
}
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
item.productImage = ''
|
||||
}
|
||||
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 = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消订单
|
||||
const handleCancelOrder = async (orderId: number) => {
|
||||
const cancelOrder = (orderId: number) => {
|
||||
Modal.confirm({
|
||||
title: '确认取消订单',
|
||||
content: '确定要取消这个订单吗?',
|
||||
@@ -127,218 +88,35 @@ const handleCancelOrder = async (orderId: number) => {
|
||||
try {
|
||||
await orderApi.cancelOrder(orderId)
|
||||
message.success('订单已取消')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
await loadOrders()
|
||||
} catch {
|
||||
message.error('取消订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 处理返回按钮点击
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理浏览作品
|
||||
const handleBrowseProducts = () => {
|
||||
router.push('/products')
|
||||
}
|
||||
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 页面加载时获取订单数据
|
||||
onMounted(() => {
|
||||
loadOrders()
|
||||
})
|
||||
onMounted(loadOrders)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
padding-top: 60px;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.placeholder {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.order-section {
|
||||
padding: 15px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.order-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.order-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.order-status.pending {
|
||||
background: #fff7e6;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.order-status.completed {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.order-status.cancelled {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.order-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.item-image {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: rgba(0,0,0,0.1);
|
||||
flex-shrink: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.item-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.item-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item-artist {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.artist-avatar-small {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.order-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.order-total {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.total-price {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
.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>
|
||||
|
||||
@@ -1,218 +1,122 @@
|
||||
<template>
|
||||
<div class="orders">
|
||||
<a-page-header title="订单管理" sub-title="管理系统订单" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #extra>
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索订单编号或用户ID"
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="orders"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<a-card :bordered="false">
|
||||
<a-table :columns="columns" :data-source="orders" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="getStatusColor(record.status)">
|
||||
{{ record.statusText }}
|
||||
</a-tag>
|
||||
<a-tag :color="statusColor(record.status)">{{ record.statusText }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'totalAmount'">
|
||||
¥{{ record.totalAmount.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actualAmount'">
|
||||
¥{{ record.actualAmount.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showOrderDetail(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="record.status === 1" type="primary" size="small" @click="processOrder(record.id, 2)">
|
||||
确认完成
|
||||
</a-button>
|
||||
<a-button v-if="record.status === 1" danger size="small" @click="processOrder(record.id, 3)">
|
||||
取消订单
|
||||
</a-button>
|
||||
<a-button type="link" size="small" @click="currentOrder = record">查看</a-button>
|
||||
<a-button v-if="record.status === 1" type="primary" size="small" @click="process(record.id, 2)">确认完成</a-button>
|
||||
<a-button v-if="record.status === 1" danger size="small" @click="process(record.id, 3)">取消订单</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 订单详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="detailModalVisible"
|
||||
title="订单详情"
|
||||
@cancel="handleDetailModalCancel"
|
||||
width="800px"
|
||||
>
|
||||
<div v-if="currentOrder">
|
||||
<a-modal v-model:open="detailVisible" title="订单详情" width="860px" @cancel="currentOrder = null">
|
||||
<template v-if="currentOrder">
|
||||
<a-descriptions :column="2">
|
||||
<a-descriptions-item label="订单编号">{{ currentOrder.orderNo }}</a-descriptions-item>
|
||||
<a-descriptions-item label="用户ID">{{ currentOrder.userId }}</a-descriptions-item>
|
||||
<a-descriptions-item label="总金额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="实际金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单总额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="实付金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券">{{ currentOrder.couponName || '无' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单状态">{{ currentOrder.statusText }}</a-descriptions-item>
|
||||
<a-descriptions-item label="创建时间" :span="2">{{ currentOrder.createTime }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
|
||||
<a-divider>订单作品</a-divider>
|
||||
<a-table :columns="orderItemColumns" :data-source="currentOrder.items" row-key="id">
|
||||
|
||||
<a-divider>订单项目</a-divider>
|
||||
<a-table :columns="itemColumns" :data-source="currentOrder.items" row-key="id" :pagination="false">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'price'">
|
||||
¥{{ record.price.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'totalPrice'">
|
||||
¥{{ (record.price * record.quantity).toFixed(2) }}
|
||||
</template>
|
||||
<template v-if="column.key === 'price'">¥{{ record.price.toFixed(2) }}</template>
|
||||
<template v-else-if="column.key === 'totalPrice'">¥{{ (record.price * record.quantity).toFixed(2) }}</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
</template>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
|
||||
interface Order {
|
||||
id: number
|
||||
orderNo: string
|
||||
userId: number
|
||||
totalAmount: number
|
||||
actualAmount: number
|
||||
couponId: number | null
|
||||
couponName: string | null
|
||||
status: number
|
||||
statusText: string
|
||||
createTime: string
|
||||
items: any[]
|
||||
}
|
||||
|
||||
const orders = ref<Order[]>([])
|
||||
const orders = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const detailModalVisible = ref(false)
|
||||
const currentOrder = ref<Order | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
const currentOrder = ref<any | null>(null)
|
||||
const detailVisible = computed({
|
||||
get: () => !!currentOrder.value,
|
||||
set: value => { if (!value) currentOrder.value = null }
|
||||
})
|
||||
|
||||
const orderItemColumns = [
|
||||
{ title: '作品ID', dataIndex: 'productId', key: 'productId' },
|
||||
{ title: '作品名称', dataIndex: 'productTitle', key: 'productTitle' },
|
||||
{ title: '单价', key: 'price', width: 100 },
|
||||
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 100 },
|
||||
{ title: '总价', key: 'totalPrice', width: 100 }
|
||||
]
|
||||
|
||||
const columns = [
|
||||
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId' },
|
||||
{ title: '总金额', dataIndex: 'totalAmount', key: 'totalAmount',
|
||||
render: (text: number) => `¥${text.toFixed(2)}`
|
||||
},
|
||||
{ title: '实际金额', dataIndex: 'actualAmount', key: 'actualAmount',
|
||||
render: (text: number) => `¥${text.toFixed(2)}`
|
||||
},
|
||||
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName',
|
||||
render: (text: string | null) => text || '无'
|
||||
},
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 100 },
|
||||
{ title: '订单总额', key: 'totalAmount', width: 120 },
|
||||
{ title: '实付金额', key: 'actualAmount', width: 120 },
|
||||
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
||||
{ title: '操作', key: 'actions', width: 180 }
|
||||
]
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'orange'
|
||||
case 2:
|
||||
return 'green'
|
||||
case 3:
|
||||
return 'red'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
const itemColumns = [
|
||||
{ title: '商品ID', dataIndex: 'productId', key: 'productId', width: 100 },
|
||||
{ title: '商品名称', dataIndex: 'productTitle', key: 'productTitle' },
|
||||
{ title: '美甲师', dataIndex: 'artistName', key: 'artistName', width: 120 },
|
||||
{ title: '预约时间', dataIndex: 'appointmentTime', key: 'appointmentTime', width: 180 },
|
||||
{ title: '单价', key: 'price', width: 100 },
|
||||
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 80 },
|
||||
{ title: '总价', key: 'totalPrice', width: 100 }
|
||||
]
|
||||
|
||||
const statusColor = (status: number) => {
|
||||
if (status === 1) return 'orange'
|
||||
if (status === 2) return 'green'
|
||||
if (status === 3) return 'red'
|
||||
return 'default'
|
||||
}
|
||||
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await orderApi.getAllOrders() as unknown as Order[]
|
||||
orders.value = data
|
||||
pagination.total = data.length
|
||||
} catch (error) {
|
||||
orders.value = await orderApi.getAllOrders() as unknown as any[]
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
loadOrders()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
loadOrders()
|
||||
}
|
||||
|
||||
const processOrder = async (orderId: number, status: number) => {
|
||||
const process = async (orderId: number, status: number) => {
|
||||
try {
|
||||
await orderApi.processOrder(orderId, status)
|
||||
message.success('操作成功')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
await loadOrders()
|
||||
if (currentOrder.value?.id === orderId) {
|
||||
currentOrder.value = orders.value.find(order => order.id === orderId) || null
|
||||
}
|
||||
} catch {
|
||||
message.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const showOrderDetail = (order: Record<string, any>) => {
|
||||
currentOrder.value = order as Order
|
||||
detailModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleDetailModalCancel = () => {
|
||||
detailModalVisible.value = false
|
||||
currentOrder.value = null
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadOrders()
|
||||
})
|
||||
onMounted(loadOrders)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.orders {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.orders :deep(.ant-table) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.orders :deep(.ant-table-thead > tr > th) {
|
||||
background-color: #fafafa;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.orders :deep(.ant-table-tbody > tr:hover > td) {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.orders { padding: 0; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user