123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- // 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,
- guideIsShow: false,
- 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
- })
- // if (this.data.userInfo.mem_id === 12581) {
- // let which = Math.ceil(Math.random() * 8)
- // 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
- // })
- // }
- 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
- })
- },
- showGuide: function (e) {
- this.setData({
- guideIsShow: true
- })
- },
- hideGuide: function (e) {
- this.setData({
- guideIsShow: false
- })
- }
- })
|