功能:补齐订单预约时间落库
This commit is contained in:
@@ -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