index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // pages/promoter_rank/index.js
  2. import { getRankList } from '../../api/user.js'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. parameter: {
  10. navbar: '1',
  11. return: '1',
  12. title: '推广人排行',
  13. color: true,
  14. class: '0'
  15. },
  16. navList: ['周榜', '月榜'],
  17. active: 0,
  18. page: 1,
  19. limit: 15,
  20. type: 'week',
  21. loading: false,
  22. loadend: false,
  23. loadTitle: '加载更多',
  24. rankList: [],
  25. Two: {},
  26. One: {},
  27. Three: {}
  28. },
  29. onLoadFun: function (e) {
  30. this.getRanklist()
  31. },
  32. getRanklist: function () {
  33. let that = this
  34. if (that.data.loadend) return
  35. if (that.data.loading) return
  36. that.setData({
  37. loading: true,
  38. loadTitle: ''
  39. })
  40. getRankList({
  41. page: this.data.page,
  42. limit: this.data.limit,
  43. type: this.data.type
  44. })
  45. .then(res => {
  46. let list = res.data
  47. that.data.rankList = that.data.rankList.concat(list)
  48. if (that.data.page == 1) {
  49. that.data.One = that.data.rankList.shift() || {}
  50. that.data.Two = that.data.rankList.shift() || {}
  51. that.data.Three = that.data.rankList.shift() || {}
  52. }
  53. let loadend = list.length < that.data.limit
  54. that.setData({
  55. loadend: loadend,
  56. loading: false,
  57. rankList: that.data.rankList,
  58. page: that.data.page + 1,
  59. loadTitle: loadend ? '我也是有底线的' : '加载更多',
  60. One: that.data.One,
  61. Two: that.data.Two,
  62. Three: that.data.Three
  63. })
  64. })
  65. .catch(err => {
  66. that.setData({
  67. loading: false,
  68. loadTitle: '加载更多'
  69. })
  70. })
  71. },
  72. switchTap: function (e) {
  73. var index = e.currentTarget.dataset.index
  74. if (this.data.active === index) return
  75. this.setData({
  76. active: index,
  77. type: index ? 'month' : 'week',
  78. page: 1,
  79. loadend: false,
  80. rankList: [],
  81. Two: {},
  82. One: {},
  83. Three: {}
  84. })
  85. this.getRanklist()
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {},
  91. /**
  92. * 生命周期函数--监听页面初次渲染完成
  93. */
  94. onReady: function () {},
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. if (this.data.isClone && app.globalData.isLog) {
  100. this.setData({
  101. loadend: false,
  102. page: 1,
  103. rankList: []
  104. })
  105. this.getRanklist()
  106. }
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. this.setData({
  113. isClone: true
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload: function () {},
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {},
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. this.getRanklist()
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {}
  134. })