gamelist.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // components/gamelist/gamelist.js
  2. const api = require('../../utils/api.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp()
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. btnType: { // 按钮类型 1: 打开 2:推广
  11. type: String
  12. },
  13. params: {
  14. type: Object,
  15. value: {},
  16. observer: function (newVal, oldVal) {
  17. if (newVal.listype == 1) {
  18. // 1: 游戏列表 2: 推广游戏列表
  19. if (this.data.gameCount <= this.data.gameData.length) {
  20. return false
  21. }
  22. api.getGameList({ page: newVal.page, offset: newVal.offset, rank_type: newVal.rank_type }).then(res => {
  23. this.setData({
  24. gameData: newVal.page > 1 ? this.data.gameData.concat(res.data.list) : res.data.list,
  25. gameCount: res.data.count,
  26. floats: this.data.floats.concat(res.data.list.map((item) => {
  27. return this.data.mpType === 'gd' ? item.mem_agent_integral : (item.mem_agent_reward || 0).toFixed(2)
  28. }))
  29. })
  30. })
  31. } else if (newVal.listype == 2) {
  32. api.getMemGameList({page: newVal.page, offset: newVal.offset}).then(res => {
  33. this.setData({
  34. gameData: newVal.page > 1 ? this.data.gameData.concat(res.data.list) : res.data.list,
  35. gameCount: res.data.count,
  36. floats: this.data.floats.concat(res.data.list.map((item) => {
  37. return this.data.mpType === 'gd' ? item.mem_agent_integral : (item.mem_agent_reward || 0).toFixed(2)
  38. }))
  39. })
  40. })
  41. }
  42. }
  43. }
  44. },
  45. /**
  46. * 组件的初始数据
  47. */
  48. data: {
  49. floats: [],
  50. gameCount: 10,
  51. gameData: [],
  52. mpType: app.globalData.mpType
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. routeDetail: function (e) {
  59. util.routeTo(`/pages/detail/detail?id=${e.currentTarget.dataset.id}`)
  60. },
  61. openGame: function (e) {
  62. let id = e.currentTarget.dataset.id
  63. api.openGame({
  64. game_id: id
  65. }).then(res => {
  66. console.log(res)
  67. }, err => {
  68. console.log(err)
  69. })
  70. }
  71. }
  72. })