list.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '用户管理', leftArrow: true, useBar: false },
  5. list: [],
  6. total: 0,
  7. page: 0,
  8. skip: 0,
  9. limit: 5,
  10. },
  11. back: function () {
  12. wx.navigateBack({ delta: 1 })
  13. },
  14. // 详细信息
  15. toView: function (e) {
  16. const that = this;
  17. that.setData({ skip: 0, page: 0, list: [] })
  18. let { item } = e.currentTarget.dataset;
  19. wx.navigateTo({ url: `/pages/user/info?openid=${item.openid}` })
  20. },
  21. // 分页
  22. toPage: function () {
  23. const that = this;
  24. let list = that.data.list;
  25. let limit = that.data.limit;
  26. if (that.data.total > list.length) {
  27. wx.showLoading({ title: '加载中', mask: true })
  28. let page = that.data.page + 1;
  29. that.setData({ page: page })
  30. let skip = page * limit;
  31. that.setData({ skip: skip })
  32. that.watchLogin();
  33. wx.hideLoading()
  34. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) { },
  40. // 监听用户是否登录
  41. watchLogin: async function () {
  42. const that = this;
  43. // 监听用户是否登录,
  44. wx.getStorage({
  45. key: 'user',
  46. success: async res => {
  47. let info = { skip: that.data.skip, limit: that.data.limit };
  48. let arr;
  49. arr = await app.$get(`/newCourt/api/user`, { ...info });
  50. if (arr.errcode == '0') {
  51. that.setData({ list: [...that.data.list, ...arr.data] })
  52. that.setData({ total: arr.total })
  53. }
  54. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  55. },
  56. fail: async res => {
  57. wx.redirectTo({ url: '/pages/index/index' })
  58. }
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. const that = this;
  71. // 监听用户是否登录
  72. that.watchLogin();
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload: function () {
  83. },
  84. /**
  85. * 页面相关事件处理函数--监听用户下拉动作
  86. */
  87. onPullDownRefresh: function () {
  88. console.log('1');
  89. },
  90. /**
  91. * 页面上拉触底事件的处理函数
  92. */
  93. onReachBottom: function () {
  94. console.log('2');
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {
  100. }
  101. })