购物车和订单中心以及优惠券相关功能初版
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
layout="vertical"
|
||||
class="auth-form"
|
||||
>
|
||||
<a-form-item name="account" label="账号">
|
||||
<a-form-item v-if="activeTab === 'register'" name="nickname" label="昵称">
|
||||
<a-input
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
v-model:value="formData.nickname"
|
||||
placeholder="请输入昵称"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
@@ -42,6 +42,27 @@
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="account" label="账号">
|
||||
<a-input
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
size="large"
|
||||
@blur="handleAccountBlur"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
<div v-if="accountStatus" class="account-status">
|
||||
<span v-if="accountStatus.exists" class="status-success">
|
||||
账号存在,昵称:{{ accountStatus.nickname }}
|
||||
</span>
|
||||
<span v-else class="status-error">
|
||||
账号不存在
|
||||
</span>
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="password" label="密码">
|
||||
<a-input-password
|
||||
v-model:value="formData.password"
|
||||
@@ -90,18 +111,6 @@
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="nickname" label="昵称">
|
||||
<a-input
|
||||
v-model:value="formData.nickname"
|
||||
placeholder="请输入昵称"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'login'" style="margin-bottom: 8px">
|
||||
<div class="form-actions">
|
||||
<a-checkbox v-model:checked="formData.rememberMe">记住我</a-checkbox>
|
||||
@@ -150,6 +159,7 @@ import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined } from '@ant-des
|
||||
import { message } from 'ant-design-vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { shopApi } from '@/api/shop'
|
||||
import { userApi } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -157,6 +167,7 @@ const activeTab = ref<'login' | 'register'>('login')
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
const accountStatus = ref<any>(null)
|
||||
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
@@ -187,7 +198,8 @@ const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
const rules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' }
|
||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' },
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
@@ -267,6 +279,28 @@ const handleQQLogin = () => {
|
||||
message.info('QQ登录功能开发中')
|
||||
}
|
||||
|
||||
const handleAccountBlur = async () => {
|
||||
if (activeTab.value === 'login' && formData.account) {
|
||||
try {
|
||||
const res = await userApi.getUserByAccount(formData.account)
|
||||
if (res) {
|
||||
accountStatus.value = {
|
||||
exists: true,
|
||||
nickname: res.nickname
|
||||
}
|
||||
} else {
|
||||
accountStatus.value = {
|
||||
exists: false
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
accountStatus.value = {
|
||||
exists: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdminLogin = () => {
|
||||
console.log('跳转到管理后台登录')
|
||||
localStorage.removeItem('accessToken')
|
||||
@@ -432,4 +466,17 @@ onMounted(() => {
|
||||
color: #764ba2;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.account-status {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
color: #f5222d;
|
||||
}
|
||||
</style>
|
||||
+130
-96
@@ -29,15 +29,17 @@
|
||||
<a-checkbox v-model:checked="item.selected" @change="handleSelectChange" />
|
||||
|
||||
<!-- 商品图片 -->
|
||||
<div class="item-image" :style="{ backgroundColor: item.bgColor }">
|
||||
<span>{{ item.title[0] }}</span>
|
||||
<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-details">
|
||||
<h3 class="item-name">{{ item.title }}</h3>
|
||||
<h3 class="item-name">{{ item.productTitle }}</h3>
|
||||
<p class="item-price">¥{{ item.price.toFixed(2) }}</p>
|
||||
<p class="item-duration">预计耗时: {{ item.approximateDuration }}</p>
|
||||
|
||||
<!-- 数量控制和删除按钮 -->
|
||||
<div class="item-actions">
|
||||
@@ -84,10 +86,6 @@
|
||||
<span>小计</span>
|
||||
<span>¥{{ subtotal.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>预计消耗时间</span>
|
||||
<span class="duration">{{ totalDuration }}</span>
|
||||
</div>
|
||||
<div class="summary-row total">
|
||||
<span>总计</span>
|
||||
<span class="total-price">¥{{ subtotal.toFixed(2) }}</span>
|
||||
@@ -109,60 +107,84 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
LeftOutlined,
|
||||
DeleteOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { ProductVO } from '@/api/product'
|
||||
import { cartApi } from '../api/cart'
|
||||
import { orderApi } from '../api/order'
|
||||
import { fileApi } from '../api/index'
|
||||
|
||||
interface CartItem {
|
||||
id: number
|
||||
productId: number
|
||||
productTitle: string
|
||||
productImage: string
|
||||
price: number
|
||||
quantity: number
|
||||
totalPrice: number
|
||||
selected: boolean
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 购物车商品数据(模拟真实产品数据结构)
|
||||
const cartItems = ref<Array<{
|
||||
id: number
|
||||
productId: number
|
||||
title: string
|
||||
price: number
|
||||
imageUrl?: string
|
||||
bgColor: string
|
||||
quantity: number
|
||||
selected: boolean
|
||||
approximateDuration: string
|
||||
}>>([
|
||||
{
|
||||
id: 1,
|
||||
productId: 1,
|
||||
title: '经典美甲',
|
||||
price: 99,
|
||||
bgColor: '#ffe4d6',
|
||||
quantity: 1,
|
||||
selected: true,
|
||||
approximateDuration: '30分钟'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
productId: 2,
|
||||
title: '法式美甲',
|
||||
price: 168,
|
||||
bgColor: '#d6eaff',
|
||||
quantity: 2,
|
||||
selected: true,
|
||||
approximateDuration: '45分钟'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
productId: 3,
|
||||
title: '光疗美甲',
|
||||
price: 238,
|
||||
bgColor: '#e2ffd6',
|
||||
quantity: 1,
|
||||
selected: false,
|
||||
approximateDuration: '60分钟'
|
||||
// 购物车商品数据
|
||||
const cartItems = ref<CartItem[]>([])
|
||||
|
||||
// 图片缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
// 加载购物车数据
|
||||
const loadCartItems = async () => {
|
||||
try {
|
||||
const data = await cartApi.getCartList()
|
||||
cartItems.value = data.map((item: any) => ({
|
||||
...item,
|
||||
selected: true
|
||||
}))
|
||||
|
||||
// 加载商品图片的临时加签链接
|
||||
await loadProductImages(cartItems.value)
|
||||
} catch (error) {
|
||||
message.error('获取购物车数据失败')
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
// 加载商品图片
|
||||
const loadProductImages = async (items: CartItem[]) => {
|
||||
for (const item of items) {
|
||||
if (item.productImage) {
|
||||
// 过滤掉HTML标签
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
// 从cleanImageUrl中提取图片ID
|
||||
// 假设图片URL的格式为 '/api/file/get/123'
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(imageId))
|
||||
imageIdCache.value[imageId] = signedUrl
|
||||
}
|
||||
// 更新商品图片为临时加签链接
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
// 如果获取签名链接失败,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
// 如果不是有效的图片URL格式,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算选中的商品数量
|
||||
const selectedCount = computed(() => {
|
||||
@@ -178,39 +200,17 @@ const totalQuantity = computed(() => {
|
||||
const subtotal = computed(() => {
|
||||
return cartItems.value
|
||||
.filter(item => item.selected)
|
||||
.reduce((sum, item) => sum + (item.price * item.quantity), 0)
|
||||
.reduce((sum, item) => sum + item.totalPrice, 0)
|
||||
})
|
||||
|
||||
// 计算预计总消耗时间
|
||||
const totalDuration = computed(() => {
|
||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||
if (selectedItems.length === 0) return '0分钟'
|
||||
|
||||
let totalMinutes = 0
|
||||
selectedItems.forEach(item => {
|
||||
const durationStr = item.approximateDuration
|
||||
const match = durationStr.match(/(\d+)/)
|
||||
if (match) {
|
||||
totalMinutes += parseInt(match[1]) * item.quantity
|
||||
}
|
||||
})
|
||||
|
||||
if (totalMinutes < 60) {
|
||||
return `${totalMinutes}分钟`
|
||||
} else {
|
||||
const hours = Math.floor(totalMinutes / 60)
|
||||
const minutes = totalMinutes % 60
|
||||
if (minutes === 0) {
|
||||
return `${hours}小时`
|
||||
} else {
|
||||
return `${hours}小时${minutes}分钟`
|
||||
}
|
||||
}
|
||||
})
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 处理返回按钮点击
|
||||
const handleBackClick = () => {
|
||||
console.log('返回按钮被点击')
|
||||
router.back()
|
||||
}
|
||||
|
||||
@@ -225,26 +225,42 @@ const handleSelectChange = () => {
|
||||
}
|
||||
|
||||
// 处理减少数量
|
||||
const handleDecreaseQuantity = (item: any) => {
|
||||
const handleDecreaseQuantity = async (item: CartItem) => {
|
||||
if (item.quantity > 1) {
|
||||
item.quantity--
|
||||
try {
|
||||
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||
} catch (error) {
|
||||
message.error('更新数量失败')
|
||||
item.quantity++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理增加数量
|
||||
const handleIncreaseQuantity = (item: any) => {
|
||||
const handleIncreaseQuantity = async (item: CartItem) => {
|
||||
if (item.quantity < 99) {
|
||||
item.quantity++
|
||||
try {
|
||||
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||
} catch (error) {
|
||||
message.error('更新数量失败')
|
||||
item.quantity--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理删除商品
|
||||
const handleDeleteItem = (item: any) => {
|
||||
console.log('删除商品:', item.name)
|
||||
const index = cartItems.value.findIndex(i => i.id === item.id)
|
||||
if (index > -1) {
|
||||
cartItems.value.splice(index, 1)
|
||||
message.success('商品已删除')
|
||||
const handleDeleteItem = async (item: CartItem) => {
|
||||
try {
|
||||
await cartApi.removeFromCart(item.productId)
|
||||
const index = cartItems.value.findIndex(i => i.id === item.id)
|
||||
if (index > -1) {
|
||||
cartItems.value.splice(index, 1)
|
||||
message.success('商品已删除')
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除商品失败')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,19 +270,26 @@ const handleBrowseProducts = () => {
|
||||
}
|
||||
|
||||
// 处理结算
|
||||
const handleCheckout = () => {
|
||||
const handleCheckout = async () => {
|
||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||
if (selectedItems.length === 0) {
|
||||
message.warning('请先选择要结算的商品')
|
||||
return
|
||||
}
|
||||
console.log('结算购物车:', {
|
||||
items: selectedItems,
|
||||
subtotal: subtotal.value,
|
||||
totalDuration: totalDuration.value
|
||||
})
|
||||
message.success('正在跳转到结算页面...')
|
||||
|
||||
try {
|
||||
const order = await orderApi.createOrder({})
|
||||
message.success('订单创建成功')
|
||||
router.push('/profile')
|
||||
} catch (error) {
|
||||
message.error('创建订单失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时获取购物车数据
|
||||
onMounted(() => {
|
||||
loadCartItems()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -338,13 +361,19 @@ const handleCheckout = () => {
|
||||
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;
|
||||
}
|
||||
|
||||
.item-details {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
@@ -353,6 +382,11 @@ const handleCheckout = () => {
|
||||
font-weight: 600;
|
||||
margin: 0 0 4px 0;
|
||||
line-height: 1.4;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
|
||||
@@ -97,6 +97,7 @@ import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { fileApi } from '@/api/index'
|
||||
import { cartApi } from '@/api/cart'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -192,15 +193,36 @@ const handleFavoriteClick = () => {
|
||||
ElMessage.success(isFavorite.value ? '已收藏' : '已取消收藏')
|
||||
}
|
||||
|
||||
const handleAddToCart = () => {
|
||||
console.log('添加到购物车:', product.value.title)
|
||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||
const handleAddToCart = async () => {
|
||||
console.log('添加到购物车按钮被点击')
|
||||
console.log('商品ID:', product.value.id)
|
||||
console.log('商品标题:', product.value.title)
|
||||
try {
|
||||
console.log('开始调用cartApi.addToCart')
|
||||
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||
console.log('调用cartApi.addToCart成功')
|
||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||
} catch (error) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
ElMessage.error('添加到购物车失败,请重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBuyNow = () => {
|
||||
console.log('立即购买:', product.value.title)
|
||||
// 这里可以跳转到订单确认页面
|
||||
ElMessage.success('跳转到订单确认页面')
|
||||
const handleBuyNow = async () => {
|
||||
console.log('立即购买按钮被点击')
|
||||
console.log('商品ID:', product.value.id)
|
||||
console.log('商品标题:', product.value.title)
|
||||
try {
|
||||
console.log('开始调用cartApi.addToCart')
|
||||
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||
console.log('调用cartApi.addToCart成功')
|
||||
// 跳转到购物车页面
|
||||
console.log('开始跳转到购物车页面')
|
||||
router.push('/cart')
|
||||
} catch (error) {
|
||||
console.error('立即购买失败:', error)
|
||||
ElMessage.error('操作失败,请重试')
|
||||
}
|
||||
}
|
||||
|
||||
// 页面挂载时获取商品详情
|
||||
|
||||
@@ -94,6 +94,78 @@
|
||||
</a-list>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<a-card v-if="activeTab === 'orders'" :bordered="false" class="content-card">
|
||||
<h3>我的订单</h3>
|
||||
<a-empty v-if="orders.length === 0" 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>
|
||||
</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>
|
||||
</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>
|
||||
</a-card>
|
||||
|
||||
<!-- 优惠券列表 -->
|
||||
<a-card v-if="activeTab === 'coupons'" :bordered="false" class="content-card">
|
||||
<h3>我的优惠券</h3>
|
||||
<a-empty v-if="coupons.length === 0" description="暂无优惠券">
|
||||
<a-button type="primary">去领取</a-button>
|
||||
</a-empty>
|
||||
<div v-else class="coupon-list">
|
||||
<a-card v-for="coupon in coupons" :key="coupon.id" class="coupon-card">
|
||||
<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 :class="['coupon-status', coupon.status === 1 ? 'available' : 'used']">
|
||||
{{ coupon.statusName }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<div class="logout-section">
|
||||
<a-button danger block @click="handleLogout">
|
||||
退出登录
|
||||
@@ -154,6 +226,8 @@ import type { UploadProps } from 'ant-design-vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { orderApi } from '@/api/order'
|
||||
import { couponApi } from '@/api/coupon'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -172,6 +246,12 @@ const editModalVisible = ref(false)
|
||||
const saving = ref(false)
|
||||
const uploading = ref(false)
|
||||
|
||||
// 订单和优惠券相关状态
|
||||
const activeTab = ref('')
|
||||
const orders = ref<any[]>([])
|
||||
const coupons = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const editForm = ref({
|
||||
nickname: '',
|
||||
avatar: '',
|
||||
@@ -310,12 +390,58 @@ const handleCancelEdit = () => {
|
||||
editModalVisible.value = false
|
||||
}
|
||||
|
||||
// 加载订单列表
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await orderApi.getOrderList()
|
||||
orders.value = data
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载优惠券列表
|
||||
const loadCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await couponApi.listUserCoupons()
|
||||
coupons.value = data
|
||||
} catch (error) {
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消订单
|
||||
const handleCancelOrder = async (orderId: number) => {
|
||||
Modal.confirm({
|
||||
title: '确认取消订单',
|
||||
content: '确定要取消这个订单吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await orderApi.cancelOrder(orderId)
|
||||
message.success('订单已取消')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
message.error('取消订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleMenuClick = (key: string) => {
|
||||
console.log('菜单项被点击:', key)
|
||||
if (key === 'wishlist') {
|
||||
router.push('/wishlist')
|
||||
} else if (key === 'orders') {
|
||||
message.info('订单功能开发中...')
|
||||
router.push('/orders')
|
||||
} else if (key === 'coupons') {
|
||||
activeTab.value = 'coupons'
|
||||
loadCoupons()
|
||||
} else if (key === 'address') {
|
||||
message.info('地址管理功能开发中...')
|
||||
} else if (key === 'payment') {
|
||||
@@ -363,6 +489,12 @@ const handleShopClick = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
@@ -672,4 +804,213 @@ onMounted(() => {
|
||||
color: white !important;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.content-card {
|
||||
margin: 0 15px 15px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.content-card :deep(.ant-card-body) {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.content-card h3 {
|
||||
margin: 0 0 20px 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.coupon-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.coupon-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
background: linear-gradient(135deg, #f5f7ff 0%, #e8ecff 100%);
|
||||
}
|
||||
|
||||
.coupon-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.coupon-value {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #667eea;
|
||||
padding: 20px;
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
border-radius: 8px;
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.coupon-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.coupon-condition {
|
||||
font-size: 12px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.coupon-time {
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.coupon-status {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
padding: 2px 8px;
|
||||
border-radius: 8px;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.coupon-status.available {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.coupon-status.used {
|
||||
background: #f5f5f5;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
</style>
|
||||
@@ -72,7 +72,10 @@ const formState = reactive({
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
account: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@
|
||||
<a-button v-if="hasPermission('coupon:edit')" 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)">
|
||||
发放
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('coupon:delete') && record.status !== 2" type="link" size="small" danger @click="handleDelete(record)">
|
||||
删除
|
||||
</a-button>
|
||||
@@ -132,6 +135,43 @@
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 发放优惠券模态框 -->
|
||||
<a-modal
|
||||
v-model:open="distributeModalVisible"
|
||||
title="发放优惠券"
|
||||
@ok="handleDistributeOk"
|
||||
@cancel="handleDistributeCancel"
|
||||
:confirmLoading="distributeLoading"
|
||||
width="800px"
|
||||
>
|
||||
<a-form
|
||||
ref="distributeFormRef"
|
||||
:model="distributeFormState"
|
||||
:rules="distributeFormRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券" name="couponId">
|
||||
<a-input v-model:value="distributeFormState.couponName" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="选择用户" name="userIds">
|
||||
<a-select
|
||||
v-model:value="distributeFormState.userIds"
|
||||
mode="multiple"
|
||||
placeholder="请选择要发放的用户"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option v-for="user in userList" :key="user.id" :value="user.id">
|
||||
{{ user.nickname }} ({{ user.account }})
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="发放数量" name="quantity">
|
||||
<a-input-number v-model:value="distributeFormState.quantity" placeholder="请输入发放数量" :min="1" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -179,8 +219,15 @@ const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentCoupon = ref<Coupon | null>(null)
|
||||
|
||||
// 发放优惠券相关状态
|
||||
const distributeModalVisible = ref(false)
|
||||
const distributeLoading = ref(false)
|
||||
const distributeFormRef = ref<FormInstance>()
|
||||
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
|
||||
const couponList = ref<Coupon[]>([])
|
||||
const tagList = ref<TagVO[]>([])
|
||||
const userList = ref<any[]>([])
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -217,6 +264,19 @@ const formRules = {
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 发放优惠券表单状态
|
||||
const distributeFormState = reactive({
|
||||
couponName: '',
|
||||
userIds: [] as number[],
|
||||
quantity: 1
|
||||
})
|
||||
|
||||
// 发放优惠券表单规则
|
||||
const distributeFormRules = {
|
||||
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
|
||||
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||
@@ -371,6 +431,62 @@ const handleDelete = (record: Coupon) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 加载用户列表
|
||||
const fetchUsers = async () => {
|
||||
try {
|
||||
// 这里应该调用获取用户列表的API
|
||||
// 暂时使用模拟数据
|
||||
userList.value = [
|
||||
{ id: 1, nickname: '用户1', account: 'user1' },
|
||||
{ id: 2, nickname: '用户2', account: 'user2' },
|
||||
{ id: 3, nickname: '用户3', account: 'user3' }
|
||||
]
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 显示发放优惠券模态框
|
||||
const showDistributeModal = (record: Coupon) => {
|
||||
currentDistributeCoupon.value = record
|
||||
distributeFormState.couponName = record.couponName
|
||||
distributeFormState.userIds = []
|
||||
distributeFormState.quantity = 1
|
||||
fetchUsers()
|
||||
distributeModalVisible.value = true
|
||||
}
|
||||
|
||||
// 处理发放优惠券
|
||||
const handleDistributeOk = async () => {
|
||||
try {
|
||||
await distributeFormRef.value?.validate()
|
||||
distributeLoading.value = true
|
||||
|
||||
if (!currentDistributeCoupon.value) return
|
||||
|
||||
// 调用发放优惠券的API
|
||||
await adminCouponApi.distributeCoupon({
|
||||
couponId: currentDistributeCoupon.value.id,
|
||||
userIds: distributeFormState.userIds,
|
||||
quantity: distributeFormState.quantity
|
||||
})
|
||||
|
||||
message.success('发放成功')
|
||||
distributeModalVisible.value = false
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
message.error('发放失败')
|
||||
} finally {
|
||||
distributeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 取消发放优惠券
|
||||
const handleDistributeCancel = () => {
|
||||
distributeModalVisible.value = false
|
||||
distributeFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await fetchTags()
|
||||
|
||||
Reference in New Issue
Block a user