riku
2024-08-12 65124213af664a68ad88ce7f6dcb133116d7702f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { fetchNotice } from '../../../services/notice/fetchNotice';
import { useLoading } from '../../../behaviors/loading';
 
Page({
  behaviors: [useLoading],
  data: {
    unReadList: [0, 0, 0],
    workNoticeList: [],
    warnNoticeList: [],
    sysNoticeList: [],
  },
 
  onLoad(options) {
    if (typeof options.type === 'string') {
      let index = 0;
      switch (options.type) {
        // 系统通知
        case '1':
          index = 2;
          break;
        // 工作通知
        case '2':
          index = 0;
          break;
        // 预警警示
        case '3':
          index = 1;
          break;
      }
      this.setData({ tabValue: index });
    }
    this._startLoad();
  },
 
  onPullDownRefresh() {
    this._startLoad();
  },
 
  onReachBottom() {
    this._loadMore();
  },
 
  // onTabsChange(e) {
  //   const { value } = e.detail;
  //   this.setData({ tabValue: value });
  // },
 
  _fetchData(page) {
    return fetchNotice({ page }).then(res => {
      let workNoticeList = [],
        warnNoticeList = [],
        sysNoticeList = [];
      const { unReadList } = this.data;
      res.data.forEach(r => {
        switch (r.typeId) {
          // 系统通知
          case '1':
            if (!r.hasRead) unReadList[2]++;
            sysNoticeList.push(r);
            break;
          // 工作通知
          case '2':
            if (!r.hasRead) unReadList[0]++;
            workNoticeList.push(r);
            break;
          // 预警警示
          case '3':
            if (!r.hasRead) unReadList[1]++;
            warnNoticeList.push(r);
            break;
          default:
            if (!r.hasRead) unReadList[2]++;
            sysNoticeList.push(r);
            break;
        }
      });
      this.setData({
        workNoticeList:
          page == 1
            ? workNoticeList
            : this.data.workNoticeList.concat(workNoticeList),
        warnNoticeList:
          page == 1
            ? warnNoticeList
            : this.data.warnNoticeList.concat(warnNoticeList),
        sysNoticeList:
          page == 1
            ? sysNoticeList
            : this.data.sysNoticeList.concat(sysNoticeList),
        unReadList,
      });
      return res.head;
    });
  },
 
  navToPublishNotice() {
    wx.navigateTo({
      url: '/pages/usercenter/notice/publish/index',
      events: {
        uploadOver: () => {
          this._startLoad();
        },
      },
    });
  },
 
  onReadNotice(e) {
    const { index } = e.currentTarget.dataset;
    const { unReadList } = this.data;
    unReadList[index]--;
    this.setData({ unReadList });
  },
});