index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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({loading:true,loadTitle:''});
  45. getBrokerageRank({
  46. page:this.data.page,
  47. limit:this.data.limit,
  48. type:this.data.type
  49. }).then(res=>{
  50. let list = res.data.rank;
  51. let loadend = list.length < this.data.limit;
  52. this.data.rankList.push.apply(this.data.rankList, list);
  53. this.setData({
  54. loading:false,
  55. loadend: loadend,
  56. loadTitle: loadend ? '😕我也是有底线的':'加载更多',
  57. rankList: this.data.rankList,
  58. position: res.data.position
  59. });
  60. }).catch(err=>{
  61. this.setData({loading:false,loadTitle:'加载更多'});
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad: function (options) {
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. if (this.data.isClone && app.globalData.isLog){
  79. this.setData({ page: 1, loadend: false, rankList:{}});
  80. this.getBrokerageRankList();
  81. }
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. this.setData({isClone:true});
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh: function () {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. this.getBrokerageRankList();
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. }
  110. })