riku
2023-02-24 5d8e52e398bff7bc8f83e8f5b8a387175b958c98
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
// pages/mService/pSchedule/pSchedule.js
import bScheduleManager from '../behaviors/bScheduleManager'
const moment = require('../../../utils/moment.min')
 
Page({
  behaviors: [bScheduleManager],
  /**
   * 页面的初始数据
   */
  data: {
    totals: 0,
    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
 
    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, [])
        }
        map.get(e.category).push({
          time: s.time.format('MM月DD日'),
          name: e.name,
          left: s.diffDays,
          s: s
        })
      });
    }
    for (let item of map) {
      schedules.push({
        category: item[0],
        details: item[1]
      })
    }
    this.setData({
      schedules,
      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);
    wx.navigateTo({
      url: '/pages/mService/pScheduledetail/pScheduledetail',
      success: (res) => {
        res.eventChannel.emit('acceptDataFromOpenerPage', _s)
      },
    })
  }
})