task.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // pages/find/find.js
  2. import api from '../../utils/api.js'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. params: {
  10. page: 1,
  11. offset: 10
  12. },
  13. Rplist: [],
  14. RpCount: 0,
  15. mpType: app.globalData.mpType
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function(options) {
  21. },
  22. onShow: function() {
  23. let timer = setInterval(() => {
  24. if (app.globalData.PageCallback) {
  25. this.getRpGameList()
  26. clearInterval(timer)
  27. }
  28. }, 200)
  29. },
  30. getPrize: function(e) {
  31. api.getGameIncome().then(res => {
  32. if (res.code === 200) {
  33. wx.showModal({
  34. title: '试玩奖励',
  35. content: `恭喜获得${res.data.gain_integral}积分!`,
  36. showCancel: false,
  37. success: (e) => {
  38. this.data.Rplist.list[e.currentTarget.dataset.index].status = 3
  39. }
  40. })
  41. }
  42. })
  43. },
  44. getRpGameList(hdld) {
  45. api.getRpGameList(hdld ? { ...this.data.params, HideLoading: true} : this.data.params).then(res => {
  46. this.setData({
  47. Rplist: this.data.params.page > 1 ? this.data.Rplist.concat(res.data.list) : res.data.list,
  48. RpCount: res.data.count
  49. })
  50. })
  51. },
  52. /**
  53. * 页面上拉触底事件的处理函数
  54. */
  55. onReachBottom: function() {
  56. if (this.data.Rplist.length >= this.data.RpCount) {
  57. return false
  58. }
  59. this.data.params.page++
  60. this.setData({
  61. params: this.data.params
  62. })
  63. this.getRpGameList()
  64. },
  65. // 页面相关事件处理函数--监听用户下拉动作
  66. onPullDownRefresh: function () {
  67. this.setData({
  68. params: {
  69. page: 1,
  70. offset: 10
  71. }
  72. })
  73. this.getRpGameList(true)
  74. wx.stopPullDownRefresh()
  75. },
  76. openGame: function (e) {
  77. let id = e.currentTarget.dataset.id
  78. api.openGame({
  79. game_id: id
  80. }).then(res => {
  81. this.getRpGameList(true)
  82. }, err => {
  83. console.log(err)
  84. })
  85. },
  86. showPop: function (e) {
  87. wx.previewImage({
  88. urls: [e.currentTarget.dataset.entrance]
  89. })
  90. }
  91. })