index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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({ loading: true, loadTitle: ""});
  37. getRankList({
  38. page:this.data.page,
  39. limit:this.data.limit,
  40. type: this.data.type
  41. }).then(res=>{
  42. let list = res.data;
  43. that.data.rankList = that.data.rankList.concat(list);
  44. if(that.data.page == 1){
  45. that.data.One=that.data.rankList.shift() || {};
  46. that.data.Two = that.data.rankList.shift() || {};
  47. that.data.Three = that.data.rankList.shift() || {};
  48. }
  49. let loadend = list.length < that.data.limit;
  50. that.setData({
  51. loadend: loadend,
  52. loading:false,
  53. rankList: that.data.rankList,
  54. page: that.data.page+1,
  55. loadTitle: loadend ? "我也是有底线的" : '加载更多',
  56. One: that.data.One,
  57. Two: that.data.Two,
  58. Three: that.data.Three,
  59. });
  60. }).catch(err=>{
  61. that.setData({ loading: false, loadTitle: "加载更多"});
  62. })
  63. },
  64. switchTap:function(e){
  65. var index = e.currentTarget.dataset.index;
  66. if (this.data.active === index) return;
  67. this.setData({
  68. active:index,
  69. type: index ? 'month': 'week',
  70. page:1,
  71. loadend:false,
  72. rankList:[],
  73. Two:{},
  74. One:{},
  75. Three:{}
  76. });
  77. this.getRanklist();
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. if(this.data.isClone && app.globalData.isLog){
  94. this.setData({ loadend: false, page: 1, rankList:[]});
  95. this.getRanklist();
  96. }
  97. },
  98. /**
  99. * 生命周期函数--监听页面隐藏
  100. */
  101. onHide: function () {
  102. this.setData({isClone:true});
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. this.getRanklist();
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage: function () {
  124. }
  125. })