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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import { RRule, RRuleSet, rrulestr } from "rrule";
import { getHomeUserSchedule1 } from "../../api/request";
import {
getFormatDate,
getCurrentMonthFirst,
getCurrentMonthLast,
throttle
} from "../../utils/utils";
import create from "dd-store";
create.Component({
mixins: [],
data: {
userMsg: "",
$data: null,
response: "",
scheduleList: [],
todayStr: "",
thisYear: "",
maxYear: "",
minYear: "",
pageStartTime: "",
pageEndTime: "",
show: false,
scrollHeight: "",
timeStamp: "",
userMsg: {},
loading: true
},
props: {},
didMount() {
this.getDate();
this.setData({
userMsg: {
headUrl: getApp().globalData.avatar || "",
userName: getApp().globalData.name
}
});
this.$store.locationSchedule = () => {
this.locationScheduleList();
};
},
didUpdate() {
if (this.props.update) {
this.$store.data.indexNeedUpdate = false;
this.update();
this.getDate();
}
},
didUnmount() { },
methods: {
getDate: throttle(function (e) {
let data = {
startTime: "2020-01-01 00:00:00",
endTime: "2025-12-30 23:59:59"
};
let that = this;
getHomeUserSchedule1(data).then(res => {
that.setData(
{
response: res.data.data
},
() => {
let now = new Date();
let year = now.getFullYear();
let scheduleList = [];
for (let i = 0; i <= year - 2019; i++) {
scheduleList.push(that.returnScheduleList(2019 + i));
}
// 第一次加载
const finalDate = new Date();
that.setData({
scheduleList: scheduleList,
todayStr: finalDate.toLocaleDateString(),
thisYear: year,
maxYear: year
});
}
);
that.setData({
loading: false
})
});
}, 1000),
nextDetail: throttle(function (e) {
let item = e.target.dataset.item;
dd.navigateTo({
url: `./../meetingDetail/meetingDetail?scheduleItem=${JSON.stringify(
item
)}`
});
}, 1000),
closePop() {
this.setData({
show: false
});
},
changesidebar() {
this.setData({
show: true
});
},
preventSort() {
return false;
},
// 返回删除的日期
returnExcludeDate(data) {
let returnData = {
scheduleList: [],
templateList: []
};
data.map(item => {
if (item.length > 10) {
returnData.templateList.push(
new Date(item.slice(6, 16).replace(/-/g, "/")).getTime()
);
} else {
returnData.scheduleList.push(item);
}
});
return {
scheduleList: returnData.scheduleList,
templateList: Math.min(...returnData.templateList)
};
},
// 生成用户时间段内的会议日程并返回会议日程List
getCalendarList() {
let that = this;
// 定义map数据结构
let scheduleMap = new Map();
// 对规则内的
if (this.data.response) {
this.data.response.templateList.map(item => {
// TO DO 判断所获取的时间区间
// 将会议的年,月,日拆分,时分拆分,生成rrules规则
let initialTime = item.initialTime.split("-");
let initialTimeDate = new Date(
parseInt(initialTime[0]),
parseInt(initialTime[1]) - 1,
parseInt(initialTime[2])
);
let initialTimeDateyear = initialTimeDate.getFullYear();
let initialTimeDatemonth =
initialTimeDate.getMonth() + 1 < 10
? "0" + (initialTimeDate.getMonth() + 1)
: initialTimeDate.getMonth() + 1;
let initialTimeDateday =
initialTimeDate.getDate() < 10
? "0" + initialTimeDate.getDate()
: initialTimeDate.getDate();
let startTimeList = item.startTime.split(":");
let DTSTART = `${initialTimeDateyear}${initialTimeDatemonth}${initialTimeDateday}T${startTimeList[0]}${startTimeList[1]}00Z`;
let rule = RRule.fromString(
`${item.recurrenceModel.recurrenceRule};DTSTART=${DTSTART}`
);
// rule.options.tzid = "";
// 判断是否需要剔除某一天
if (item.excludePlanDates) {
// 拿到剔除日期的list
let excludeDateList = that.returnExcludeDate(
item.excludePlanDates.split(",")
);
rule.all().map(item2 => {
let time = new Date(item2);
time.setHours(time.getHours() - 8);
let hasExclude = excludeDateList.scheduleList.indexOf(excludeDate) === -1;
let excludeDate = getFormatDate(time, "yyyyMMdd", "-");
if (
new Date(time).getTime() < excludeDateList.templateList &&
hasExclude
) {
let startTime =
getFormatDate(time, "yyyyMMdd") +
" " +
item.recurrenceModel.startTime;
let endTime = new Date(
getFormatDate(time, "yyyyMMdd") +
" " +
item.recurrenceModel.startTime
);
endTime.setMinutes(
endTime.getMinutes() + item.recurrenceModel.duration
);
scheduleMap.set(
`${new Date(time).toLocaleDateString()}/${item.id}`,
{
confirmAttendance: item.confirmAttendance,
endTime: getFormatDate(endTime, "yyyyMMdd HH:mm:ss"),
scheduleTemplateId: item.id,
startTime: startTime,
title: item.title,
planDate: getFormatDate(time, "yyyyMMdd", "-")
}
);
}
});
} else {
rule.all().map(item2 => {
let time = new Date(item2);
time.setHours(time.getHours() - 8);
let startTime =
getFormatDate(time, "yyyyMMdd") +
" " +
item.recurrenceModel.startTime;
let endTime = new Date(
getFormatDate(time, "yyyyMMdd") +
" " +
item.recurrenceModel.startTime
);
endTime.setMinutes(
endTime.getMinutes() + item.recurrenceModel.duration
);
scheduleMap.set(
`${new Date(time).toLocaleDateString()}/${item.id}`,
{
confirmAttendance: item.confirmAttendance,
endTime: getFormatDate(endTime, "yyyyMMdd HH:mm:ss"),
scheduleTemplateId: item.id,
startTime: startTime,
title: item.title,
planDate: getFormatDate(time, "yyyyMMdd", "-")
}
);
});
}
});
let scheduleList = [];
this.data.response.scheduleList.map(item => {
if (!item.scheduleTemplateId) {
scheduleList.push(item);
} else if (
item.scheduleTemplateId &&
scheduleMap.get(
`${new Date(
item.planDate.replace(/-/g, "/")
).toLocaleDateString()}/${item.scheduleTemplateId}`
)
) {
scheduleMap.set(
`${new Date(
item.planDate.replace(/-/g, "/")
).toLocaleDateString()}/${item.scheduleTemplateId}`,
item
);
}
});
scheduleMap.forEach(function (value, key, map) {
scheduleList.push(value);
});
return scheduleList;
} else {
return [];
}
},
returnScheduleList(year) {
let that = this;
let weekList = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
let DateMap = new Map();
// 平年或闰年
let isLeapYear =
(year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 366 : 365;
let isFirstWeek = false;
for (let i = 1; i <= isLeapYear; i++) {
// 判断一月第一周的第一个周日
if (i <= 7 && new Date(year, 0, i).getDay() === 0) {
isFirstWeek = true;
}
// 是第一个月第一个周一
if (isFirstWeek) {
DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, {
scheduleList: []
});
}
}
// 跨年的那几天不是周一的
let num = 6 - new Date(year, 0, 366).getDay();
for (let i = 0; i <= num; i++) {
DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, {
scheduleList: []
});
}
let AllScheduleList = this.getCalendarList();
// 遍历所有日程
for (let y = 0; y < AllScheduleList.length; y++) {
let date1 = AllScheduleList[y].startTime
.slice(0, 10)
.replace(/-/g, "/");
let date2 = AllScheduleList[y].endTime.slice(0, 10).replace(/-/g, "/");
let count = this.count(date1, date2);
for (let j = 0; j <= count; j++) {
let time = new Date(date1);
time.setDate(time.getDate() + j);
let keyDate = time.toLocaleDateString();
if (DateMap.get(keyDate)) {
DateMap.get(keyDate).scheduleList.push({
...AllScheduleList[y],
isDaySpan: count == 0 ? false : true,
isfirstDayOrEndDay: j === 0 ? "0" : j === count ? "2" : "1", // 0 第一天,1中间的天,2结束的天
thisDayStartTime: AllScheduleList[y].startTime.slice(11, 16),
thisDayEndTime: AllScheduleList[y].endTime.slice(11, 16),
isFewDays: j + 1,
duration: count + 1,
isBeOverdue:
new Date().getTime() >
new Date(
AllScheduleList[y].endTime.replace(/-/g, "/")
).getTime()
? true
: false
});
}
}
}
let DateList = [];
let listMonth = "";
// 第一个月的第一天
let listWeek = new Date(year, 0, 1).getDay() === 0 ? 0 : 1;
let thisDay = new Date().toLocaleDateString();
DateMap.forEach(function (value, key, map) {
const keyDate = new Date(key);
if (keyDate.getDay() === 0) {
let rangeYear1 = keyDate.getFullYear();
let rangeMonth1 = keyDate.getMonth();
let rangeDay1 = keyDate.getDate();
let rangeDate = new Date(rangeYear1, rangeMonth1, rangeDay1 + 6);
let rangeMonth2 = new Date(rangeDate).getMonth();
let rangeDay2 = new Date(rangeDate).getDate();
DateList.push({
type: "week",
value: `第${listWeek}周,${rangeMonth1 + 1}月${rangeDay1}日 - ${
rangeMonth2 == rangeMonth1 ? "" : rangeMonth2 + 1 + "月"
}${rangeDay2}日`,
dayStr: key
});
listWeek += 1;
}
if (keyDate.getMonth() === 0 && keyDate.getDate() === 1) {
DateList.push({
type: "year",
value: year
});
}
if (keyDate.getDate() === 1) {
DateList.push({
type: "month",
value: keyDate.getMonth() + 1
});
}
// 有日程长度 并且不是今天
if (value.scheduleList.length !== 0 && key !== thisDay) {
DateList.push({
type: "day",
isThisDay: true,
value: {
value: value.scheduleList,
day:
keyDate.getDate() < 10
? "0" + keyDate.getDate()
: keyDate.getDate(),
week: weekList[keyDate.getDay()]
}
});
}
// 有日程长度,并且是今天
else if (value.scheduleList.length !== 0 && key === thisDay) {
DateList.push({
type: "today",
value: {
value: value.scheduleList,
day:
keyDate.getDate() < 10
? "0" + keyDate.getDate()
: keyDate.getDate(),
week: weekList[keyDate.getDay()],
dateStr: key
}
});
}
if (value.scheduleList.length === 0 && key === thisDay) {
DateList.push({
type: "thisDay",
value: {
value: value.scheduleList,
day:
keyDate.getDate() < 10
? "0" + keyDate.getDate()
: keyDate.getDate(),
week: weekList[keyDate.getDay()],
dateStr: key
}
});
}
});
return DateList;
},
// 是否跨天 返回跨天数
count(date1, date2) {
var date1 = new Date(date1);
var date2 = new Date(date2);
var date =
(date2.getTime() - date1.getTime()) /
(1000 * 60 * 60 * 24); /*不用考虑闰年否*/
return date;
},
lower() {
let year = this.data.maxYear + 1;
let DateList = this.returnScheduleList(year);
this.data.scheduleList.push(DateList);
let scheduleList = [...this.data.scheduleList];
this.setData({
scheduleList: scheduleList,
maxYear: year
});
},
nextPage() {
dd.navigateTo({ url: "./../createMeeting/createMeeting" });
},
locationScheduleList() {
this.setData(
{
todayStr: ""
},
() => {
this.setData({
todayStr: new Date().toLocaleDateString()
});
this.$store.data.isLocation = false;
this.update();
}
);
}
}
});