优惠券发放和展示功能优化
This commit is contained in:
@@ -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 = []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user