riku
2022-10-28 b45a01a8bee4a9bff5f9c248ead301b8675d1099
pages/m_service/p_schedule/p_schedule.js
@@ -1,8 +1,9 @@
// pages/m_service/p_schedule/p_schedule.js
import b_scheduleManager from '../behaviors/b_scheduleManager'
const moment = require('../../../utils/moment.min')
Page({
  behaviors: [b_scheduleManager],
  /**
   * 页面的初始数据
   */
@@ -22,90 +23,55 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const now = moment().hour(0).minute(0).second(0).millisecond(0)
    const year = now.year()
    // const now = moment().hour(0).minute(0).second(0).millisecond(0)
    // const year = now.year()
    const schedules = []
    let totals = 0
    for (let m = 1; m <= 12; m++) {
      const s = {
        category: `${year}年${m}月环保工作日程`,
        details: []
      }
      const mon = m > 9 ? m : `0${m}`
      //10,15,20
      let t1 = moment(`${year}-${mon}-10`)
      let d1 = t1.diff(now, 'days')
      s.details.push({
        time: t1.format('MM月DD日'),
        name: '环保日程环保日程环保日程环保日程环保日程环保日程',
        left: d1,
      })
      let t2 = moment(`${year}-${mon}-15`)
      let d2 = t2.diff(now, 'days')
      s.details.push({
        time: t2.format('MM月DD日'),
        name: '环保日程',
        left: d2,
      })
      let t3 = moment(`${year}-${mon}-20`)
      let d3 = t3.diff(now, 'days')
      s.details.push({
        time: t3.format('MM月DD日'),
        name: '环保日程',
        left: d3,
      })
      schedules.push(s)
      totals += 3
    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
        })
      });
    }
    this.setData({schedules, totals})
    for (let item of map) {
      schedules.push({
        category: item[0],
        details: item[1]
      })
    }
    this.setData({
      schedules,
      totals
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  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/m_service/p_scheduledetail/p_scheduledetail',
      success: (res) => {
        res.eventChannel.emit('acceptDataFromOpenerPage', _s)
      },
    })
  }
})