From e74dc3faa4efc35a5b66f6af95c2f17e08f00701 Mon Sep 17 00:00:00 2001 From: xiaowang Date: Sat, 28 Feb 2026 15:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E5=8F=91=E6=94=BE?= =?UTF-8?q?=E5=92=8C=E5=B1=95=E7=A4=BA=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/src/components.d.ts | 2 + Frontend/src/router/index.ts | 6 ++ Frontend/src/views/CartView.vue | 18 ++++- Frontend/src/views/ProfileView.vue | 65 +++++-------------- .../service/impl/CartServiceImpl.java | 1 + .../service/impl/CouponServiceImpl.java | 62 ++++++++++++------ .../com/xiaowang/yuminailcore/vo/CartVO.java | 1 + 7 files changed, 84 insertions(+), 71 deletions(-) diff --git a/Frontend/src/components.d.ts b/Frontend/src/components.d.ts index 4a37c6c3..a639dab1 100644 --- a/Frontend/src/components.d.ts +++ b/Frontend/src/components.d.ts @@ -51,8 +51,10 @@ declare module 'vue' { ARadio: typeof import('ant-design-vue/es')['Radio'] ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup'] ARow: typeof import('ant-design-vue/es')['Row'] + ASegmented: typeof import('ant-design-vue/es')['Segmented'] ASelect: typeof import('ant-design-vue/es')['Select'] ASelectOption: typeof import('ant-design-vue/es')['SelectOption'] + ASkeleton: typeof import('ant-design-vue/es')['Skeleton'] ASpace: typeof import('ant-design-vue/es')['Space'] ASpin: typeof import('ant-design-vue/es')['Spin'] AStatistic: typeof import('ant-design-vue/es')['Statistic'] diff --git a/Frontend/src/router/index.ts b/Frontend/src/router/index.ts index 9707204b..9026672b 100644 --- a/Frontend/src/router/index.ts +++ b/Frontend/src/router/index.ts @@ -63,6 +63,12 @@ const router = createRouter({ component: () => import('../views/SettingsView.vue'), meta: { requiresAuth: true, hideNav: true, isAdmin: false } }, + { + path: '/coupons', + name: 'coupons', + component: () => import('../views/CouponView.vue'), + meta: { requiresAuth: true, isAdmin: false ,hideNav: true} + }, { path: '/admin/login', name: 'admin-login', diff --git a/Frontend/src/views/CartView.vue b/Frontend/src/views/CartView.vue index e74e184e..4297574d 100644 --- a/Frontend/src/views/CartView.vue +++ b/Frontend/src/views/CartView.vue @@ -215,6 +215,7 @@ interface CartItem { price: number quantity: number totalPrice: number + tags: string selected: boolean } @@ -290,17 +291,28 @@ const loadAvailableCoupons = async () => { const totalPrice = subtotal.value // 收集商品标签 - const productTags = cartItems.value + const productTagsSet = new Set() + cartItems.value .filter(item => item.selected) - .map(item => item.productTitle.split(' ')[0]) // 简单处理,取商品标题的第一个词作为标签 - .join(',') + .forEach(item => { + if (item.tags) { + const tags = item.tags.split(',').map(tag => tag.trim()) + tags.forEach(tag => { + if (tag) productTagsSet.add(tag) + }) + } + }) + const productTags = Array.from(productTagsSet).join(',') if (totalPrice > 0) { const coupons = await couponApi.getAvailableCoupons(productTags, totalPrice) availableCoupons.value = coupons + } else { + availableCoupons.value = [] } } catch (error) { console.error('获取可用优惠券失败:', error) + availableCoupons.value = [] } } diff --git a/Frontend/src/views/ProfileView.vue b/Frontend/src/views/ProfileView.vue index 9490a314..b84d6454 100644 --- a/Frontend/src/views/ProfileView.vue +++ b/Frontend/src/views/ProfileView.vue @@ -137,34 +137,7 @@ - - -

我的优惠券

- - 去领取 - -
- -
-
- {{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }} -
-
-
{{ coupon.couponName }}
-
- 满{{ coupon.minAmount }}元可用 -
-
- {{ coupon.startTime }} 至 {{ coupon.endTime }} -
-
- {{ coupon.statusName }} -
-
-
-
-
-
+
@@ -246,10 +219,9 @@ const editModalVisible = ref(false) const saving = ref(false) const uploading = ref(false) -// 订单和优惠券相关状态 +// 订单相关状态 const activeTab = ref('') const orders = ref([]) -const coupons = ref([]) const loading = ref(false) const orderCount = ref(0) const couponCount = ref(0) @@ -406,24 +378,11 @@ const loadOrders = async () => { } } -// 加载优惠券列表 -const loadCoupons = async () => { - loading.value = true - try { - const data = await couponApi.listUserCoupons() - coupons.value = data - couponCount.value = data.length - } catch (error) { - message.error('获取优惠券列表失败') - } finally { - loading.value = false - } -} + // 处理优惠券点击 const handleCouponClick = () => { - activeTab.value = 'coupons' - loadCoupons() + router.push('/coupons') } // 处理取消订单 @@ -450,8 +409,7 @@ const handleMenuClick = (key: string) => { } else if (key === 'orders') { router.push('/orders') } else if (key === 'coupons') { - activeTab.value = 'coupons' - loadCoupons() + router.push('/coupons') } else if (key === 'address') { message.info('地址管理功能开发中...') } else if (key === 'payment') { @@ -508,8 +466,19 @@ const getRandomColor = () => { onMounted(() => { fetchUserInfo() loadOrders() - loadCoupons() + // 异步加载优惠券数量 + loadCouponCount() }) + +// 加载优惠券数量 +const loadCouponCount = async () => { + try { + const data = await couponApi.listUserCoupons() + couponCount.value = data.length + } catch (error) { + console.error('获取优惠券数量失败:', error) + } +}