list.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '羽校信息', leftArrow: true, useBar: false },
  8. user: {},
  9. // 查询
  10. search: {},
  11. list: [],
  12. total: 0,
  13. skip: 0,
  14. limit: 10,
  15. page: 0,
  16. },
  17. // 跳转菜单
  18. back(e) {
  19. wx.navigateBack({ delta: 1 })
  20. },
  21. // 查询
  22. toInput(e) {
  23. const that = this;
  24. let value = e.detail.value;
  25. if (value) that.setData({ 'search.name': value })
  26. else that.setData({ search: {} })
  27. that.clearPage(); that.watchLogin();
  28. },
  29. // 清空列表
  30. clearPage() {
  31. const that = this;
  32. that.setData({ list: [], skip: 0, limit: 10, page: 0 })
  33. },
  34. // 详细信息
  35. toView: function (e) {
  36. const that = this;
  37. const { item } = e.currentTarget.dataset;
  38. that.clearPage()
  39. wx.navigateTo({
  40. url: `/pagesSchool/school/info?id=${item.school_id}`,
  41. })
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. },
  48. /**
  49. * 生命周期函数--监听页面初次渲染完成
  50. */
  51. onReady: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: async function () {
  57. const that = this;
  58. // 监听用户是否登录
  59. await that.watchLogin();
  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. that.search()
  68. },
  69. fail: async res => {
  70. wx.redirectTo({ url: '/pages/index/index' })
  71. }
  72. })
  73. },
  74. async search() {
  75. const that = this;
  76. let user = that.data.user;
  77. let info = { skip: that.data.skip, limit: that.data.limit, student_id: user.info.id };
  78. let arr = await app.$get(`/rss`, { ...info });
  79. if (arr.errcode == '0') {
  80. let list = [...that.data.list, ...arr.data];
  81. that.setData({ list })
  82. that.setData({ total: arr.total })
  83. } else { wx.showToast({ title: arr.errmsg, icon: 'error' }) }
  84. },
  85. // 分页
  86. toPage: function () {
  87. const that = this;
  88. let list = that.data.list;
  89. let limit = that.data.limit;
  90. if (that.data.total > list.length) {
  91. wx.showLoading({ title: '加载中', mask: true })
  92. let page = that.data.page + 1;
  93. that.setData({ page: page })
  94. let skip = page * limit;
  95. that.setData({ skip: skip })
  96. that.search();
  97. wx.hideLoading()
  98. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  99. },
  100. /**
  101. * 生命周期函数--监听页面隐藏
  102. */
  103. onHide: function () {
  104. const that = this;
  105. that.clearPage();
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. }
  127. })