Files
cardtest/pages/couponArr/couponArr.js
zhangmanman b5c5316f8b [更新]
2021-06-29 14:15:41 +08:00

109 lines
2.8 KiB
JavaScript

// pages/couponArr/couponArr.js
Page({
/**
* 页面的初始数据
*/
data: {
id : '',
status : '',
couponArr : '', //卡券组列表
page : 1, //分页
lodingStats : false //加载状态
},
/**
* 生命周期函数--监听页面加载
*/
onLoad (options) {
this.setData({
id : options.id,
status : options.status
})
// 获取卡券组列表
this.couponInfo();
},
/**
* 卡券组列表
*/
couponInfo(page) {
wx.$api.user.couponArr(this.data.id, this.data.status, page || '').then(res=>{
let listArr = this.data.couponArr,
newData = []
if(page == 1 || page == undefined) listArr = []
newData = listArr.concat(res.data.data)
this.setData({
couponArr : newData,
page : res.data.page,
lodingStats : false
})
wx.stopPullDownRefresh()
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
// 获取团购列表
this.couponInfo();
},
/**
* 上拉加载
*/
onReachBottom(){
this.setData({
lodingStats: true
})
let pageNumber = this.data.page.current
if(this.data.page.has_more){
pageNumber++
this.couponInfo(pageNumber)
}
},
// 优惠券跳转
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
})
}
}
/**
* 去使用卡券
*/
// applyTap(e) {
// let id = e.currentTarget.dataset.id
// wx.navigateTo({
// url: '/pages/couponDetails/couponDetails?id=' + id
// })
// }
})