index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '话题', leftArrow: false, useBar: true },
  5. list: [],
  6. total: 0,
  7. skip: 0,
  8. page: 0,
  9. limit: 5,
  10. },
  11. // 跳转菜单
  12. tabPath(e) {
  13. let { route } = e.detail.detail;
  14. if (route) wx.redirectTo({ url: `/${route}` })
  15. },
  16. //查询
  17. onSearch: function (e) {
  18. const that = this;
  19. that.setData({ skip: 0, page: 0, list: [] })
  20. that.setData({ 'searchInfo.title': e.detail.value });
  21. that.watchLogin()
  22. },
  23. toView: function (e) {
  24. const that = this;
  25. that.setData({ skip: 0, page: 0, list: [] })
  26. let { item } = e.currentTarget.dataset;
  27. wx.navigateTo({ url: `/pages/topic/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. watchLogin: async function () {
  50. const that = this;
  51. let searchInfo = that.data.searchInfo;
  52. wx.getStorage({
  53. key: 'user',
  54. success: async (res) => {
  55. let info = { skip: that.data.skip, limit: that.data.limit, is_show: '0' };
  56. if (searchInfo && searchInfo.title) info.title = searchInfo.title;
  57. const arr = await app.$get(`/newCourt/api/topic`, { ...info });
  58. if (arr.errcode == '0') { that.setData({ list: [...that.data.list, ...arr.data] }); that.setData({ total: arr.total }); }
  59. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  60. },
  61. fail: async (res) => {
  62. wx.redirectTo({ url: '/pages/index/index' });
  63. },
  64. });
  65. },
  66. /**
  67. * 生命周期函数--监听页面初次渲染完成
  68. */
  69. onReady: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面显示
  73. */
  74. onShow: function () {
  75. const that = this;
  76. // 监听用户是否登录
  77. that.watchLogin();
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. },
  99. /**
  100. * 用户点击右上角分享
  101. */
  102. onShareAppMessage: function () {
  103. }
  104. })