156 lines
2.9 KiB
JavaScript
156 lines
2.9 KiB
JavaScript
import commonApi from '../../../../api/common';
|
|
import userApi from '../../../../api/user';
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
detail:{},
|
|
activityId:'',
|
|
detailLoading:false,
|
|
getting:true,
|
|
hasProduct:false,
|
|
reveivedSuccess:false,
|
|
|
|
|
|
isShowModal:false,
|
|
errorMsg:'',
|
|
|
|
canReceive:false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
// const { miniProgram } = wx.getAccountInfoSync();
|
|
// const envVersion = miniProgram.envVersion;
|
|
// if(envVersion=='develop'){
|
|
// this.setData({
|
|
// activityId:2
|
|
// })
|
|
// return;
|
|
// }
|
|
this.setData({
|
|
activityId:options.id
|
|
});
|
|
},
|
|
getActivityDetail(){
|
|
|
|
},
|
|
getActivity(){
|
|
this.setData({
|
|
getting:true
|
|
})
|
|
commonApi.activities.receive(this.data.activityId).then((data)=>{
|
|
this.setData({
|
|
isShowModal:true,
|
|
getting:false,
|
|
reveivedSuccess:true,
|
|
errorMsg:'恭喜您已领取成功!'
|
|
})
|
|
}).catch((e)=>{
|
|
this.setData({
|
|
isShowModal:true,
|
|
getting:false,
|
|
errorMsg:e.message||'领取错误'
|
|
})
|
|
})
|
|
},
|
|
navToIndex(){
|
|
if(this.data.hasProduct&&this.data.canReceive){
|
|
wx.reLaunch({
|
|
url: '/pages/my/coupon/index',
|
|
})
|
|
}else{
|
|
wx.reLaunch({
|
|
url: '/pages/help/index/index',
|
|
})
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
//放在onshow里是因为去登录回来之后要继续执行这些操作
|
|
this.setData({
|
|
detailLoading:true
|
|
})
|
|
commonApi.activities.detail(this.data.activityId).then((data)=>{
|
|
const hasProduct = !!data.coupons.find((item)=>item.coupon_type=='PRODUCT');
|
|
this.setData({
|
|
detailLoading:false,
|
|
getting:false,
|
|
detail:data,
|
|
hasProduct
|
|
});
|
|
return userApi.coupon.check(this.data.activityId);
|
|
}).then((data)=>{
|
|
this.data.canReceive = data.can_receive;
|
|
if(!data.can_receive){
|
|
this.setData({
|
|
isShowModal:true,
|
|
errorMsg:data.message
|
|
})
|
|
}
|
|
}).catch((res)=>{
|
|
this.setData({
|
|
detailLoading:false
|
|
})
|
|
})
|
|
|
|
|
|
// userApi.coupon.check(this.data.activityId).then((data)=>{
|
|
// if(!data.can_receive){
|
|
// this.setData({
|
|
// isShowModal:true,
|
|
// errorMsg:data.message
|
|
// })
|
|
// }
|
|
// })
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |