list.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // pages/list/list.js
  2. const app = getApp();
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. total:0,
  10. page:1,
  11. group:{},
  12. list:[]
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. // options.id=29
  19. this.setData({
  20. id: options.id
  21. })
  22. wx.showNavigationBarLoading()
  23. /**获取token */
  24. wx.getStorage({
  25. key: 'userInfo',
  26. success: res => {
  27. this.setData({
  28. userInfo: res.data
  29. })
  30. this.getData();
  31. },
  32. fail: error => {
  33. //跳转到登陆页面
  34. wx.switchTab({
  35. url: '../user/user',
  36. })
  37. }
  38. })
  39. },
  40. next: function () {
  41. if (this.data.list.length < this.data.total) {
  42. const page = this.data.page + 1
  43. this.setData({
  44. page: page
  45. })
  46. this.getData()
  47. }
  48. },
  49. getData() {
  50. const list = this.data.list;
  51. wx.request({
  52. url: host + '/api/wx/group/rank',
  53. data: {
  54. id: this.data.id ,
  55. page: this.data.page,
  56. page_size:20
  57. },
  58. header: {
  59. 'Authorization': this.data.userInfo.token
  60. },
  61. success: res => {
  62. const players = res.data.data.players;
  63. for (let i = 0; i < players.length; i++) {
  64. list.push(players[i])
  65. }
  66. this.setData({
  67. group: res.data.data.group,
  68. list:list,
  69. total: res.data.data.total
  70. })
  71. wx.setNavigationBarTitle({
  72. title: res.data.data.group.name,
  73. })
  74. wx.hideNavigationBarLoading()
  75. },
  76. fail: error => {
  77. //跳转到登陆页面
  78. wx.switchTab({
  79. url: '../user/user',
  80. })
  81. }
  82. })
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })