与牧同行-小程序用户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.5 KiB

  1. import http from '../../../utils/api'
  2. Page({
  3. data: {
  4. // 分类数据
  5. categories: [
  6. { name: '全部', value: 'all' },
  7. { name: '系统公告', value: 'system', tagBg: '#e9efff', importanceColor: '#3b82f6' },
  8. { name: '活动通知', value: 'activity', tagBg: '#f3e8ff', importanceColor: '#8b5cf6' },
  9. { name: '紧急提醒', value: 'urgent', tagBg: '#ffe4e2', importanceColor: '#ef4444' },
  10. { name: '学术讲座', value: 'academic', tagBg: '#dcfce7', importanceColor: '#10b981' },
  11. { name: '校园生活', value: 'campus', tagBg: '#fff3cd', importanceColor: '#f59e0b' },
  12. ],
  13. currentCategory: 'all', // 当前选中分类
  14. searchKeyword: '', // 搜索关键字
  15. noticeList: [], // 渲染列表数据
  16. pageIndex: 1, // 页码
  17. pageSize: 8, // 每页条数
  18. hasMore: true, // 是否有更多
  19. loading: false, // 首次加载/加载中
  20. refreshing: false, // 下拉刷新状态
  21. mockTotal: 28, // 模拟总条数
  22. },
  23. onLoad() {
  24. // this.loadFirstPage();
  25. this.getdisaster()
  26. },
  27. // 通知公告
  28. getdisaster(){
  29. http.disaster({
  30. data:{},
  31. success: res => {
  32. console.log(111,res);
  33. this.setData({
  34. noticeList:res.rows
  35. })
  36. }
  37. })
  38. },
  39. // 切换分类
  40. switchCategory(e) {
  41. const category = e.currentTarget.dataset.category;
  42. if (category === this.data.currentCategory) return;
  43. this.setData({ currentCategory: category });
  44. this.loadFirstPage();
  45. },
  46. // 搜索输入
  47. onSearchInput(e) {
  48. this.setData({ searchKeyword: e.detail.value });
  49. },
  50. // 执行搜索(确认或点击清空后也会触发重置)
  51. handleSearch() {
  52. this.loadFirstPage();
  53. },
  54. // 清空搜索框
  55. clearSearch() {
  56. this.setData({ searchKeyword: '' }, () => {
  57. this.loadFirstPage();
  58. });
  59. },
  60. // 上拉加载更多
  61. loadMore() {
  62. const { hasMore, loading, refreshing } = this.data;
  63. if (!hasMore || loading || refreshing) return;
  64. this.setData({ loading: true });
  65. this.fetchNotices(false);
  66. },
  67. // 下拉刷新
  68. onRefresh() {
  69. this.setData({ refreshing: true });
  70. // 重置到第一页
  71. this.setData({ pageIndex: 1, hasMore: true }, () => {
  72. this.fetchNotices(true);
  73. });
  74. },
  75. // 查看详情 (仅跳转示意)
  76. viewDetail(e) {
  77. const id = e.currentTarget.dataset.id;
  78. wx.showToast({
  79. title: `查看公告 ${id}`,
  80. icon: 'none'
  81. });
  82. // 实际开发: wx.navigateTo...
  83. }
  84. })