123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- // pages/luckDraw/detail.js
- import LuckDraw from '../../api/luck-draw'
- import {getMobileCache, getPhoneNumber as getPhoneNumberSync} 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: {
- pointerPos: 0,
- activityId: 0,
- forbidTurn: false,
- giftList: DEFAULT_GIFTS,
- allNum: 1000,
- remainNum: 128,
- remainNumSplits: [],
- showHitPrizeDlg: false,
- showNoHitPrizeDlg: false,
- showPage: true,
- isLogin: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (!options.id) {
- app.showToast ('入参错误');
- wx.navigateTo({
- url: './index',
- })
- return
- }
- this.setData({
- isLogin: getMobileCache() != ''
- })
- 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("开始抽奖")
- if (this.isLock || !this.data.isLogin) {
- return
- }
- this.isLock = false
- // 开始动画,开始是快阶段
- this.startTurnAnimationFast();
- // 开始调用后台
-
- },
- // 授权手机号
- getPhoneNumber(e) {
- getPhoneNumberSync(e, _ => {
- this.getDrawTimes()
- })
- },
- startTurnAnimationFast: function() {
- const timer = setInterval(_ => {
- if (this.data.pointerPos > 7) {
- this.data.pointerPos = 0
- }
- this.data.giftList.forEach((v, i) => {
- if (i == this.data.pointerPos) {
- v.active = true
- } else {
- v.active = false
- }
- })
- this.data.pointerPos++
- this.setData({
- giftList: this.data.giftList
- })
- }, 120)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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
- })
- }
- })
|