index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const app = getApp()
  2. import { news_type } from '../../utils/dict';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '资讯', leftArrow: false, useBar: true },
  9. tabs: {
  10. active: '0',
  11. list: [
  12. { title: '推荐', name: '0' },
  13. { title: '羽毛球', name: '1' },
  14. ],
  15. },
  16. //查询条件
  17. searchInfo: {},
  18. list: [],
  19. typeList: news_type,
  20. },
  21. // 跳转菜单
  22. tabPath(e) {
  23. let { route } = e.detail.detail;
  24. if (route) wx.redirectTo({ url: `/${route}` })
  25. },
  26. // 详情页
  27. toView: function (e) {
  28. let { id } = e.currentTarget.dataset;
  29. wx.navigateTo({ url: `/pages/news/info?id=${id}` })
  30. },
  31. // 选项卡
  32. tabsChange: function (e) {
  33. const that = this;
  34. that.setData({ 'tabs.active': e.detail.name });
  35. that.watchLogin();
  36. },
  37. //搜索
  38. onSearch: function (e) {
  39. const that = this;
  40. that.setData({ 'searchInfo.title': e.detail.value });
  41. that.watchLogin()
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. const that = this;
  48. },
  49. watchLogin: function () {
  50. const that = this;
  51. let searchInfo = that.data.searchInfo;
  52. let type = that.data.tabs.active;
  53. wx.getStorage({
  54. key: 'user',
  55. success: async (res) => {
  56. let info = { skip: 0, limit: 1000 };
  57. if (searchInfo && searchInfo.title) info.title = searchInfo.title;
  58. info.type = type; info.is_show = "0";
  59. const arr = await app.$get(`/newCourt/api/news`, { ...info });
  60. if (arr.errcode == '0') {
  61. that.setData({ list: arr.data })
  62. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  63. },
  64. fail: async (res) => {
  65. wx.redirectTo({ url: '/pages/index/index' });
  66. },
  67. });
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. this.watchLogin();
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage: function () {
  104. }
  105. })