index.js 3.0 KB

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