all.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const api = require('../../utils/api')
  2. const util = require('../../utils/util')
  3. const app = getApp()
  4. Page({
  5. // 页面的初始数据
  6. data: {
  7. auth: {},
  8. params: {
  9. type_id: 0,
  10. page: 1,
  11. offset: 10
  12. },
  13. result: {
  14. list: []
  15. },
  16. mpType: app.globalData.mpType
  17. },
  18. // 生命周期函数--监听页面加载
  19. onLoad: function (opt) {
  20. let timer = setInterval(() => {
  21. if (app.globalData.PageCallback) {
  22. clearInterval(timer)
  23. this.setData({
  24. auth: app.globalData.auth
  25. })
  26. }
  27. }, 60)
  28. let { params } = this.data
  29. params.type_id = opt.type
  30. this.setData({
  31. params
  32. })
  33. wx.setNavigationBarTitle({
  34. title: opt.title || '更多'
  35. })
  36. this.getList()
  37. },
  38. routeDetail: function (e) {
  39. // util.routeTo(`/pages/detail/detail?id=${e.currentTarget.dataset.id}`)
  40. },
  41. // 页面相关事件处理函数--监听用户下拉动作
  42. onPullDownRefresh: function () {
  43. let { result, params } = this.data
  44. // 重置数据和参数
  45. result = {
  46. list: []
  47. }
  48. params.page = 1
  49. this.setData({
  50. result,
  51. params
  52. })
  53. // 请求新数据
  54. this.getList(true)
  55. wx.stopPullDownRefresh()
  56. },
  57. // 页面上拉触底事件的处理函数
  58. onReachBottom: function () {
  59. this.getList()
  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. getList: function (hdld) {
  72. let { params, result } = this.data
  73. if (result.count <= (params.page - 1) * params.offset) {
  74. return false
  75. }
  76. api.getTagGameList(hdld ? { ...params, HideLoading: true} : params).then(res => {
  77. params.page++
  78. res.data.list = [
  79. ...result.list,
  80. ...res.data.list
  81. ]
  82. result = res.data
  83. this.setData({
  84. params,
  85. result
  86. })
  87. }, err => {
  88. console.log(err)
  89. })
  90. }
  91. })