// pages/tips/tips.js const api = require('../../utils/api.js') const util = require('../../utils/util.js') const app = getApp() Page({ /** * 页面的初始数据 */ data: { first: true, isLoad: false, lotteryInfo: { award: {} }, userInfo: {}, bgFlag: false, animationData: {}, isClick: false, ModalConfig: { visible: false, title: '', content: '', ModalType: '' }, qrCode: '', howToWithdraw: false, rotate: 0, mpGzh: app.globalData.mpGzh }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let timer = setInterval(() => { if (app.globalData.PageCallback) { clearInterval(timer) this.setData({ isClick: true, userInfo: app.globalData.userInfo, isLoad: true }) this.SwitchBg() } }, 200) }, onShow: function () { if (this.data.isLoad) { api.getUserInfo({ HideLoading: true }).then(res => { this.setData({ userInfo: res.data }) }, err => { console.log(err) }) } api.getLotteryDetail({ HideLoading: !this.data.first }).then(res => { this.setData({ lotteryInfo: res.data }) }) if (this.data.first) { this.setData({ first: false }) } }, SwitchBg: function (e) { setInterval(() => { this.setData({ bgFlag: !this.data.bgFlag }) }, 1000) }, start: function (e) { // 抽奖中 if (!this.data.isClick) { return false } let _self = this let award = this.data.lotteryInfo.award let length = Object.keys(award).length let deg = 360 / length this.setData({ rotate: this.data.rotate - this.data.rotate % 360 }) api.drawLottery({ HideLoading: true }).then(res => { let which = res.data.list_order let animation = wx.createAnimation({ duration: 1.4 * (2160 - (which - 1) * deg), timingFunction: 'ease-in-out' }) let rotate = this.data.rotate + 2160 - (which - 0.5) * deg animation.rotate(rotate).step() this.setData({ animationData: animation.export(), isClick: false, rotate }) setTimeout(function () { let ModelConf = { visible: true, ModalType: res.data.is_real === 2 ? 'input' : 'text' } ModelConf.title = res.data.has_award === 1 ? '很遗憾,没有中奖' : '恭喜,中奖啦' ModelConf.content = res.data.has_award === 1 ? '' : `恭喜获得${res.data.award_name}${res.data.is_real === 2 ? ',请填写相关信息领取奖励' : ''}` let { lotteryInfo } = _self.data lotteryInfo = { ...lotteryInfo, ...res.data } _self.setData({ ModalConfig: ModelConf, isClick: true, lotteryInfo }) }, 1.4 * (2160 - (which - 1) * deg) + 600) }, err => { this.setData({ isClick: true }) }) }, hideModal: function(e) { console.log(`获取到手机号-${e.detail}`) var animation = wx.createAnimation({ transformOrigin: "50% 50%", duration: 0, timingFunction: "linear" }); // animation.rotate(0).step(); this.setData({ animationData: animation.export(), isClick: true, ModalConfig: { visible: false } }) }, routeTo: function (e) { util.routeTo(e.currentTarget.dataset.url) }, routeUser: function (e) { app.globalData.openGZH = true wx.switchTab({ url: '/pages/user/index' }) }, OpenWithdraw: function (e) { console.log(this.data.qrCode) if (!this.data.qrCode) { api.getWithdrawTips().then(res => { if (res.code === 200) { this.setData({ howToWithdraw: true, qrCode: res.data.image }) } }) } else { this.setData({ howToWithdraw: true }) } }, hideWithdraw: function (e) { this.setData({ howToWithdraw: false }) } })