// pages/coupon/coupon.js Page({ /** * 页面的初始数据 */ data: { couponArr : '', coupons : [], count : '', couponLabel : [ { title : "未使用", used: 0 }, { title : "已使用", used: 1 }, { title : "已过期", used: 2 } ], stateType : '0', //卡券状态 barHeight : getApp().globalData.statusBarHeight, type : '' }, /** * 生命周期函数--监听页面加载 */ onLoad (options) { this.setData({ type : options.type }) }, /** * tabs */ orderTab(e){ if(this.data.stateType != e.currentTarget.dataset.state){ this.setData({ stateType: e.currentTarget.dataset.state }) // 获取卡权益 this.couponInfo() } }, /** * 生命周期函数--监听页面显示 */ onShow () { // 获取列表 this.couponInfo(); }, /** * 卡券列表 */ couponInfo() { wx.$api.user.coupon(this.data.stateType).then(res=>{ this.setData({ count : res.data.count, coupons : res.data.list }) }).catch(err => {}); }, /** * 去使用卡券 */ // applyTap(e) { // let id = e.currentTarget.dataset.id // wx.navigateTo({ // url: '/pages/couponDetails/couponDetails?id=' + id // }) // }, /** * 查看优惠券分组 */ couponTap(e) { let id = e.currentTarget.dataset.id, status = e.currentTarget.dataset.status wx.navigateTo({ url: '/pages/couponArr/couponArr?id=' + id + '&status=' + status }) }, publicTap() { if(this.data.type == 'couponPublic'){ wx.switchTab({ url: '/pages/user/user' }) }else { wx.navigateBack({ delta: 1 }) } }, // 优惠券跳转 couponUrl(e) { let newFrom = e.currentTarget.dataset.from, newId = e.currentTarget.dataset.id, newStatus = e.currentTarget.dataset.status if(newStatus == 0) { if(newFrom == 'washcar') { wx.$api.index.washcarCoupon(newId).then(res=>{ const newUrl = res.data let url= encodeURIComponent(newUrl) wx.redirectTo({ // 跳转到webview页面 url: `/pages/washcar/washcar?url=${url}` }); }).catch(err=>{ if(!err.login){ // 写入缓存 wx.setStorage({ key : 'token', data : '' }) } }) return } wx.navigateTo({ url: '/pages/couponDetails/couponDetails?id=' + newId }) } } })