123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- const api = require('../../utils/api.js')
- const app = getApp()
- Page({
- data: {
- auth: {},
- userInfo: {},
- ShareGamesParams: '',
- ShowRedPackMask: false, // 红包
- authEnter: false,
- VisitorList: [], // 最近访客
- floats: [],
- gameData: {},
- gameCount: 99,
- sharePath: 'pages/share/share',
- shareInfo: {},
- boxInfo: '', // 主页信息
- redIcon: '',
- redName: '',
- mpType: app.globalData.mpType
- },
- onLoad: function (opt) {
- let timer = setInterval(() => {
- if (app.globalData.PageCallback) {
- this.getBoxInfo(opt.mem_id, opt.scene)
- this.getShareInfo()
- this.getMemGameList(opt.mem_id, opt.scene)
- this.setData({
- auth: app.globalData.auth,
- userInfo: app.globalData.userInfo,
- helpShareId: opt.mem_id || '',
- helpShareState: opt.state || ''
- })
- this.PageInit()
- clearInterval(timer)
- }
- }, 200)
- },
- PageInit: function () {
- this.setData({
- userInfo: app.globalData.userInfo,
- auth: app.globalData.auth,
- })
- // 红包
- console.log('game-onLoad-获取userInfo', app.globalData.userInfo)
- 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
- })
- }
- }
- },
- // 设置红包动画
- setAnimation: function (e) {
- const _self = this
- return new Promise((resolve, reject) => {
- _self.setData({
- ShowRedPackMask: true
- })
- resolve()
- })
- },
- getShareInfo: function () {
- api.getShareInfo({
- data: {
- path: this.data.sharePath
- }
- }).then(res => {
- this.setData({
- shareInfo: res.data
- })
- }).catch(err => {
- console.log('getShare', err)
- })
- },
- // 获取他人主页信息
- getBoxInfo: function (id, state) {
- let params = {
- to_mem_id: id || '',
- state: state || ''
- }
- api.getHomeInfo(params).then(res => {
- this.setData({
- boxInfo: res.data
- })
- })
- },
- ChangeShare: function (e) {
- this.setData({
- ShowShareMask: e.currentTarget.dataset.show ? true : false
- })
- },
- routeHome: function (e) {
- wx.switchTab({
- url: '/pages/game/game'
- })
- },
- getMemGameList: function (id, state) {
- let params = {
- to_mem_id: id || '',
- state: state || '',
- page: 1,
- offset: 3
- }
- api.getMemGameList(params).then(res => {
- if (res.data && res.data.list.length) {
- this.setData({
- memGame: res.data,
- gameCount: res.data.count,
- floats: res.data.list.map((item) => {
- return this.data.mpType === 'gd' ? item.mem_integral : (item.mem_reward).toFixed(2)
- })
- })
- } else {
- this.getGameList(id,state)
- }
- })
- },
- getGameList: function (id, state) {
- let params = {
- to_mem_id: id || '',
- state: state || '',
- page: 1,
- offset: 999
- }
- api.getGameList(params).then(res => {
- this.setData({
- gameData: res.data.list,
- gameCount: res.data.count,
- floats: res.data.list.map((item) => {
- return this.data.mpType === 'gd' ? item.mem_integral : (item.mem_reward).toFixed(2)
- })
- })
- })
- },
- openGame: function (e) {
- let id = e.currentTarget.dataset.id
- api.openGame({
- game_id: id
- }).then(res => {
- console.log(res)
- }, err => {
- console.log(err)
- })
- },
- onShow: function () {
- wx.showShareMenu({ // 允许转发时携带 shareTicket。
- withShareTicket: true
- })
- },
- onShareAppMessage: function (e) {
- this.getShareInfo()
- let { title, image, state } = this.data.shareInfo
- let memid = this.data.userInfo.mem_id
- if (e.target && e.target.id === 'help') {
- state = this.data.helpShareState
- memid = this.data.helpShareId
- }
- let path = `/pages/share/share?state=${state}&mem_id=${memid}`
- title = title || this.data.userInfo.nickname
- return {
- title,
- path,
- imageUrl: image
- }
- },
- // 获取用户信息
- 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: (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)
- }
- })
|