index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/commission_rank/index.js
  2. import {
  3. getBrokerageRank
  4. } from '../../api/user.js';
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. parameter: {
  12. 'navbar': '1',
  13. 'return': '1',
  14. 'title': '盈利排行',
  15. 'color': true,
  16. 'class': '0'
  17. },
  18. navList: ["周排行", "月排行"],
  19. active: 0,
  20. rankList: [],
  21. page: 1,
  22. limit: 10,
  23. loadend: false,
  24. loading: false,
  25. loadTitle: '加载更多',
  26. type: 'week',
  27. position: 0,
  28. },
  29. switchTap: function (e) {
  30. let index = e.currentTarget.dataset.index
  31. this.setData({
  32. active: index,
  33. type: index ? 'month' : 'week',
  34. page: 1,
  35. loadend: false,
  36. rankList: [],
  37. });
  38. this.getBrokerageRankList();
  39. },
  40. onLoadFun: function () {
  41. this.getBrokerageRankList();
  42. },
  43. getBrokerageRankList: function () {
  44. if (this.data.loadend) return;
  45. if (this.data.loading) return;
  46. this.setData({
  47. loading: true,
  48. loadTitle: ''
  49. });
  50. getBrokerageRank({
  51. page: this.data.page,
  52. limit: this.data.limit,
  53. type: this.data.type
  54. }).then(res => {
  55. let list = res.data.rank;
  56. let loadend = list.length < this.data.limit;
  57. this.data.rankList.push.apply(this.data.rankList, list);
  58. this.setData({
  59. loading: false,
  60. loadend: loadend,
  61. loadTitle: loadend ? '😕我也是有底线的' : '加载更多',
  62. rankList: this.data.rankList,
  63. position: res.data.position
  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. */
  80. onReady: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function () {
  86. if (this.data.isClone && app.globalData.isLog) {
  87. this.setData({
  88. page: 1,
  89. loadend: false,
  90. rankList: {}
  91. });
  92. this.getBrokerageRankList();
  93. }
  94. },
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. this.setData({
  100. isClone: true
  101. });
  102. },
  103. /**
  104. * 生命周期函数--监听页面卸载
  105. */
  106. onUnload: function () {
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function () {
  112. },
  113. /**
  114. * 页面上拉触底事件的处理函数
  115. */
  116. onReachBottom: function () {
  117. this.getBrokerageRankList();
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. }
  124. })