my-users.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // pages/my-users/my-users.js
  2. var http = require("../../utils/http.js")
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. totalInvite: 0,
  9. records: [],
  10. loadingMsg: "正在加载..",
  11. emptyMsg: "",
  12. totalPage: 1,
  13. pageNum: 1,
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function(options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function() {
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function() {
  29. this.loadPageData(1)
  30. },
  31. /**
  32. * 生命周期函数--监听页面隐藏
  33. */
  34. onHide: function() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面卸载
  38. */
  39. onUnload: function() {
  40. },
  41. /**
  42. * 页面相关事件处理函数--监听用户下拉动作
  43. */
  44. onPullDownRefresh: function() {
  45. },
  46. /**
  47. * 页面上拉触底事件的处理函数
  48. */
  49. onReachBottom: function() {
  50. if (this.data.pageNum < this.data.totalPage) {
  51. this.loadPageData(this.data.pageNum + 1);
  52. }
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function() {
  58. },
  59. /**
  60. * 加载用户数据
  61. */
  62. loadPageData: function (pageNum) {
  63. var ths = this;
  64. wx.showLoading();
  65. var params = {
  66. url: "/p/distribution/bindUserList",
  67. method: "GET",
  68. data: {
  69. // shopId: 1,
  70. current: pageNum,
  71. size: 20
  72. },
  73. callBack: (res)=> {
  74. wx.hideLoading();
  75. var records = [];
  76. if (res.current == 1) {
  77. records = res.records;
  78. } else {
  79. records = this.data.records;
  80. Array.prototype.push.apply(records, res.records);
  81. }
  82. var loadingMsg = this.data.loadingMsg;
  83. if (pageNum == res.pages) {
  84. loadingMsg = "没有更多了~";
  85. }
  86. ths.setData({
  87. records: records,
  88. totalPage: res.pages,
  89. pageNum: pageNum,
  90. loadingMsg: loadingMsg,
  91. emptyMsg: "还没有用户哦~",
  92. totalInvite:res.total
  93. });
  94. }
  95. };
  96. http.request(params);
  97. }
  98. })