修复一些问题以及优惠券管理功能
This commit is contained in:
@@ -91,7 +91,8 @@ import {
|
||||
SafetyCertificateOutlined,
|
||||
DownOutlined,
|
||||
LogoutOutlined,
|
||||
GiftOutlined
|
||||
GiftOutlined,
|
||||
TagOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi, type UserVO, adminAuthApi } from '@/api/admin'
|
||||
@@ -147,6 +148,12 @@ const menuItems = [
|
||||
icon: SafetyCertificateOutlined,
|
||||
label: '权限管理',
|
||||
permissionCode: 'permission:view'
|
||||
},
|
||||
{
|
||||
key: '/admin/tags',
|
||||
icon: TagOutlined,
|
||||
label: '标签管理',
|
||||
permissionCode: 'tag:view'
|
||||
}
|
||||
]
|
||||
|
||||
@@ -197,7 +204,7 @@ const handleLogout = () => {
|
||||
sessionStorage.removeItem('accessToken')
|
||||
clearPermissions()
|
||||
message.success('已退出登录')
|
||||
window.location.href = '/auth'
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -61,10 +61,12 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { adminAuthApi } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const { loadUserPermissions } = usePermission()
|
||||
|
||||
const formState = reactive({
|
||||
account: '',
|
||||
@@ -102,11 +104,16 @@ const handleLogin = async () => {
|
||||
sessionStorage.setItem('adminAccessToken', accessToken)
|
||||
|
||||
console.log('存储登录信息完成')
|
||||
|
||||
message.success('登录成功')
|
||||
|
||||
console.log('开始加载用户权限...')
|
||||
await loadUserPermissions()
|
||||
console.log('用户权限加载完成')
|
||||
|
||||
console.log('准备跳转到首页...')
|
||||
router.push('/admin').catch(err => {
|
||||
console.error('跳转到首页失败:', err)
|
||||
// 尝试使用window.location进行跳转
|
||||
window.location.href = '/admin'
|
||||
})
|
||||
console.log('跳转命令已执行')
|
||||
@@ -125,11 +132,12 @@ const goToFrontend = () => {
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/auth'
|
||||
window.location.href = '/'
|
||||
}, 100)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
{{ record.couponTypeName }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ record.shopName || '未知店铺' }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'value'">
|
||||
<template v-if="record.couponType === 1">
|
||||
{{ record.discountValue }}折
|
||||
@@ -49,7 +52,7 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('coupon:assign') && record.status === 1" type="link" size="small" @click="showDistributeModal(record)">
|
||||
@@ -85,6 +88,30 @@
|
||||
<a-form-item label="优惠券名称" name="couponName">
|
||||
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择所属店铺"
|
||||
style="width: 100%"
|
||||
:loading="loadingShops"
|
||||
:disabled="getCurrentUserInfo()?.type === 2"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="优惠券类型" name="couponType">
|
||||
<a-select v-model:value="formState.couponType" placeholder="请选择优惠券类型">
|
||||
<a-select-option :value="1">折扣券</a-select-option>
|
||||
@@ -180,7 +207,7 @@ import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { adminCouponApi, adminTagApi } from '@/api/admin'
|
||||
import { adminCouponApi, adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import type { Coupon } from '@/api/coupon'
|
||||
|
||||
interface CreateCouponRequest {
|
||||
@@ -195,6 +222,7 @@ interface CreateCouponRequest {
|
||||
endTime: string
|
||||
availableTagIds: number[]
|
||||
unavailableTagIds: number[]
|
||||
shopId: number
|
||||
}
|
||||
|
||||
interface TagVO {
|
||||
@@ -211,6 +239,19 @@ import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
@@ -228,6 +269,8 @@ const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
const couponList = ref<Coupon[]>([])
|
||||
const tagList = ref<TagVO[]>([])
|
||||
const userList = ref<any[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
const loadingShops = ref(false)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -249,7 +292,8 @@ const formState = reactive({
|
||||
startTime: new Date(),
|
||||
endTime: new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000),
|
||||
availableTagIds: [] as number[],
|
||||
unavailableTagIds: [] as number[]
|
||||
unavailableTagIds: [] as number[],
|
||||
shopId: undefined as number | undefined
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
@@ -261,7 +305,8 @@ const formRules = {
|
||||
reduceAmount: [{ required: formState.couponType === 2, message: '请输入减免金额', trigger: 'blur' }],
|
||||
totalCount: [{ required: true, message: '请输入优惠券总数量', trigger: 'blur' }],
|
||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 发放优惠券表单状态
|
||||
@@ -280,6 +325,7 @@ const distributeFormRules = {
|
||||
const columns = [
|
||||
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||
{ title: '类型', key: 'couponType', width: 100 },
|
||||
{ title: '优惠信息', key: 'value', width: 150 },
|
||||
{ title: '总数量', dataIndex: 'totalCount', key: 'totalCount', width: 100 },
|
||||
@@ -307,7 +353,9 @@ const getStatusColor = (status: number) => {
|
||||
const fetchCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await adminCouponApi.listAllCoupons()
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
const res = await adminCouponApi.listAllCoupons(shopId)
|
||||
// 处理后端返回的分页数据结构
|
||||
couponList.value = res?.list || []
|
||||
pagination.total = res?.total || 0
|
||||
@@ -327,6 +375,18 @@ const fetchTags = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
shops.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
fetchCoupons()
|
||||
@@ -340,6 +400,8 @@ const handleTableChange = (pag: any) => {
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
couponCode: '',
|
||||
couponName: '',
|
||||
@@ -351,28 +413,43 @@ const showAddModal = () => {
|
||||
startTime: undefined,
|
||||
endTime: undefined,
|
||||
availableTagIds: [],
|
||||
unavailableTagIds: []
|
||||
unavailableTagIds: [],
|
||||
shopId: shopId
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: Coupon) => {
|
||||
isEdit.value = true
|
||||
currentCoupon.value = record
|
||||
Object.assign(formState, {
|
||||
couponCode: record.couponCode,
|
||||
couponName: record.couponName,
|
||||
couponType: record.couponType,
|
||||
discountValue: record.discountValue,
|
||||
minAmount: record.minAmount,
|
||||
reduceAmount: record.reduceAmount,
|
||||
totalCount: record.totalCount,
|
||||
startTime: undefined,
|
||||
endTime: undefined,
|
||||
availableTagIds: record.availableTags.map(tag => tag.id),
|
||||
unavailableTagIds: record.unavailableTags.map(tag => tag.id)
|
||||
console.log('showEditModal called with record:', record)
|
||||
if (!record) {
|
||||
message.error('优惠券数据不存在')
|
||||
return
|
||||
}
|
||||
try {
|
||||
isEdit.value = true
|
||||
currentCoupon.value = record
|
||||
console.log('Form state before:', formState)
|
||||
Object.assign(formState, {
|
||||
couponCode: record.couponCode || '',
|
||||
couponName: record.couponName || '',
|
||||
couponType: record.couponType || 1,
|
||||
discountValue: record.discountValue || 0,
|
||||
minAmount: record.minAmount || 0,
|
||||
reduceAmount: record.reduceAmount || 0,
|
||||
totalCount: record.totalCount || 0,
|
||||
startTime: record.startTime ? new Date(record.startTime) : undefined,
|
||||
endTime: record.endTime ? new Date(record.endTime) : undefined,
|
||||
availableTagIds: record.availableTags ? record.availableTags.map(tag => tag.id) : [],
|
||||
unavailableTagIds: record.unavailableTags ? record.unavailableTags.map(tag => tag.id) : [],
|
||||
shopId: record.shopId
|
||||
})
|
||||
modalVisible.value = true
|
||||
console.log('Form state after:', formState)
|
||||
modalVisible.value = true
|
||||
console.log('Modal visible set to:', modalVisible.value)
|
||||
} catch (error) {
|
||||
console.error('Error in showEditModal:', error)
|
||||
message.error('打开编辑模态框失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
@@ -380,6 +457,35 @@ const handleModalOk = async () => {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = formState.shopId || (currentUser && currentUser.shopId)
|
||||
|
||||
if (!shopId) {
|
||||
message.error('请选择所属店铺')
|
||||
modalLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
// 处理日期格式
|
||||
let startTimeStr = ''
|
||||
let endTimeStr = ''
|
||||
|
||||
if (formState.startTime) {
|
||||
if (formState.startTime instanceof Date) {
|
||||
startTimeStr = formState.startTime.toISOString()
|
||||
} else {
|
||||
startTimeStr = formState.startTime
|
||||
}
|
||||
}
|
||||
|
||||
if (formState.endTime) {
|
||||
if (formState.endTime instanceof Date) {
|
||||
endTimeStr = formState.endTime.toISOString()
|
||||
} else {
|
||||
endTimeStr = formState.endTime
|
||||
}
|
||||
}
|
||||
|
||||
const requestData: CreateCouponRequest = {
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
@@ -388,17 +494,18 @@ const handleModalOk = async () => {
|
||||
minAmount: formState.minAmount,
|
||||
reduceAmount: formState.reduceAmount,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime.toISOString(),
|
||||
endTime: formState.endTime.toISOString(),
|
||||
startTime: startTimeStr,
|
||||
endTime: endTimeStr,
|
||||
availableTagIds: formState.availableTagIds,
|
||||
unavailableTagIds: formState.unavailableTagIds
|
||||
unavailableTagIds: formState.unavailableTagIds,
|
||||
shopId: shopId
|
||||
}
|
||||
|
||||
if (isEdit.value && currentCoupon.value) {
|
||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, requestData)
|
||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, requestData, shopId)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminCouponApi.createCoupon(requestData)
|
||||
await adminCouponApi.createCoupon(requestData, shopId)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
@@ -406,6 +513,7 @@ const handleModalOk = async () => {
|
||||
fetchCoupons()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
message.error('操作失败')
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
@@ -422,7 +530,9 @@ const handleDelete = (record: Coupon) => {
|
||||
content: `确定要删除优惠券 ${record.couponName} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
await adminCouponApi.deleteCoupon(record.id)
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : record.shopId
|
||||
await adminCouponApi.deleteCoupon(record.id, shopId)
|
||||
message.success('删除成功')
|
||||
fetchCoupons()
|
||||
} catch (error) {
|
||||
@@ -465,12 +575,21 @@ const handleDistributeOk = async () => {
|
||||
|
||||
if (!currentDistributeCoupon.value) return
|
||||
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : currentDistributeCoupon.value.shopId
|
||||
|
||||
if (!shopId) {
|
||||
message.error('请选择所属店铺')
|
||||
distributeLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
// 调用发放优惠券的API
|
||||
await adminCouponApi.distributeCoupon({
|
||||
couponId: currentDistributeCoupon.value.id,
|
||||
userIds: distributeFormState.userIds,
|
||||
quantity: distributeFormState.quantity
|
||||
})
|
||||
}, shopId)
|
||||
|
||||
message.success('发放成功')
|
||||
distributeModalVisible.value = false
|
||||
@@ -491,6 +610,7 @@ const handleDistributeCancel = () => {
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await fetchTags()
|
||||
await fetchShops()
|
||||
await fetchCoupons()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
</template>
|
||||
<a-grid :columns="3" :colGap="16" :rowGap="16">
|
||||
<a-grid-item v-for="item in quickActions" :key="item.key">
|
||||
<a-card hoverable @click="navigateTo(item.path)">
|
||||
<a-card hoverable @click="navigateTo(item.path, item.permissionCode)">
|
||||
<template #cover>
|
||||
<div class="action-icon">
|
||||
<component :is="item.icon" />
|
||||
@@ -71,6 +71,7 @@ import { useRouter } from 'vue-router'
|
||||
import { DashboardOutlined, UserOutlined, ShopOutlined, SafetyCertificateOutlined, HomeOutlined } from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO, permissionApi, type PermissionVO } from '@/api/admin'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const router = useRouter()
|
||||
const currentTime = ref('')
|
||||
@@ -105,31 +106,36 @@ const quickActions = computed(() => {
|
||||
key: 'dashboard',
|
||||
title: '仪表盘',
|
||||
path: '/admin/dashboard',
|
||||
icon: DashboardOutlined
|
||||
icon: DashboardOutlined,
|
||||
permissionCode: 'dashboard:view'
|
||||
},
|
||||
{
|
||||
key: 'users',
|
||||
title: '用户管理',
|
||||
path: '/admin/users',
|
||||
icon: UserOutlined
|
||||
icon: UserOutlined,
|
||||
permissionCode: 'user:view'
|
||||
},
|
||||
{
|
||||
key: 'products',
|
||||
title: '商品管理',
|
||||
path: '/admin/products',
|
||||
icon: ShopOutlined
|
||||
icon: ShopOutlined,
|
||||
permissionCode: 'product:view'
|
||||
},
|
||||
{
|
||||
key: 'shops',
|
||||
title: '店铺管理',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined
|
||||
icon: HomeOutlined,
|
||||
permissionCode: 'shop:view'
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined
|
||||
icon: SafetyCertificateOutlined,
|
||||
permissionCode: 'permission:view'
|
||||
}
|
||||
]
|
||||
|
||||
@@ -189,7 +195,15 @@ const fetchUserPermissions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const navigateTo = (path: string) => {
|
||||
const navigateTo = (path: string, permissionCode?: string) => {
|
||||
// 检查是否需要权限
|
||||
if (permissionCode) {
|
||||
const hasPermission = userPermissions.value.some(p => p.permissionCode === permissionCode)
|
||||
if (!hasPermission) {
|
||||
message.warning('您没有该操作的权限')
|
||||
return
|
||||
}
|
||||
}
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +1,49 @@
|
||||
<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 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"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="getStatusColor(record.status)">
|
||||
{{ record.statusText }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<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-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
@@ -61,16 +62,72 @@ interface Order {
|
||||
}
|
||||
|
||||
const orders = ref<Order[]>([])
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
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: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'orange'
|
||||
case 2:
|
||||
return 'green'
|
||||
case 3:
|
||||
return 'red'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await orderApi.getAllOrders()
|
||||
orders.value = data
|
||||
pagination.total = data.length
|
||||
} catch (error) {
|
||||
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) => {
|
||||
try {
|
||||
await orderApi.processOrder(orderId, status)
|
||||
@@ -87,63 +144,20 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.orders-view {
|
||||
padding: 20px;
|
||||
.orders {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 20px;
|
||||
font-size: 24px;
|
||||
color: #333;
|
||||
.orders :deep(.ant-table) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.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;
|
||||
.orders :deep(.ant-table-thead > tr > th) {
|
||||
background-color: #fafafa;
|
||||
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;
|
||||
.orders :deep(.ant-table-tbody > tr:hover > td) {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -256,7 +256,7 @@ const getUserTypeText = (type: number) => {
|
||||
|
||||
const filteredUserList = computed(() => {
|
||||
if (!currentLoginUser.value) return []
|
||||
return userList.value.filter(user => user.type < currentLoginUser.value!.type)
|
||||
return userList.value.filter(user => user.type < currentLoginUser.value!.type && user.type !== 0)
|
||||
})
|
||||
|
||||
const fetchCurrentUser = async () => {
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ getShopName(record.shopId) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'price'">
|
||||
<span style="color: #cf1322; font-weight: 600;">
|
||||
¥{{ record.price }}
|
||||
@@ -107,7 +110,7 @@
|
||||
placeholder="请选择店铺"
|
||||
style="width: 100%"
|
||||
:loading="loadingShops"
|
||||
:disabled="!isAdmin && formState.shopId"
|
||||
:disabled="!isAdmin && !!formState.shopId"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
@@ -308,6 +311,7 @@ const formRules = {
|
||||
const columns = [
|
||||
{ title: '图片', key: 'image', width: 150 },
|
||||
{ title: '商品名称', dataIndex: 'title', key: 'title' },
|
||||
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||
{ title: '描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '价格', key: 'price', width: 100 },
|
||||
{ title: '预计时长', dataIndex: 'approximateDuration', key: 'approximateDuration', width: 120 },
|
||||
@@ -317,6 +321,11 @@ const columns = [
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const getShopName = (shopId: number): string => {
|
||||
const shop = shops.value.find(s => s.id === shopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
|
||||
Reference in New Issue
Block a user