import sysSchedules from '../../../data/schedules'; import moment from "../../../utils/moment.min"; Page({ /** * 页面的初始数据 */ data: { totals: 0, schedules: [ // { // category: '2022年9月环保工作日程', // details: [ // { // time: '9月10日', // name: '环保日程', // left: 3, // }, // ], // }, ], }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { sysSchedules().then(res => this.parseAllSchedules(res)); }, parseAllSchedules(allSchedules) { const schedules = []; let totals = allSchedules.length; const map = new Map(); for (let i = 0; i < allSchedules.length; i++) { const s = allSchedules[i]; const _time = moment(s.time) const category = `${_time.year()}年${_time.month() + 1}月环保工作日程` if (!map.has(category)) { map.set(category, []); } map.get(category).push({ time: _time.format('MM月DD日'), name: s.title, left: s.diffDays, s: s, }); } for (let item of map) { schedules.push({ category: item[0], details: item[1], }); } this.setData({ schedules, totals, }); }, goto(e) { const index = e.currentTarget.dataset.index; const s = this.data.schedules[index[0]].details[index[1]].s; // const _s = { // time: s.time.format('YYYY-MM-DD dddd'), // events: s.events, // diffDays: s.diffDays, // steps: s.steps, // category: s.category, // }; wx.navigateTo({ url: '/pages/mService/pScheduledetail/pScheduledetail', success: res => { res.eventChannel.emit('acceptDataFromOpenerPage', s); }, }); }, });