game.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/share/game.js
  2. const api = require('../../utils/api.js')
  3. let app = getApp()
  4. Page({
  5. data: {
  6. result: {
  7. mem: {},
  8. game: {},
  9. auth: {},
  10. currentInfo: {},
  11. authEnter: false,
  12. ShowRedPackMask: false, // 红包
  13. getSuccess: false, // 红包是否领取
  14. redAnimation: false, // 红包动画
  15. redIcon: '',
  16. redName: ''
  17. },
  18. mpType: app.globalData.mpType
  19. },
  20. onLoad: function(opt) {
  21. let timer = setInterval(() => {
  22. if (app.globalData.PageCallback) {
  23. let {
  24. game_id,
  25. state,
  26. mem_id
  27. } = opt
  28. this.initPage()
  29. this.getInfo(mem_id)
  30. this.getGameInfo(game_id, state)
  31. clearInterval(timer)
  32. }
  33. }, 200)
  34. },
  35. initPage: function() {
  36. this.setData({
  37. auth: app.globalData.auth,
  38. })
  39. if (app.globalData.userInfo.get_novice_award === 1) {
  40. // 是否领取了新手奖励 1否 2是
  41. if (app.globalData.auth.red === 2) {
  42. wx.hideTabBar({
  43. animation: true
  44. })
  45. api.getMpRedInfo().then(res => {
  46. this.setData({
  47. redIcon: res.data.icon || '/image/logo.png',
  48. redName: res.data.name || app.globalData.mpName
  49. })
  50. setTimeout(() => {
  51. this.setAnimation().then(() => {
  52. this.setData({
  53. redAnimation: true
  54. })
  55. })
  56. }, 350)
  57. })
  58. } else {
  59. this.setData({
  60. authEnter: true
  61. })
  62. }
  63. }
  64. },
  65. // 获取用户信息
  66. getUserInfoFun: function() {
  67. var _self = this;
  68. wx.getUserInfo({
  69. success: function(res) {
  70. console.log(res)
  71. api.updateUserInfo({
  72. raw_data: res.rawData,
  73. signature: res.signature,
  74. encrypted_data: res.encryptedData,
  75. iv: res.iv
  76. }).then(res => {
  77. if (res.code === 200) {
  78. _self.setData({
  79. // redPackAward: _self.data.mpType === 'gd' ? res.data.novice_award_integral : (res.data.novice_award * 1).toFixed(2),
  80. redPackAward: (res.data.novice_award * 1).toFixed(2),
  81. getSuccess: true
  82. })
  83. // 更新余额
  84. api.getUserInfo()
  85. setTimeout(() => {
  86. _self.setData({
  87. userInfo: getApp().globalData.userInfo
  88. })
  89. }, 500)
  90. } else {
  91. wx.showToast({
  92. title: res.msg,
  93. })
  94. }
  95. })
  96. _self.setData({
  97. authEnter: false
  98. })
  99. },
  100. fail: function(err) {
  101. console.log(err)
  102. }
  103. })
  104. },
  105. // 关闭红包弹框
  106. CloseRedPack: function(e) {
  107. const _self = this
  108. _self.setData({
  109. redAnimation: false
  110. })
  111. setTimeout(() => {
  112. _self.setData({
  113. ShowRedPackMask: false
  114. })
  115. wx.showTabBar({
  116. animation: true
  117. })
  118. }, 300)
  119. },
  120. // 设置红包动画
  121. setAnimation: function(e) {
  122. const _self = this
  123. return new Promise((resolve, reject) => {
  124. _self.setData({
  125. ShowRedPackMask: true
  126. })
  127. resolve()
  128. })
  129. },
  130. getGameInfo: function(game_id, state) {
  131. api.getShareGameDetail({
  132. game_id,
  133. state
  134. }).then(res => {
  135. this.setData({
  136. result: res.data
  137. })
  138. }, err => {
  139. console.log(err)
  140. })
  141. },
  142. getInfo: function(id) {
  143. api.getHomeInfo({
  144. to_mem_id: id
  145. }).then(res => {
  146. this.setData({
  147. currentInfo: res.data
  148. })
  149. })
  150. },
  151. switchTo: function(e) {
  152. wx.switchTab({
  153. url: e.currentTarget.dataset.path
  154. })
  155. }
  156. })