index.js 2.7 KB

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