修复优惠券显示错误的问题

This commit is contained in:
tsui110 2026-02-03 19:20:31 +08:00
parent 1cfa7e8322
commit f918bfc81a

View File

@ -263,8 +263,8 @@ async function fetchCoupons() {
try { try {
const userId = uni.getStorageSync('user_id') const userId = uni.getStorageSync('user_id')
if (!userId) return if (!userId) return
const res = await getUserCoupons(userId, 1, 1, 100) // status=1 const res = await getUserCoupons(userId, 0, 1, 20) // status=0
let list = [] let list = []
if (Array.isArray(res)) list = res if (Array.isArray(res)) list = res
else if (res && Array.isArray(res.coupons)) list = res.coupons else if (res && Array.isArray(res.coupons)) list = res.coupons
@ -273,14 +273,22 @@ async function fetchCoupons() {
// (scope_type = 1) (discount_type = 1) // (scope_type = 1) (discount_type = 1)
// //
// balance_amount remaining
coupons.value = list.filter(c => { coupons.value = list.filter(c => {
// scope_type=1 // scope_type=1
// scope_type // scope_type
if (c.scope_type !== undefined && c.scope_type !== 1) return false if (c.scope_type !== undefined && c.scope_type !== 1) return false
// // balance_amount remaining
if (!c.balance_amount || c.balance_amount <= 0) return false const balance = c.balance_amount ?? c.remaining ?? c.amount
if (!balance || balance <= 0) return false
return true return true
}) }).map(c => ({
// balance_amount 使
...c,
balance_amount: c.balance_amount ?? c.remaining ?? c.amount
}))
console.log('获取到的优惠券列表:', coupons.value)
} catch (e) { } catch (e) {
console.error('获取优惠券失败:', e) console.error('获取优惠券失败:', e)
coupons.value = [] coupons.value = []