index.js 3.0 KB

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