123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- // pages/share/game.js
- const api = require('../../utils/api.js')
- let app = getApp()
- Page({
- data: {
- result: {
- mem: {},
- game: {},
- auth: {},
- currentInfo: {},
- authEnter: false,
- ShowRedPackMask: false, // 红包
- getSuccess: false, // 红包是否领取
- redAnimation: false, // 红包动画
- redIcon: '',
- redName: ''
- },
- mpType: app.globalData.mpType
- },
- onLoad: function(opt) {
- let timer = setInterval(() => {
- if (app.globalData.PageCallback) {
- let {
- game_id,
- state,
- mem_id
- } = opt
- this.initPage()
- this.getInfo(mem_id)
- this.getGameInfo(game_id, state)
- clearInterval(timer)
- }
- }, 200)
- },
- initPage: function() {
- this.setData({
- auth: app.globalData.auth,
- })
- if (app.globalData.userInfo.get_novice_award === 1) {
- // 是否领取了新手奖励 1否 2是
- if (app.globalData.auth.red === 2) {
- wx.hideTabBar({
- animation: true
- })
- api.getMpRedInfo().then(res => {
- this.setData({
- redIcon: res.data.icon || '/image/logo.png',
- redName: res.data.name || app.globalData.mpName
- })
- setTimeout(() => {
- this.setAnimation().then(() => {
- this.setData({
- redAnimation: true
- })
- })
- }, 350)
- })
- } else {
- this.setData({
- authEnter: true
- })
- }
- }
- },
- // 获取用户信息
- getUserInfoFun: function() {
- var _self = this;
- wx.getUserInfo({
- success: function(res) {
- console.log(res)
- api.updateUserInfo({
- raw_data: res.rawData,
- signature: res.signature,
- encrypted_data: res.encryptedData,
- iv: res.iv
- }).then(res => {
- if (res.code === 200) {
- _self.setData({
- // redPackAward: _self.data.mpType === 'gd' ? res.data.novice_award_integral : (res.data.novice_award * 1).toFixed(2),
- redPackAward: (res.data.novice_award * 1).toFixed(2),
- getSuccess: true
- })
- // 更新余额
- api.getUserInfo()
- setTimeout(() => {
- _self.setData({
- userInfo: getApp().globalData.userInfo
- })
- }, 500)
- } else {
- wx.showToast({
- title: res.msg,
- })
- }
- })
- _self.setData({
- authEnter: false
- })
- },
- fail: function(err) {
- console.log(err)
- }
- })
- },
- // 关闭红包弹框
- CloseRedPack: function(e) {
- const _self = this
- _self.setData({
- redAnimation: false
- })
- setTimeout(() => {
- _self.setData({
- ShowRedPackMask: false
- })
- wx.showTabBar({
- animation: true
- })
- }, 300)
- },
- // 设置红包动画
- setAnimation: function(e) {
- const _self = this
- return new Promise((resolve, reject) => {
- _self.setData({
- ShowRedPackMask: true
- })
- resolve()
- })
- },
- getGameInfo: function(game_id, state) {
- api.getShareGameDetail({
- game_id,
- state
- }).then(res => {
- this.setData({
- result: res.data
- })
- }, err => {
- console.log(err)
- })
- },
- getInfo: function(id) {
- api.getHomeInfo({
- to_mem_id: id
- }).then(res => {
- this.setData({
- currentInfo: res.data
- })
- })
- },
- switchTo: function(e) {
- wx.switchTab({
- url: e.currentTarget.dataset.path
- })
- }
- })
|