index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // pages/commission_rank/index.js
  2. import { getBrokerageRank } 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. rankList: [],
  19. page: 1,
  20. limit: 10,
  21. loadend: false,
  22. loading: false,
  23. loadTitle: '加载更多',
  24. type: 'week',
  25. position: 0
  26. },
  27. switchTap: function (e) {
  28. let index = e.currentTarget.dataset.index
  29. this.setData({
  30. active: index,
  31. type: index ? 'month' : 'week',
  32. page: 1,
  33. loadend: false,
  34. rankList: []
  35. })
  36. this.getBrokerageRankList()
  37. },
  38. onLoadFun: function () {
  39. this.getBrokerageRankList()
  40. },
  41. getBrokerageRankList: function () {
  42. if (this.data.loadend) return
  43. if (this.data.loading) return
  44. this.setData({
  45. loading: true,
  46. loadTitle: ''
  47. })
  48. getBrokerageRank({
  49. page: this.data.page,
  50. limit: this.data.limit,
  51. type: this.data.type
  52. })
  53. .then(res => {
  54. let list = res.data.rank
  55. let loadend = list.length < this.data.limit
  56. this.data.rankList.push.apply(this.data.rankList, list)
  57. this.setData({
  58. loading: false,
  59. loadend: loadend,
  60. loadTitle: loadend ? '😕我也是有底线的' : '加载更多',
  61. rankList: this.data.rankList,
  62. position: res.data.position
  63. })
  64. })
  65. .catch(err => {
  66. this.setData({
  67. loading: false,
  68. loadTitle: '加载更多'
  69. })
  70. })
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {},
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () {},
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. if (this.data.isClone && app.globalData.isLog) {
  85. this.setData({
  86. page: 1,
  87. loadend: false,
  88. rankList: {}
  89. })
  90. this.getBrokerageRankList()
  91. }
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide: function () {
  97. this.setData({
  98. isClone: true
  99. })
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {},
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {},
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. this.getBrokerageRankList()
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function () {}
  119. })