index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/promoter_rank/index.js
  2. import {
  3. getRankList
  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. page: 1,
  21. limit: 15,
  22. type: 'week',
  23. loading: false,
  24. loadend: false,
  25. loadTitle: "加载更多",
  26. rankList: [],
  27. Two: {},
  28. One: {},
  29. Three: {},
  30. },
  31. onLoadFun: function (e) {
  32. this.getRanklist();
  33. },
  34. getRanklist: function () {
  35. let that = this;
  36. if (that.data.loadend) return;
  37. if (that.data.loading) return;
  38. that.setData({
  39. loading: true,
  40. loadTitle: ""
  41. });
  42. getRankList({
  43. page: this.data.page,
  44. limit: this.data.limit,
  45. type: this.data.type
  46. }).then(res => {
  47. let list = res.data;
  48. that.data.rankList = that.data.rankList.concat(list);
  49. if (that.data.page == 1) {
  50. that.data.One = that.data.rankList.shift() || {};
  51. that.data.Two = that.data.rankList.shift() || {};
  52. that.data.Three = that.data.rankList.shift() || {};
  53. }
  54. let loadend = list.length < that.data.limit;
  55. that.setData({
  56. loadend: loadend,
  57. loading: false,
  58. rankList: that.data.rankList,
  59. page: that.data.page + 1,
  60. loadTitle: loadend ? "我也是有底线的" : '加载更多',
  61. One: that.data.One,
  62. Two: that.data.Two,
  63. Three: that.data.Three,
  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. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. if (this.data.isClone && app.globalData.isLog) {
  102. this.setData({
  103. loadend: false,
  104. page: 1,
  105. rankList: []
  106. });
  107. this.getRanklist();
  108. }
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. this.setData({
  115. isClone: true
  116. });
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. this.getRanklist();
  133. },
  134. /**
  135. * 用户点击右上角分享
  136. */
  137. onShareAppMessage: function () {
  138. }
  139. })