index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const WXAPI = require('apifm-wxapi')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. number1: 0, // 直推用户数
  8. number2: 0, // 间推用户数
  9. activeIndex: 0, // tab点亮索引
  10. page: 1 // 读取第几页
  11. },
  12. onLoad: function () {
  13. this.fxMembersStatistics()
  14. this.fxMembers()
  15. },
  16. onShow: function () {
  17. },
  18. async fxMembersStatistics() {
  19. const res = await WXAPI.fxMembersStatistics(wx.getStorageSync('token'))
  20. if (res.code == 0) {
  21. this.setData({
  22. number1: res.data.totleFansLevel1,
  23. number2: res.data.totleFansLevel2
  24. })
  25. }
  26. },
  27. async fxMembers() {
  28. const res = await WXAPI.fxMembers({
  29. token: wx.getStorageSync('token'),
  30. page: this.data.page,
  31. level: this.data.activeIndex == 0 ? 1 : 2
  32. })
  33. if (res.code == 700) {
  34. if (this.data.page == 1) {
  35. this.setData({
  36. members: []
  37. })
  38. } else {
  39. wx.showToast({
  40. title: '没有更多了',
  41. icon: 'none'
  42. })
  43. }
  44. }
  45. if (res.code == 0) {
  46. const statisticsCommisionMap = res.data.statisticsCommisionMap
  47. const userCashMap = res.data.userCashMap
  48. res.data.result.forEach(ele => {
  49. if (!ele.avatarUrls) {
  50. ele.avatarUrls = '/images/face.png'
  51. }
  52. if (!ele.nicks) {
  53. ele.nicks = '用户' + ele.uids
  54. }
  55. const _statisticsCommisionMap = statisticsCommisionMap[ele.uids]
  56. if (_statisticsCommisionMap) {
  57. ele.saleroom = _statisticsCommisionMap.saleroom
  58. ele.numberOrder = _statisticsCommisionMap.numberOrder
  59. }
  60. if (userCashMap) {
  61. const _userCashMap = userCashMap[ele.uids]
  62. if (_userCashMap) {
  63. ele.totleConsumed = _userCashMap.totleConsumed
  64. ele.totalPayNumber = _userCashMap.totalPayNumber
  65. ele.totalPayAmount = _userCashMap.totalPayAmount
  66. }
  67. }
  68. })
  69. if (this.data.page == 1) {
  70. this.setData({
  71. members: res.data.result
  72. })
  73. } else {
  74. this.setData({
  75. members: this.data.members.concat(res.data.result)
  76. })
  77. }
  78. }
  79. },
  80. tabChange(e) {
  81. this.setData({
  82. activeIndex: e.detail.index,
  83. page: 1
  84. })
  85. this.fxMembers()
  86. },
  87. onReachBottom: function() {
  88. this.data.page += 1
  89. this.fxMembers()
  90. },
  91. onPullDownRefresh: function() {
  92. this.data.page = 1
  93. this.fxMembersStatistics()
  94. this.fxMembers()
  95. wx.stopPullDownRefresh()
  96. },
  97. })