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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import scheduleservice from '../../../service/scheduleservice'
import sysSchedules from '../../../data/schedules'
import moment from '../../../utils/moment.min'
import util from '../../../utils/util'
 
const app = getApp()
 
/**
 * 环保日程管理
 */
module.exports = Behavior({
  // behaviors: [bLoadingStatus],
  properties: {
    ledgerCompleted: {
      type: Boolean,
      observer(value) {
        this.checkScheduleComplete(0, value)
      }
    },
    assessmentCompleted: {
      type: Boolean,
      observer(value) {
        this.checkScheduleComplete(1, value)
      }
    }
  },
  data: {
    allSchedules: [],
    thisSchedule: {},
    index: 0
  },
  lifetimes: {
    attached: function () {
      this.getRecentSchedule()
      if (app.globalData.newUser) {
        this.nextSchedules()
      }
      // this.getAllSchedules()
    }
  },
  methods: {
    //查找最临近的日程
    getRecentSchedule() {
      //1. 从接口获取用户个人、用户企业类型的相关最临近日程
      //2. 按照本地逻辑,得出最邻近日程
      const schedules = sysSchedules()
      //2.1 将台账、评估、承诺三项APP功能定义为日程
      //2.2 选择最邻近的事项作为当日的提醒事项, 
      let today = moment().hour(0).minute(0).second(0).millisecond(0)
      let diffDays = 999
      let schedule
      let index = 0
      for (let i = 0; i < schedules.length; i++) {
        let s = schedules[i];
        let d = s.time.diff(today, 'days')
        s.diffDays = d
        if (Math.abs(d) < Math.abs(diffDays)) {
          let _index = i
 
          schedule = s
          diffDays = d
          index = _index
        }
      }
      //2.3 日程在时间维度上分为三类提醒,预告、当日、未完成的逾期提醒
 
 
      this.setData({
        allSchedules: schedules,
        thisSchedule: {
          date: schedule.time,
          time: schedule.time.format('YYYY-MM-DD dddd'),
          type: schedule.type,
          events: schedule.events,
          diffDays: schedule.diffDays,
        },
        index
      })
    },
 
    //获取所有日程
    getAllSchedules() {
      console.log('getAllSchedules');
      scheduleservice.getAllSchedules(app.globalData.accessToken.userId, {
        success(res) {
          console.log('success');
          console.log(res);
        },
        fail(e) {
          console.log('fail');
          console.log(e);
        },
        complete(res) {
          console.log('complete');
        },
      })
    },
 
    // 当前日程完成,顺延下一个日程
    nextSchedules() {
      let today = moment().hour(0).minute(0).second(0).millisecond(0)
      let s = this.data.allSchedules[this.data.index + 1];
      let d = s.time.diff(today, 'days')
      s.diffDays = d
 
      this.setData({
        thisSchedule: {
          date: s.time,
          time: s.time.format('YYYY-MM-DD dddd'),
          type: s.type,
          events: s.events,
          diffDays: s.diffDays,
        },
        index: this.data.index + 1
      })
    },
 
    // 检查当前日程是否完成
    checkScheduleComplete(type, value) {
      debugger
      // 新用户不做判断
      if (app.globalData.newUser) return
      // 日程类型不一致无需判断
      if (this.data.thisSchedule.type != type) return
      // 日程不在当月的无需判断
      const thisMonth = moment().month()
      const sTimeMonth = moment(this.data.thisSchedule.date).month()
      if (thisMonth != sTimeMonth) return
 
      // 日程完成则顺延下个日程
      if (value) {
        this.nextSchedules()
      }
    }
  }
})