优惠券发放和展示功能优化

This commit is contained in:
xiaowang
2026-02-28 15:45:16 +08:00
parent 29168a39fb
commit e74dc3faa4
7 changed files with 84 additions and 71 deletions
+15 -3
View File
@@ -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<string>()
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 = []
}
}