购物车和订单中心以及优惠券相关功能初版

This commit is contained in:
xiaowang
2026-02-27 16:44:41 +08:00
parent 3529a73d84
commit 43f31eed53
36 changed files with 1785 additions and 24 deletions
+3 -2
View File
@@ -308,8 +308,9 @@ const fetchCoupons = async () => {
loading.value = true
try {
const res = await adminCouponApi.listAllCoupons()
couponList.value = res || []
pagination.total = res.length || 0
// 处理后端返回的分页数据结构
couponList.value = res?.list || []
pagination.total = res?.total || 0
} catch (error) {
message.error('获取优惠券列表失败')
} finally {
+149
View File
@@ -0,0 +1,149 @@
<template>
<div class="orders-view">
<h1>订单管理</h1>
<div class="orders-table">
<table>
<thead>
<tr>
<th>订单编号</th>
<th>用户ID</th>
<th>总金额</th>
<th>实际金额</th>
<th>优惠券</th>
<th>状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="order in orders" :key="order.id">
<td>{{ order.orderNo }}</td>
<td>{{ order.userId }}</td>
<td>{{ order.totalAmount }}</td>
<td>{{ order.actualAmount }}</td>
<td>{{ order.couponName || '无' }}</td>
<td>{{ order.statusText }}</td>
<td>{{ order.createTime }}</td>
<td>
<div class="order-actions">
<button v-if="order.status === 1" @click="processOrder(order.id, 2)" class="btn btn-success">
确认完成
</button>
<button v-if="order.status === 1" @click="processOrder(order.id, 3)" class="btn btn-danger">
取消订单
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { orderApi } from '../../api/order'
import { message } from 'ant-design-vue'
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 loadOrders = async () => {
try {
const data = await orderApi.getAllOrders()
orders.value = data
} catch (error) {
message.error('获取订单列表失败')
}
}
const processOrder = async (orderId: number, status: number) => {
try {
await orderApi.processOrder(orderId, status)
message.success('操作成功')
loadOrders()
} catch (error) {
message.error('操作失败')
}
}
onMounted(() => {
loadOrders()
})
</script>
<style scoped>
.orders-view {
padding: 20px;
}
h1 {
margin-bottom: 20px;
font-size: 24px;
color: #333;
}
.orders-table {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #e8e8e8;
}
th {
background-color: #f5f5f5;
font-weight: 600;
}
.order-actions {
display: flex;
gap: 8px;
}
.btn {
padding: 6px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.btn-success {
background-color: #52c41a;
color: white;
}
.btn-danger {
background-color: #ff4d4f;
color: white;
}
.btn:hover {
opacity: 0.8;
}
</style>
+8 -1
View File
@@ -217,6 +217,7 @@
placeholder="请选择优惠券"
style="width: 100%"
:loading="loadingCoupons"
:disabled="!isShopOwner()"
>
<a-select-option
v-if="coupons.length === 0"
@@ -331,6 +332,11 @@ const getCurrentUserInfo = () => {
return null
}
const isShopOwner = () => {
const userInfo = getCurrentUserInfo()
return userInfo && userInfo.type === 2
}
const fetchShops = async () => {
loadingShops.value = true
try {
@@ -397,7 +403,8 @@ const fetchCoupons = async () => {
loadingCoupons.value = true
try {
const res = await adminCouponApi.listAllCoupons()
coupons.value = res || []
// 处理后端返回的分页数据结构
coupons.value = res?.list || []
} catch (error) {
console.error('获取优惠券列表失败', error)
message.error('获取优惠券列表失败')