manage.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // pages/manage/manage.js
  2. const api = require('../../utils/api.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabIndex: 1,
  11. is_Change: false,
  12. hotParams: {
  13. page: 1,
  14. offset: 10,
  15. rank_type: 2
  16. },
  17. hotGameCount: 99,
  18. hotGames: [],
  19. hotFloats: [],
  20. goldParams: {
  21. page: 1,
  22. offset: 10,
  23. rank_type: 4
  24. },
  25. goldGameCount: 99,
  26. goldGames: [],
  27. goldFloats: [],
  28. playParams: {
  29. page: 1,
  30. offset: 10
  31. },
  32. playGameCount: 99,
  33. playGames: [],
  34. playFloats: [],
  35. auth: {},
  36. mpType: app.globalData.mpType
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. this.setData({
  43. auth: app.globalData.auth
  44. })
  45. if (this.data.auth.gain === 2) {
  46. this.getGoldGames()
  47. } else {
  48. this.setData({
  49. tabIndex: 2
  50. })
  51. }
  52. this.getHotGames()
  53. this.getPlayGames()
  54. },
  55. routeDetail: function (e) {
  56. // util.routeTo(`/pages/detail/detail?id=${e.currentTarget.dataset.id}`)
  57. },
  58. ChangeGame: function (e) {
  59. const _self = this
  60. let index = e.currentTarget.dataset.index
  61. if (e.currentTarget.dataset.clicktype === 'add') {
  62. api.addMemGame({ game_id: e.currentTarget.dataset.id }).then(res => {
  63. _self.statusChange(2, res, index)
  64. })
  65. } else if (e.currentTarget.dataset.clicktype === 'cancel') {
  66. api.delMemGame({ game_id: e.currentTarget.dataset.id }).then(res => {
  67. _self.statusChange(1, res, index)
  68. })
  69. }
  70. },
  71. statusChange: function (status, data, itemIndex) {
  72. const _self = this
  73. if (data.code === 200) {
  74. if (this.data.tabIndex === 0) {
  75. this.setData({
  76. playParams: {
  77. page: 1,
  78. offset: 10
  79. },
  80. is_Change: false
  81. })
  82. this.getPlayGames()
  83. }
  84. wx.showToast({
  85. title: data.msg,
  86. icon: 'success',
  87. duration: 500,
  88. success: function () {
  89. setTimeout(() => {
  90. let _id = '';
  91. if (_self.data.tabIndex === 1) {
  92. _id = _self.data.goldGames[itemIndex].game_id
  93. } else if (_self.data.tabIndex === 2) {
  94. _id = _self.data.hotGames[itemIndex].game_id
  95. } else {
  96. _id = _self.data.playGames[itemIndex].game_id
  97. }
  98. // 佣金
  99. _self.data.goldGames.forEach((item, ids) => {
  100. if (item.game_id === _id) {
  101. _self.data.goldGames[ids].is_add = status
  102. }
  103. })
  104. // 热度
  105. _self.data.hotGames.forEach((item, ids) => {
  106. if (item.game_id === _id) {
  107. _self.data.hotGames[ids].is_add = status
  108. }
  109. })
  110. // 玩过
  111. _self.data.playGames.forEach((item, ids) => {
  112. if (item.game_id === _id) {
  113. _self.data.playGames[ids].is_add = status
  114. }
  115. })
  116. _self.setData({
  117. goldGames: _self.data.goldGames,
  118. hotGames: _self.data.hotGames,
  119. playGames: _self.data.playGames,
  120. is_Change: true
  121. })
  122. }, 500)
  123. }
  124. })
  125. } else {
  126. wx.showToast({
  127. title: '请稍后再试',
  128. icon: 'none'
  129. })
  130. }
  131. },
  132. getHotGames: function (hdld) {
  133. api.getGameList(hdld ? { ...this.data.hotParams, HideLoading: true } : this.data.hotParams).then(res => {
  134. this.setData({
  135. hotGames: this.data.hotGames.concat(res.data.list),
  136. hotGameCount: res.data.count,
  137. hotFloats: this.data.hotFloats.concat(res.data.list.map((item) => {
  138. return this.data.mpType === 'gd' ? item.mem_agent_integral : item.mem_agent_reward.toFixed(2)
  139. }))
  140. })
  141. })
  142. },
  143. getGoldGames: function (hdld) {
  144. api.getGameList(hdld ? { ...this.data.goldParams, HideLoading: true } : this.data.goldParams).then(res => {
  145. this.setData({
  146. goldGames: this.data.goldGames.concat(res.data.list),
  147. goldGameCount: res.data.count,
  148. goldFloats: this.data.goldFloats.concat(res.data.list.map((item) => {
  149. return this.data.mpType === 'gd' ? item.mem_agent_integral : item.mem_agent_reward.toFixed(2)
  150. }))
  151. })
  152. })
  153. },
  154. getPlayGames: function (hdld) {
  155. api.getGamePlayList(hdld ? { ...this.data.playParams, HideLoading: true } : this.data.playParams).then(res => {
  156. this.setData({
  157. playGames: this.data.playParams.page === 1 ? res.data.list : this.data.playGames.concat(res.data.list),
  158. playGameCount: res.data.count,
  159. playFloats: this.data.playParams.page === 1 ? res.data.list.map((item) => {
  160. return this.data.mpType === 'gd' ? item.mem_agent_integral : (item.mem_agent_reward || 0).toFixed(2)
  161. }) : this.data.playFloats.concat(res.data.list.map((item) => {
  162. return this.data.mpType === 'gd' ? item.mem_agent_integral : (item.mem_agent_reward || 0).toFixed(2)
  163. }))
  164. })
  165. })
  166. },
  167. tabChange: function (e) {
  168. let Index = e.target.dataset.index * 1
  169. if (Index === 0 && this.data.is_Change) {
  170. this.setData({
  171. playParams: {
  172. page: 1,
  173. offset: 10
  174. },
  175. is_Change: false
  176. })
  177. this.getPlayGames()
  178. }
  179. this.setData({
  180. tabIndex: e.target.dataset.index * 1
  181. })
  182. },
  183. /**
  184. * 生命周期函数--监听页面卸载
  185. */
  186. onUnload: function () {
  187. var pages = getCurrentPages();
  188. if (pages.length > 1) {
  189. var prePage = pages[pages.length - 2];
  190. prePage.getBoxGameList && prePage.getBoxGameList()
  191. }
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function () {
  197. console.log(this.data.tabIndex)
  198. if (this.data.tabIndex === 1) {
  199. if (this.data.goldGameCount <= this.data.goldGames.length) {
  200. return false
  201. }
  202. // 佣金
  203. this.setData({
  204. goldParams: {
  205. page: ++this.data.goldParams.page,
  206. offset: 10,
  207. rank_type: 4
  208. }
  209. })
  210. this.getGoldGames()
  211. } else if (this.data.tabIndex === 2) {
  212. if (this.data.hotGameCount <= this.data.hotGames.length) {
  213. return false
  214. }
  215. // 热度
  216. this.setData({
  217. hotParams: {
  218. page: ++this.data.hotParams.page,
  219. offset: 10,
  220. rank_type: 2
  221. }
  222. })
  223. this.getHotGames()
  224. } else {
  225. if (this.data.playGameCount <= this.data.playGames.length) {
  226. return false
  227. }
  228. // 最近
  229. this.setData({
  230. playParams: {
  231. page: ++this.data.playParams.page,
  232. offset: 10
  233. }
  234. })
  235. this.getPlayGames()
  236. }
  237. },
  238. // 页面相关事件处理函数--监听用户下拉动作
  239. onPullDownRefresh: function () {
  240. switch (this.data.tabIndex) {
  241. case 0:
  242. this.getPlayGames(true)
  243. break;
  244. case 1:
  245. this.getGoldGames(true)
  246. break;
  247. case 2:
  248. this.getHotGames(true)
  249. break;
  250. }
  251. wx.stopPullDownRefresh()
  252. },
  253. openGame: function (e) {
  254. let id = e.currentTarget.dataset.id
  255. api.openGame({
  256. game_id: id
  257. }).then(res => {
  258. console.log(res)
  259. }, err => {
  260. console.log(err)
  261. })
  262. }
  263. })