// pages/luckDraw/detail.js import LuckDraw from '../../api/luck-draw' import {getMobileCache, getPhoneNumber} from '../../utils/user' const app = getApp(); const DEFAULT_GIFTS = [ { icoUrl: '', text: '' }, { iconUrl: '', text: '' },{ icoUrl: '', text: '' }, { icoUrl: '', text: ''}, { icoUrl: '', text: ''}, { icoUrl: '', text: '' }, { icoUrl: '', text: ''}, { icoUrl: '', text: '' } ]; Page({ /** * 页面的初始数据 */ data: { activityId: 0, forbidTurn: false, giftList: DEFAULT_GIFTS, allNum: 1000, remainNum: 128, remainNumSplits: [], showHitPrizeDlg: false, showNoHitPrizeDlg: false, showPage: true }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (!options.id) { app.showToast ('入参错误'); wx.navigateTo({ url: './index', }) return } this.data.activityId = options.id this.loadActivity() this.getDrawTimes() }, loadActivity: function() { LuckDraw.getActivityDetail(this.data.activityId).then(resp => { if (resp.code == 200 && resp.data != null) { this.mapDataToView(resp.data) } }).catch(_ => { console.log(_) app.showToast ('活动不存在'); wx.navigateTo({ url: './index', }) return }) }, /** * 获取次数 */ getDrawTimes: function() { LuckDraw.getTimes(this.data.activityId, getMobileCache()).then(res => { if (res.code == 200) { this.setData({ remainNum: res.data.remainTimes, allNum: res.data.allTimes, }) this.setRemainNumSplits() } }).catch(_ => {}) }, /** * 活动数据映射 */ mapDataToView: function(activity) { activity.goodsItemList.forEach(v => { const pos = parseInt(v.pos || 0) if (pos > 0) { if (this.data.giftList[pos-1].isLoaded) { return true } this.data.giftList[pos - 1].isLoaded = true this.data.giftList[pos - 1].text = v.goodsName this.data.giftList[pos - 1].iconUrl = v.goodsSmallImage this.data.giftList[pos - 1].hitIconUrl = v.goodsBigImage this.data.giftList[pos - 1].goodsId = v.goodsId this.data.giftList[pos - 1].couponId = v.couponId this.data.giftList[pos - 1].isSpecial = v.isSpecial this.data.giftList[pos - 1].hitDesc = v.hitDesc this.data.giftList[pos - 1].active = false } }) this.setData({ activityTitle: activity.activityTitle, showBeginTime: activity.showBeginTime, showEndTime: activity.showEndTime, beginTime: activity.beginTime, endTime: activity.endTime, timeType: activity.timeType, giftList: this.data.giftList, ruleDesc: activity.ruleDesc || '' }) }, /** * 开始转动奖品,抽奖 */ turnPrize: function() { console.log("开始抽奖") }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, setRemainNumSplits: function() { this.setData({ remainNumSplits: (this.data.remainNum || 0).toString().split("") }) }, closeDlg: function() { this.setData({ showHitPrizeDlg: false, showNoHitPrizeDlg: false }) } })