index.js 2.6 KB

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