members.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. res.data.result.forEach(ele => {
  48. if (!ele.avatarUrls) {
  49. ele.avatarUrls = '/images/face.png'
  50. }
  51. if (!ele.nicks) {
  52. ele.nicks = '用户' + ele.uids
  53. }
  54. const _statisticsCommisionMap = statisticsCommisionMap[ele.uids]
  55. if (_statisticsCommisionMap) {
  56. ele.saleroom = _statisticsCommisionMap.saleroom
  57. }
  58. })
  59. if (this.data.page == 1) {
  60. this.setData({
  61. members: res.data.result
  62. })
  63. } else {
  64. this.setData({
  65. members: this.data.members.concat(res.data.result)
  66. })
  67. }
  68. }
  69. },
  70. tabChange(e) {
  71. this.setData({
  72. activeIndex: e.detail.index,
  73. page: 1
  74. })
  75. this.fxMembers()
  76. },
  77. onReachBottom: function() {
  78. this.data.page += 1
  79. this.fxMembers()
  80. },
  81. onPullDownRefresh: function() {
  82. this.data.page = 1
  83. this.fxMembersStatistics()
  84. this.fxMembers()
  85. wx.stopPullDownRefresh()
  86. },
  87. })