list.js 2.7 KB

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