功能:新增微信小程序界面
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
const couponApi = require('../../api/coupon')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
|
||||
function getBenefitText(coupon) {
|
||||
if (Number(coupon.couponType) === 1) {
|
||||
return `${coupon.discountValue} 折`
|
||||
}
|
||||
return `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
coupons: []
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadCoupons()
|
||||
},
|
||||
|
||||
async loadCoupons() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({
|
||||
isLoggedIn,
|
||||
loading: isLoggedIn
|
||||
})
|
||||
|
||||
if (!isLoggedIn) {
|
||||
this.setData({
|
||||
coupons: [],
|
||||
loading: false
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const coupons = await couponApi.listUserCoupons()
|
||||
const list = Array.isArray(coupons) ? coupons.map(item => ({
|
||||
...item,
|
||||
benefitText: getBenefitText(item),
|
||||
periodText: `${String(item.startTime || '').slice(0, 10)} - ${String(item.endTime || '').slice(0, 10)}`,
|
||||
sourceText: item.sourceType === 'SYSTEM_VIP' ? 'VIP 自动匹配' : '用户优惠券'
|
||||
})) : []
|
||||
|
||||
this.setData({
|
||||
coupons: list
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
coupons: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '优惠券加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenAuth() {
|
||||
navigation.openAuth('/pages/coupons/index')
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/profile/index')
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user