import commonApi from '../../../../api/common'; import userApi from '../../../../api/user'; Page({ /** * 页面的初始数据 */ data: { detail:{}, activityId:'', detailLoading:false, getting:true, isShowModal:false, errorMsg:'' }, /** * 生命周期函数--监听页面加载 */ 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)=>{ wx.showToast({ title: '领取成功', }); this.setData({ isShowModal:true, errorMsg:'恭喜您已领取成功!' }) }).catch((e)=>{ this.setData({ isShowModal:true, errorMsg:e.message||'领取错误' }) this.setData({ getting:false }) }) }, navToIndex(){ wx.reLaunch({ url: '/pages/help/index/index', }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ detailLoading:true }) commonApi.activities.detail(this.data.activityId).then((data)=>{ this.setData({ detailLoading:false, getting:false, detail:data }); return userApi.coupon.check(this.data.activityId); }).then((data)=>{ 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() { } })