list.js 2.5 KB

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