修复一些问题以及优惠券管理功能
This commit is contained in:
+28
-10
@@ -367,6 +367,15 @@ export const adminTagApi = {
|
||||
},
|
||||
listTagsByShopId: (shopId: number) => {
|
||||
return adminApi.get<any[]>('/tag/list/by-shop/' + shopId)
|
||||
},
|
||||
createTag: (data: any) => {
|
||||
return adminApi.post('/tag/create', data)
|
||||
},
|
||||
updateTag: (id: number, data: any) => {
|
||||
return adminApi.put(`/tag/update/${id}`, data)
|
||||
},
|
||||
deleteTag: (id: number) => {
|
||||
return adminApi.delete(`/tag/delete/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,20 +386,29 @@ export const adminArtistApi = {
|
||||
}
|
||||
|
||||
export const adminCouponApi = {
|
||||
listAllCoupons: () => {
|
||||
return adminApi.get<any[]>('/coupon/list', { params: { page: 1, size: 100 } })
|
||||
listAllCoupons: (shopId?: number) => {
|
||||
return adminApi.get<any[]>('/coupon/list', { params: { page: 1, size: 100, shopId } })
|
||||
},
|
||||
createCoupon: (data: any) => {
|
||||
return adminApi.post('/coupon/create', data)
|
||||
createCoupon: (data: any, shopId: number) => {
|
||||
return adminApi.post('/coupon/create', data, { params: { shopId } })
|
||||
},
|
||||
updateCoupon: (id: number, data: any) => {
|
||||
return adminApi.put(`/coupon/update/${id}`, data)
|
||||
updateCoupon: (id: number, data: any, shopId: number) => {
|
||||
return adminApi.put(`/coupon/update/${id}`, data, { params: { shopId } })
|
||||
},
|
||||
deleteCoupon: (id: number) => {
|
||||
return adminApi.delete(`/coupon/delete/${id}`)
|
||||
deleteCoupon: (id: number, shopId: number) => {
|
||||
return adminApi.delete(`/coupon/delete/${id}`, { params: { shopId } })
|
||||
},
|
||||
distributeCoupon: (data: { couponId: number; userIds: number[]; quantity: number }) => {
|
||||
return adminApi.post('/coupon/distribute', data)
|
||||
distributeCoupon: (data: { couponId: number; userIds: number[]; quantity: number }, shopId: number) => {
|
||||
const params: any = {
|
||||
couponId: data.couponId,
|
||||
quantity: data.quantity,
|
||||
shopId: shopId
|
||||
};
|
||||
// 处理userIds数组,确保它能被后端正确解析
|
||||
data.userIds.forEach((userId, index) => {
|
||||
params[`userIds[${index}]`] = userId;
|
||||
});
|
||||
return adminApi.post('/coupon/distribute', null, { params })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export const authApi = {
|
||||
},
|
||||
|
||||
adminLogin: (data: LoginRequest) => {
|
||||
return api.post<LoginResponse>('/admin/api/auth/login', data)
|
||||
return api.post<LoginResponse>('/admin/auth/login', data)
|
||||
},
|
||||
|
||||
register: (data: RegisterRequest) => {
|
||||
|
||||
@@ -53,13 +53,13 @@ const handleTokenExpired = () => {
|
||||
sessionStorage.removeItem('accessToken')
|
||||
showError('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/auth').catch(err => {
|
||||
router.push('/').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
window.location.href = '/auth'
|
||||
window.location.href = '/'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/auth'
|
||||
window.location.href = '/'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+52
@@ -11,8 +11,60 @@ export {}
|
||||
/* prettier-ignore */
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
AAlert: typeof import('ant-design-vue/es')['Alert']
|
||||
AAvatar: typeof import('ant-design-vue/es')['Avatar']
|
||||
ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||
AButton: typeof import('ant-design-vue/es')['Button']
|
||||
ACard: typeof import('ant-design-vue/es')['Card']
|
||||
ACheckbox: typeof import('ant-design-vue/es')['Checkbox']
|
||||
ACheckboxGroup: typeof import('ant-design-vue/es')['CheckboxGroup']
|
||||
ACol: typeof import('ant-design-vue/es')['Col']
|
||||
ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
||||
ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
||||
ADatePicker: typeof import('ant-design-vue/es')['DatePicker']
|
||||
ADescriptions: typeof import('ant-design-vue/es')['Descriptions']
|
||||
ADescriptionsItem: typeof import('ant-design-vue/es')['DescriptionsItem']
|
||||
ADropdown: typeof import('ant-design-vue/es')['Dropdown']
|
||||
AEmpty: typeof import('ant-design-vue/es')['Empty']
|
||||
AForm: typeof import('ant-design-vue/es')['Form']
|
||||
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
||||
AGrid: typeof import('ant-design-vue/es')['Grid']
|
||||
AImage: typeof import('ant-design-vue/es')['Image']
|
||||
AInput: typeof import('ant-design-vue/es')['Input']
|
||||
AInputNumber: typeof import('ant-design-vue/es')['InputNumber']
|
||||
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
||||
AInputSearch: typeof import('ant-design-vue/es')['InputSearch']
|
||||
ALayout: typeof import('ant-design-vue/es')['Layout']
|
||||
ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent']
|
||||
ALayoutHeader: typeof import('ant-design-vue/es')['LayoutHeader']
|
||||
ALayoutSider: typeof import('ant-design-vue/es')['LayoutSider']
|
||||
AList: typeof import('ant-design-vue/es')['List']
|
||||
AListItem: typeof import('ant-design-vue/es')['ListItem']
|
||||
AListItemMeta: typeof import('ant-design-vue/es')['ListItemMeta']
|
||||
AMenu: typeof import('ant-design-vue/es')['Menu']
|
||||
AMenuDivider: typeof import('ant-design-vue/es')['MenuDivider']
|
||||
AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
|
||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
||||
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
||||
ARow: typeof import('ant-design-vue/es')['Row']
|
||||
ASelect: typeof import('ant-design-vue/es')['Select']
|
||||
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
||||
ASpace: typeof import('ant-design-vue/es')['Space']
|
||||
ASpin: typeof import('ant-design-vue/es')['Spin']
|
||||
AStatistic: typeof import('ant-design-vue/es')['Statistic']
|
||||
ASwitch: typeof import('ant-design-vue/es')['Switch']
|
||||
ATable: typeof import('ant-design-vue/es')['Table']
|
||||
ATabPane: typeof import('ant-design-vue/es')['TabPane']
|
||||
ATabs: typeof import('ant-design-vue/es')['Tabs']
|
||||
ATag: typeof import('ant-design-vue/es')['Tag']
|
||||
ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
||||
ATimeline: typeof import('ant-design-vue/es')['Timeline']
|
||||
ATimelineItem: typeof import('ant-design-vue/es')['TimelineItem']
|
||||
AUpload: typeof import('ant-design-vue/es')['Upload']
|
||||
BottomNav: typeof import('./components/BottomNav.vue')['default']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
|
||||
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||
ElTag: typeof import('element-plus/es')['ElTag']
|
||||
|
||||
@@ -121,6 +121,12 @@ const router = createRouter({
|
||||
name: 'admin-orders',
|
||||
component: () => import('../views/admin/OrdersView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'order:view' }
|
||||
},
|
||||
{
|
||||
path: 'tags',
|
||||
name: 'admin-tags',
|
||||
component: () => import('../views/admin/TagsView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'tag:view' }
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -235,20 +235,35 @@ const handleSubmit = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
if (activeTab.value === 'login') {
|
||||
console.log('开始登录...')
|
||||
const response = await authApi.login({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
rememberMe: formData.rememberMe
|
||||
})
|
||||
|
||||
const loginData = response as any
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
console.log('登录响应:', response)
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/')
|
||||
const loginData = response as any
|
||||
console.log('登录数据:', loginData)
|
||||
|
||||
if (loginData.accessToken && loginData.refreshToken) {
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
console.log('Token存储成功')
|
||||
message.success('登录成功')
|
||||
console.log('准备跳转到首页...')
|
||||
router.push('/home').catch(err => {
|
||||
console.error('跳转到首页失败:', err)
|
||||
window.location.href = '/home'
|
||||
})
|
||||
} else {
|
||||
console.error('登录响应缺少token:', loginData)
|
||||
message.error('登录失败:响应数据异常')
|
||||
}
|
||||
} else {
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
@@ -261,6 +276,7 @@ const handleSubmit = async () => {
|
||||
activeTab.value = 'login'
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('登录失败:', error)
|
||||
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
|
||||
@@ -76,6 +76,23 @@
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 优惠券选择 -->
|
||||
<div class="coupon-section" v-if="cartItems.length > 0 && selectedCount > 0">
|
||||
<a-card class="coupon-card">
|
||||
<div class="coupon-header" @click="showCouponModal = true">
|
||||
<span class="coupon-title">优惠券</span>
|
||||
<div class="coupon-value">
|
||||
{{ selectedCoupon ? '已选择: ' + selectedCoupon.couponName : '请选择' }}
|
||||
<RightOutlined :style="{ marginLeft: '4px' }" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="coupon-discount" v-if="selectedCoupon">
|
||||
<span class="discount-label">优惠金额</span>
|
||||
<span class="discount-amount">-¥{{ discountAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 订单摘要 -->
|
||||
<div class="summary" v-if="cartItems.length > 0">
|
||||
<div class="summary-row">
|
||||
@@ -86,9 +103,13 @@
|
||||
<span>小计</span>
|
||||
<span>¥{{ subtotal.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="summary-row" v-if="selectedCoupon">
|
||||
<span>优惠</span>
|
||||
<span class="discount">-¥{{ discountAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="summary-row total">
|
||||
<span>总计</span>
|
||||
<span class="total-price">¥{{ subtotal.toFixed(2) }}</span>
|
||||
<span class="total-price">¥{{ totalAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -100,23 +121,64 @@
|
||||
block
|
||||
@click="handleCheckout"
|
||||
>
|
||||
结算 ({{ selectedCount }})
|
||||
结算 ({{ selectedCount }}) - ¥{{ totalAmount.toFixed(2) }}
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<!-- 优惠券选择弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="showCouponModal"
|
||||
title="选择优惠券"
|
||||
width="90%"
|
||||
>
|
||||
<div class="coupon-modal-content">
|
||||
<a-empty v-if="availableCoupons.length === 0" description="暂无可用优惠券" />
|
||||
<div v-else class="coupon-list">
|
||||
<a-card
|
||||
v-for="coupon in availableCoupons"
|
||||
:key="coupon.id"
|
||||
class="modal-coupon-card"
|
||||
:class="{ active: selectedCoupon && selectedCoupon.id === coupon.id }"
|
||||
@click="selectCoupon(coupon)"
|
||||
>
|
||||
<div class="coupon-content">
|
||||
<div class="coupon-value">
|
||||
{{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }}
|
||||
</div>
|
||||
<div class="coupon-info">
|
||||
<div class="coupon-name">{{ coupon.couponName }}</div>
|
||||
<div class="coupon-condition" v-if="coupon.couponType === 2">
|
||||
满{{ coupon.minAmount }}元可用
|
||||
</div>
|
||||
<div class="coupon-time">
|
||||
{{ coupon.startTime }} 至 {{ coupon.endTime }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="coupon-select" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
|
||||
<CheckCircleOutlined />
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
LeftOutlined,
|
||||
DeleteOutlined
|
||||
DeleteOutlined,
|
||||
RightOutlined,
|
||||
CheckCircleOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { cartApi } from '../api/cart'
|
||||
import { orderApi } from '../api/order'
|
||||
import { fileApi } from '../api/index'
|
||||
import { couponApi, type UserCoupon } from '../api/coupon'
|
||||
|
||||
interface CartItem {
|
||||
id: number
|
||||
@@ -137,6 +199,11 @@ const cartItems = ref<CartItem[]>([])
|
||||
// 图片缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
// 优惠券相关状态
|
||||
const availableCoupons = ref<UserCoupon[]>([])
|
||||
const selectedCoupon = ref<UserCoupon | null>(null)
|
||||
const showCouponModal = ref(false)
|
||||
|
||||
// 加载购物车数据
|
||||
const loadCartItems = async () => {
|
||||
try {
|
||||
@@ -148,6 +215,9 @@ const loadCartItems = async () => {
|
||||
|
||||
// 加载商品图片的临时加签链接
|
||||
await loadProductImages(cartItems.value)
|
||||
|
||||
// 加载可用优惠券
|
||||
await loadAvailableCoupons()
|
||||
} catch (error) {
|
||||
message.error('获取购物车数据失败')
|
||||
}
|
||||
@@ -186,6 +256,27 @@ const loadProductImages = async (items: CartItem[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载可用优惠券
|
||||
const loadAvailableCoupons = async () => {
|
||||
try {
|
||||
// 计算商品总价
|
||||
const totalPrice = subtotal.value
|
||||
|
||||
// 收集商品标签
|
||||
const productTags = cartItems.value
|
||||
.filter(item => item.selected)
|
||||
.map(item => item.productTitle.split(' ')[0]) // 简单处理,取商品标题的第一个词作为标签
|
||||
.join(',')
|
||||
|
||||
if (totalPrice > 0) {
|
||||
const coupons = await couponApi.getAvailableCoupons(productTags, totalPrice)
|
||||
availableCoupons.value = coupons
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取可用优惠券失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算选中的商品数量
|
||||
const selectedCount = computed(() => {
|
||||
return cartItems.value.filter(item => item.selected).length
|
||||
@@ -203,6 +294,29 @@ const subtotal = computed(() => {
|
||||
.reduce((sum, item) => sum + item.totalPrice, 0)
|
||||
})
|
||||
|
||||
// 计算优惠金额
|
||||
const discountAmount = computed(() => {
|
||||
if (!selectedCoupon.value) return 0
|
||||
|
||||
const total = subtotal.value
|
||||
const coupon = selectedCoupon.value
|
||||
|
||||
if (coupon.couponType === 1) {
|
||||
// 折扣券
|
||||
return total - (total * parseFloat(coupon.discountValue) / 10)
|
||||
} else if (coupon.couponType === 2) {
|
||||
// 满减券
|
||||
return parseFloat(coupon.reduceAmount)
|
||||
}
|
||||
|
||||
return 0
|
||||
})
|
||||
|
||||
// 计算总金额
|
||||
const totalAmount = computed(() => {
|
||||
return Math.max(0, subtotal.value - discountAmount.value)
|
||||
})
|
||||
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
@@ -220,8 +334,10 @@ const handleEditClick = () => {
|
||||
}
|
||||
|
||||
// 处理选择状态变化
|
||||
const handleSelectChange = () => {
|
||||
const handleSelectChange = async () => {
|
||||
console.log('选择状态改变')
|
||||
// 重新加载可用优惠券
|
||||
await loadAvailableCoupons()
|
||||
}
|
||||
|
||||
// 处理减少数量
|
||||
@@ -230,6 +346,8 @@ const handleDecreaseQuantity = async (item: CartItem) => {
|
||||
item.quantity--
|
||||
try {
|
||||
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||
// 重新加载可用优惠券
|
||||
await loadAvailableCoupons()
|
||||
} catch (error) {
|
||||
message.error('更新数量失败')
|
||||
item.quantity++
|
||||
@@ -243,6 +361,8 @@ const handleIncreaseQuantity = async (item: CartItem) => {
|
||||
item.quantity++
|
||||
try {
|
||||
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||
// 重新加载可用优惠券
|
||||
await loadAvailableCoupons()
|
||||
} catch (error) {
|
||||
message.error('更新数量失败')
|
||||
item.quantity--
|
||||
@@ -258,6 +378,8 @@ const handleDeleteItem = async (item: CartItem) => {
|
||||
if (index > -1) {
|
||||
cartItems.value.splice(index, 1)
|
||||
message.success('商品已删除')
|
||||
// 重新加载可用优惠券
|
||||
await loadAvailableCoupons()
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除商品失败')
|
||||
@@ -269,6 +391,12 @@ const handleBrowseProducts = () => {
|
||||
router.push('/products')
|
||||
}
|
||||
|
||||
// 选择优惠券
|
||||
const selectCoupon = (coupon: UserCoupon) => {
|
||||
selectedCoupon.value = coupon
|
||||
showCouponModal.value = false
|
||||
}
|
||||
|
||||
// 处理结算
|
||||
const handleCheckout = async () => {
|
||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||
@@ -278,7 +406,9 @@ const handleCheckout = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await orderApi.createOrder({})
|
||||
const order = await orderApi.createOrder({
|
||||
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined
|
||||
})
|
||||
message.success('订单创建成功')
|
||||
router.push('/profile')
|
||||
} catch (error) {
|
||||
@@ -286,6 +416,15 @@ const handleCheckout = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 监听选中商品变化,重新加载可用优惠券
|
||||
watch(
|
||||
() => cartItems.value.map(item => ({ id: item.id, selected: item.selected, quantity: item.quantity })),
|
||||
async () => {
|
||||
await loadAvailableCoupons()
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
// 页面加载时获取购物车数据
|
||||
onMounted(() => {
|
||||
loadCartItems()
|
||||
@@ -473,4 +612,137 @@ onMounted(() => {
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 优惠券样式 */
|
||||
.coupon-section {
|
||||
margin: 0 15px 15px;
|
||||
}
|
||||
|
||||
.coupon-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.coupon-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.coupon-header:hover {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.coupon-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.coupon-value {
|
||||
font-size: 14px;
|
||||
color: #1890ff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.coupon-discount {
|
||||
padding: 12px 16px;
|
||||
background-color: #f0f9ff;
|
||||
border-top: 1px solid #e6f7ff;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.discount-label {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.discount-amount {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.discount {
|
||||
color: #1890ff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 优惠券弹窗样式 */
|
||||
.coupon-modal-content {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.coupon-list {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.modal-coupon-card {
|
||||
margin-bottom: 12px;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.modal-coupon-card:hover {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.modal-coupon-card.active {
|
||||
border: 2px solid #1890ff;
|
||||
}
|
||||
|
||||
.coupon-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.coupon-value {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: #ff4d4f;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.coupon-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 4px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.coupon-condition {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.coupon-time {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.coupon-select {
|
||||
color: #1890ff;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -471,7 +471,7 @@ const handleLogout = () => {
|
||||
localStorage.removeItem('refreshToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
message.success('已退出登录')
|
||||
router.push('/auth')
|
||||
router.push('/')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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