team.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. isLoading: true,
  8. dataType: 1,
  9. page: 1,
  10. no_more: false,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. },
  17. /**
  18. * 生命周期函数--监听页面显示
  19. */
  20. onShow: function() {
  21. // 获取我的团队列表
  22. this.getTeamList();
  23. },
  24. /**
  25. * 获取我的团队列表
  26. */
  27. getTeamList: function(isNextPage, page) {
  28. let _this = this;
  29. App._get('user.dealer.team/lists', {
  30. level: _this.data.dataType,
  31. page: page || 1,
  32. }, function(result) {
  33. // 创建页面数据
  34. _this.setData(_this.createData(result.data, isNextPage));
  35. });
  36. },
  37. /**
  38. * 创建页面数据
  39. */
  40. createData: function(data, isNextPage) {
  41. data['isLoading'] = false;
  42. // 列表数据
  43. let dataList = this.data.list;
  44. if (isNextPage == true && (typeof dataList !== 'undefined')) {
  45. data.list.data = dataList.data.concat(data.list.data)
  46. }
  47. // 设置当前页面标题
  48. wx.setNavigationBarTitle({
  49. title: data.words.team.title.value
  50. });
  51. // 团队总人数
  52. data['team_total'] = data.dealer.first_num;
  53. // 导航栏数据
  54. data['tabList'] = [{
  55. value: 1,
  56. text: data.words.team.words.first.value,
  57. total: data.dealer.first_num
  58. }];
  59. if (data.setting.level >= 2) {
  60. data['tabList'].push({
  61. value: 2,
  62. text: data.words.team.words.second.value,
  63. total: data.dealer.second_num
  64. });
  65. data['team_total'] += data.dealer.second_num;
  66. }
  67. if (data.setting.level == 3) {
  68. data['tabList'].push({
  69. value: 3,
  70. text: data.words.team.words.third.value,
  71. total: data.dealer.third_num
  72. });
  73. data['team_total'] += data.dealer.third_num;
  74. }
  75. // 设置swiper的高度
  76. this.setSwiperHeight(data.setting.level > 1);
  77. return data;
  78. },
  79. /**
  80. * 下拉到底加载数据
  81. */
  82. triggerDownLoad: function() {
  83. // console.log(this.data.list);
  84. // 已经是最后一页
  85. if (this.data.page >= this.data.list.last_page) {
  86. this.setData({
  87. no_more: true
  88. });
  89. return false;
  90. }
  91. this.getTeamList(true, ++this.data.page);
  92. },
  93. /**
  94. * 设置swiper的高度
  95. */
  96. setSwiperHeight: function(isTap) {
  97. // 获取系统信息(拿到屏幕宽度)
  98. let systemInfo = wx.getSystemInfoSync(),
  99. rpx = systemInfo.windowWidth / 750, // 计算rpx
  100. tapHeight = isTap ? Math.floor(rpx * 82) : 0, // tap高度
  101. peopleHeight = Math.floor(rpx * 65), // people高度
  102. swiperHeight = systemInfo.windowHeight - tapHeight - peopleHeight; // swiper高度
  103. this.setData({
  104. swiperHeight
  105. });
  106. },
  107. /**
  108. * 点击tab切换
  109. */
  110. swichNav: function(e) {
  111. let _this = this;
  112. _this.setData({
  113. dataType: e.target.dataset.current,
  114. list: {},
  115. page: 1,
  116. no_more: false,
  117. isLoading: true,
  118. }, function() {
  119. // 获取我的团队列表
  120. _this.getTeamList();
  121. });
  122. },
  123. })