share.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. const api = require('../../utils/api.js')
  2. const app = getApp()
  3. Page({
  4. data: {
  5. auth: {},
  6. userInfo: {},
  7. ShareGamesParams: '',
  8. ShowRedPackMask: false, // 红包
  9. authEnter: false,
  10. VisitorList: [], // 最近访客
  11. floats: [],
  12. gameData: {},
  13. gameCount: 99,
  14. sharePath: 'pages/share/share',
  15. shareInfo: {},
  16. boxInfo: '', // 主页信息
  17. redIcon: '',
  18. redName: '',
  19. mpType: app.globalData.mpType
  20. },
  21. onLoad: function (opt) {
  22. let timer = setInterval(() => {
  23. if (app.globalData.PageCallback) {
  24. this.getBoxInfo(opt.mem_id, opt.scene)
  25. this.getShareInfo()
  26. this.getMemGameList(opt.mem_id, opt.scene)
  27. this.setData({
  28. auth: app.globalData.auth,
  29. userInfo: app.globalData.userInfo,
  30. helpShareId: opt.mem_id || '',
  31. helpShareState: opt.state || ''
  32. })
  33. this.PageInit()
  34. clearInterval(timer)
  35. }
  36. }, 200)
  37. },
  38. PageInit: function () {
  39. this.setData({
  40. userInfo: app.globalData.userInfo,
  41. auth: app.globalData.auth,
  42. })
  43. // 红包
  44. console.log('game-onLoad-获取userInfo', app.globalData.userInfo)
  45. if (app.globalData.userInfo.get_novice_award === 1) {
  46. // 是否领取了新手奖励 1否 2是
  47. if (app.globalData.auth.red === 2) {
  48. wx.hideTabBar({
  49. animation: true
  50. })
  51. api.getMpRedInfo().then(res => {
  52. this.setData({
  53. redIcon: res.data.icon || '/image/logo.png',
  54. redName: res.data.name || app.globalData.mpName
  55. })
  56. })
  57. setTimeout(() => {
  58. this.setAnimation().then(() => {
  59. this.setData({
  60. redAnimation: true
  61. })
  62. })
  63. }, 350)
  64. } else {
  65. this.setData({
  66. authEnter: true
  67. })
  68. }
  69. }
  70. },
  71. // 设置红包动画
  72. setAnimation: function (e) {
  73. const _self = this
  74. return new Promise((resolve, reject) => {
  75. _self.setData({
  76. ShowRedPackMask: true
  77. })
  78. resolve()
  79. })
  80. },
  81. getShareInfo: function () {
  82. api.getShareInfo({
  83. data: {
  84. path: this.data.sharePath
  85. }
  86. }).then(res => {
  87. this.setData({
  88. shareInfo: res.data
  89. })
  90. }).catch(err => {
  91. console.log('getShare', err)
  92. })
  93. },
  94. // 获取他人主页信息
  95. getBoxInfo: function (id, state) {
  96. let params = {
  97. to_mem_id: id || '',
  98. state: state || ''
  99. }
  100. api.getHomeInfo(params).then(res => {
  101. this.setData({
  102. boxInfo: res.data
  103. })
  104. })
  105. },
  106. ChangeShare: function (e) {
  107. this.setData({
  108. ShowShareMask: e.currentTarget.dataset.show ? true : false
  109. })
  110. },
  111. routeHome: function (e) {
  112. wx.switchTab({
  113. url: '/pages/game/game'
  114. })
  115. },
  116. getMemGameList: function (id, state) {
  117. let params = {
  118. to_mem_id: id || '',
  119. state: state || '',
  120. page: 1,
  121. offset: 3
  122. }
  123. api.getMemGameList(params).then(res => {
  124. if (res.data && res.data.list.length) {
  125. this.setData({
  126. memGame: res.data,
  127. gameCount: res.data.count,
  128. floats: res.data.list.map((item) => {
  129. return this.data.mpType === 'gd' ? item.mem_integral : (item.mem_reward).toFixed(2)
  130. })
  131. })
  132. } else {
  133. this.getGameList(id,state)
  134. }
  135. })
  136. },
  137. getGameList: function (id, state) {
  138. let params = {
  139. to_mem_id: id || '',
  140. state: state || '',
  141. page: 1,
  142. offset: 999
  143. }
  144. api.getGameList(params).then(res => {
  145. this.setData({
  146. gameData: res.data.list,
  147. gameCount: res.data.count,
  148. floats: res.data.list.map((item) => {
  149. return this.data.mpType === 'gd' ? item.mem_integral : (item.mem_reward).toFixed(2)
  150. })
  151. })
  152. })
  153. },
  154. openGame: function (e) {
  155. let id = e.currentTarget.dataset.id
  156. api.openGame({
  157. game_id: id
  158. }).then(res => {
  159. console.log(res)
  160. }, err => {
  161. console.log(err)
  162. })
  163. },
  164. onShow: function () {
  165. wx.showShareMenu({ // 允许转发时携带 shareTicket。
  166. withShareTicket: true
  167. })
  168. },
  169. onShareAppMessage: function (e) {
  170. this.getShareInfo()
  171. let { title, image, state } = this.data.shareInfo
  172. let memid = this.data.userInfo.mem_id
  173. if (e.target && e.target.id === 'help') {
  174. state = this.data.helpShareState
  175. memid = this.data.helpShareId
  176. }
  177. let path = `/pages/share/share?state=${state}&mem_id=${memid}`
  178. title = title || this.data.userInfo.nickname
  179. return {
  180. title,
  181. path,
  182. imageUrl: image
  183. }
  184. },
  185. // 获取用户信息
  186. getUserInfoFun: function () {
  187. var _self = this;
  188. wx.getUserInfo({
  189. success: function (res) {
  190. console.log(res)
  191. api.updateUserInfo({
  192. raw_data: res.rawData,
  193. signature: res.signature,
  194. encrypted_data: res.encryptedData,
  195. iv: res.iv
  196. }).then(res => {
  197. if (res.code === 200) {
  198. _self.setData({
  199. redPackAward: (res.data.novice_award * 1).toFixed(2),
  200. getSuccess: true
  201. })
  202. // 更新余额
  203. api.getUserInfo()
  204. setTimeout(() => {
  205. _self.setData({
  206. userInfo: getApp().globalData.userInfo
  207. })
  208. }, 500)
  209. } else {
  210. wx.showToast({
  211. title: res.msg,
  212. })
  213. }
  214. })
  215. _self.setData({
  216. authEnter: false
  217. })
  218. },
  219. fail: function (err) {
  220. console.log(err)
  221. }
  222. })
  223. },
  224. // 关闭红包弹框
  225. CloseRedPack: function (e) {
  226. const _self = this
  227. _self.setData({
  228. redAnimation: false
  229. })
  230. setTimeout(() => {
  231. _self.setData({
  232. ShowRedPackMask: false
  233. })
  234. wx.showTabBar({
  235. animation: true
  236. })
  237. }, 300)
  238. }
  239. })