riku
2024-11-13 ab70c6eb4a181b282af0eb200275cd8a4d2ab172
pages/mService/pSchedule/pSchedule.js
@@ -1,77 +1,79 @@
// pages/mService/pSchedule/pSchedule.js
import bScheduleManager from '../behaviors/bScheduleManager'
const moment = require('../../../utils/moment.min')
import sysSchedules from '../../../data/schedules';
import moment from "../../../utils/moment.min";
Page({
  behaviors: [bScheduleManager],
  /**
   * 页面的初始数据
   */
  data: {
    totals: 0,
    schedules: [{
      category: '2022年9月环保工作日程',
      details: [{
        time: '9月10日',
        name: '环保日程',
        left: 3,
      }]
    }]
    schedules: [
      // {
      //   category: '2022年9月环保工作日程',
      //   details: [
      //     {
      //       time: '9月10日',
      //       name: '环保日程',
      //       left: 3,
      //     },
      //   ],
      // },
    ],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // const now = moment().hour(0).minute(0).second(0).millisecond(0)
    // const year = now.year()
    const schedules = []
    let totals = this.data.allSchedules.length
    sysSchedules().then(res => this.parseAllSchedules(res));
  },
    const map = new Map()
    for (let i = 0; i < this.data.allSchedules.length; i++) {
      const s = this.data.allSchedules[i];
      s.events.forEach(e => {
        if (!map.has(e.category)) {
          map.set(e.category, [])
  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(e.category).push({
          time: s.time.format('MM月DD日'),
          name: e.name,
      map.get(category).push({
        time: _time.format('MM月DD日'),
        name: s.title,
          left: s.diffDays,
          s: s
        })
        s: s,
      });
    }
    for (let item of map) {
      schedules.push({
        category: item[0],
        details: item[1]
      })
        details: item[1],
      });
    }
    this.setData({
      schedules,
      totals
    })
      totals,
    });
  },
  goto(e) {
    var that = this
    const index = e.currentTarget.dataset.index
    const s = that.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
    }
    console.log(that.data.schedules);
    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)
      success: res => {
        res.eventChannel.emit('acceptDataFromOpenerPage', s);
      },
    })
  }
})
    });
  },
});