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 }); }, });