index.js
21.9 KB
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
// component/calendar/calendar.js
// import {
// GET_HOSPITAL_SCHEDULES
// } from '~/http/interfaces'
// import {
// getStorageSync
// } from '~/utils/util'
// import moment from 'moment'
import api from '../../api'
var touchStartX = 0; //触摸时的原点
var touchStartY = 0; //触摸时的原点
var time = 0; // 时间记录,用于滑动时且时间小于1s则执行左右滑动
var interval = ""; // 记录/清理时间记录
var touchMoveX = 0; // x轴方向移动的距离
var touchMoveY = 0; // y轴方向移动的距离
Component({
/**
* 组件的属性列表
*/
properties: {
spotMap: {
//标点的日期
type: Object,
value: {},
},
defaultTime: {
//标记的日期,默认为今日 注意:传入格式推荐为'2022/1/2'或'2022/01/02', 其他格式在ios系统上可能出现问题
type: String,
value: '',
},
title: {
//标题
type: String,
value: '',
},
goNow: {
// 是否有快速回到今天的功能
type: Boolean,
value: true,
},
defaultOpen: {
// 是否是打开状态
type: Boolean,
value: false,
},
showShrink: {
// 是否显示收缩展开功能
type: Boolean,
value: true,
},
disabledDate: {
// 指定不可用日期
type: Function,
value: undefined,
},
// changeTime: {
// // 要改变的日期
// type: String,
// value: '',
// },
},
/**
* 组件的初始数据
*/
data: {
selectDay: {}, //选中的日期
nowDay: {}, //现在的日期
disabledDate: {}, //禁用的日期
open: true,
swiperCurrent: 1, //选中的日期
oldCurrent: 1, //之前选中的日期
dateList0: [], //0位置的日历数组
dateList1: [], //1位置的日历数组
dateList2: [], //2位置的日历数组
swiperDuration: 500,
swiperHeight: 0,
backChange: false, //跳过change切换
disabledDateList: {}, //禁用的日期集合
isShow: true,
scheduList: {},
classNameList: {
5: "blue", // 待到店,
4: "orange", // 已改约,
6: "grey", // 已取消,
8: "green", //已成交
7: "red", //未成交
},
currentSelect: '',
today: '',
showPopup: false,
// pickerTime: new Date().getTime(),
currentMonth: new Date().getTime(),
showCurrentMonth: ''
},
/**
* 组件的方法列表
*/
methods: {
// // 日历滑动时触发的方法
// swiperChange(e) {
// if (this.data.backChange) {
// this.setData({
// backChange: false,
// });
// return;
// }
// //计算第三个索引
// let rest = 3 - e.detail.current - this.data.oldCurrent;
// let dif = e.detail.current - this.data.oldCurrent;
// let date;
// if (dif === -2 || (dif > 0 && dif !== 2)) {
// //向右划的情况,日期增加
// if (this.data.open) {
// date = new Date(this.data.selectDay.year, this.data.selectDay.month);
// this.setMonth(date.getFullYear(), date.getMonth() + 1, undefined);
// this.getIndexList({
// setYear: this.data.selectDay.year,
// setMonth: this.data.selectDay.month,
// dateIndex: rest,
// });
// } else {
// date = new Date(
// this.data.selectDay.year,
// this.data.selectDay.month - 1,
// this.data.selectDay.day + 7
// );
// this.setMonth(
// date.getFullYear(),
// date.getMonth() + 1,
// date.getDate()
// );
// this.getIndexList({
// setYear: this.data.selectDay.year,
// setMonth: this.data.selectDay.month - 1,
// setDay: this.data.selectDay.day + 7,
// dateIndex: rest,
// });
// }
// } else {
// //向左划的情况,日期减少
// if (this.data.open) {
// date = new Date(
// this.data.selectDay.year,
// this.data.selectDay.month - 2
// );
// this.setMonth(date.getFullYear(), date.getMonth() + 1, undefined);
// this.getIndexList({
// setYear: this.data.selectDay.year,
// setMonth: this.data.selectDay.month - 2,
// dateIndex: rest,
// });
// } else {
// date = new Date(
// this.data.selectDay.year,
// this.data.selectDay.month - 1,
// this.data.selectDay.day - 7
// );
// this.setMonth(
// date.getFullYear(),
// date.getMonth() + 1,
// date.getDate()
// );
// this.getIndexList({
// setYear: this.data.selectDay.year,
// setMonth: this.data.selectDay.month - 1,
// setDay: this.data.selectDay.day - 7,
// dateIndex: rest,
// });
// }
// }
// this.setData({
// oldCurrent: e.detail.current,
// });
// this.setSwiperHeight(e.detail.current);
// },
// 根据指定位置数组的大小计算日历的高度
setSwiperHeight(index) {
this.setData({
swiperHeight: (this.data[`dateList${index}`].length / 7) * 98 + 18,
});
},
// 获取指定日期各时段的邀约列表
// getListByDay(inviteDate) {
// let { currentSelect } = this.data
// let params = {
// inviteDate: inviteDate || currentSelect
// }
// this.triggerEvent('getListByDay', params)
// },
// 获取邀约日历
getInviteCalendar() {
let { merchantId } = wx.$util.getUserInfo()
let { dateList1 } = this.data
let params = {
startDate: dateList1[0]?.full,
endDate: dateList1[dateList1.length - 1]?.full,
merchantId
}
api.getInviteStat(params).then(res => {
let { code, data, message } = res
if (code == '0') {
let _dateList = JSON.parse(JSON.stringify(dateList1))
_dateList.forEach((item, index) => {
item.inviteNum = data[index]?.inviteNum
item.maxNum = data[index]?.maxNum
item.remainNum = data[index]?.maxNum - data[index]?.inviteNum
})
this.setData({
dateList1: _dateList
})
// this.getListByDay()
this.triggerEventSelectDay();
} else {
wx.$util.showToast(message)
}
})
},
// 更新指定的索引和月份的列表
getIndexList({
setYear,
setMonth,
setDay = void 0,
dateIndex
}) {
let appointMonth;
if (setDay) appointMonth = new Date(setYear, setMonth, setDay);
else appointMonth = new Date(setYear, setMonth);
const listName = `dateList${dateIndex}`;
const dataList = this.dateInit({
setYear: appointMonth.getFullYear(),
setMonth: appointMonth.getMonth() + 1,
setDay: appointMonth.getDate(),
hasBack: true,
});
const disabledDateList = {};
if (this.data.disabledDate)
dataList.forEach((item) => {
if (
!this.data.disabledDateList[
`disabled${item.year}M${item.month}D${item.day}`
] &&
this.data.disabledDate(item)
) {
disabledDateList[
`disabled${item.year}M${item.month}D${item.day}`
] = true;
}
});
this.setData({
[listName]: dataList,
disabledDateList: Object.assign(
this.data.disabledDateList,
disabledDateList
),
});
this.getInviteCalendar()
},
// 设置月份
setMonth(setYear, setMonth, setDay) {
const day = Math.min(
new Date(setYear, setMonth, 0).getDate(),
this.data.selectDay.day
);
if (
this.data.selectDay.year !== setYear ||
this.data.selectDay.month !== setMonth
) {
const data = {
selectDay: {
year: setYear,
month: setMonth,
day: setDay ? setDay : day,
},
};
if (!setDay) {
data.open = true;
}
this.setData(data, () => {
this.triggerEventSelectDay();
});
} else {
const data = {
selectDay: {
year: setYear,
month: setMonth,
day: setDay ? setDay : day,
},
};
this.setData(data, () => {
this.triggerEventSelectDay();
});
}
},
// 展开收起
// openChange() {
// this.setData({
// open: !this.data.open,
// });
// // 更新数据
// const selectDate = new Date(
// this.data.selectDay.year,
// this.data.selectDay.month - 1,
// this.data.selectDay.day
// );
// if (this.data.oldCurrent === 0) {
// this.updateList(selectDate, -1, 2);
// this.updateList(selectDate, 0, 0);
// this.updateList(selectDate, 1, 1);
// } else if (this.data.oldCurrent === 1) {
// this.updateList(selectDate, -1, 0);
// this.updateList(selectDate, 0, 1);
// this.updateList(selectDate, 1, 2);
// } else if (this.data.oldCurrent === 2) {
// this.updateList(selectDate, -1, 1);
// this.updateList(selectDate, 0, 2);
// this.updateList(selectDate, 1, 0);
// }
// this.setSwiperHeight(this.data.oldCurrent);
// },
// 选中并切换今日日期
// witchDate(setDate) {
// const selectDate = new Date(
// this.data.selectDay.year,
// this.data.selectDay.month - 1,
// this.data.selectDay.day
// );
// let dateDiff =
// (selectDate.getFullYear() - setDate.getFullYear()) * 12 +
// (selectDate.getMonth() - setDate.getMonth());
// let diff = dateDiff === 0 ? 0 : dateDiff > 0 ? -1 : 1;
// const diffSum = (x) => (3 + (x % 3)) % 3;
// if (this.data.oldCurrent === 0) {
// this.updateList(setDate, -1, diffSum(2 + diff));
// this.updateList(setDate, 0, diffSum(0 + diff));
// this.updateList(setDate, 1, diffSum(1 + diff));
// } else if (this.data.oldCurrent === 1) {
// this.updateList(setDate, -1, diffSum(0 + diff));
// this.updateList(setDate, 0, diffSum(1 + diff));
// this.updateList(setDate, 1, diffSum(2 + diff));
// } else if (this.data.oldCurrent === 2) {
// this.updateList(setDate, -1, diffSum(1 + diff));
// this.updateList(setDate, 0, diffSum(2 + diff));
// this.updateList(setDate, 1, diffSum(0 + diff));
// }
// this.setData({
// swiperCurrent: diffSum(this.data.oldCurrent + diff),
// oldCurrent: diffSum(this.data.oldCurrent + diff),
// backChange: dateDiff !== 0,
// });
// this.setData({
// selectDay: {
// year: setDate.getFullYear(),
// month: setDate.getMonth() + 1,
// day: setDate.getDate(),
// },
// },
// () => {
// this.triggerEventSelectDay();
// }
// );
// this.setSwiperHeight(this.data.oldCurrent);
// },
// 切换到今天
// switchNowDate() {
// this.witchDate(new Date());
// },
// 日历主体的渲染方法
dateInit({
setYear,
setMonth,
setDay = this.data.selectDay.day,
hasBack = false,
} = {
setYear: this.data.selectDay.year,
setMonth: this.data.selectDay.month,
setDay: this.data.selectDay.day,
hasBack: false,
}) {
let dateList = []; //需要遍历的日历数组数据
let now = new Date(setYear, setMonth - 1); //当前月份的1号
let startWeek = now.getDay(); //目标月1号对应的星期
let resetStartWeek = startWeek == 0 ? 6 : startWeek - 1; //重新定义星期将星期天替换为6其余-1
let dayNum = new Date(setYear, setMonth, 0).getDate(); //当前月有多少天
let forNum = Math.ceil((resetStartWeek + dayNum) / 7) * 7; //当前月跨越的周数
let selectDay = setDay ? setDay : this.data.selectDay.day;
this.triggerEvent('getDateList', {
setYear: now.getFullYear(),
setMonth: now.getMonth() + 1,
});
if (this.data.open) {
//展开状态,需要渲染完整的月份
for (let i = 0; i < forNum; i++) {
const now2 = new Date(now);
now2.setDate(i - resetStartWeek + 1);
let obj = {};
let _month = now2.getMonth() + 1 < 10 ? '0' + (now2.getMonth() + 1) : now2.getMonth() + 1
let _day = now2.getDate() < 10 ? '0' + now2.getDate() : now2.getDate()
obj = {
day: _day,
month: _month,
year: now2.getFullYear(),
full: `${now2.getFullYear()}-${_month}-${_day}`
};
dateList[i] = obj;
}
} else {
//非展开状态,只需要渲染当前周
for (let i = 0; i < 7; i++) {
const now2 = new Date(now);
let _month = now2.getMonth() + 1 < 10 ? '0' + (now2.getMonth() + 1) : now2.getMonth() + 1
let _day = now2.getDate() < 10 ? '0' + now2.getDate() : now2.getDate()
//当前周的7天
now2.setDate(
Math.ceil((selectDay + (startWeek - 1)) / 7) * 7 -
6 -
(startWeek - 1) +
i
);
let obj = {};
obj = {
day: _day,
month: _month,
year: now2.getFullYear(),
full: `${now2.getFullYear()}-${_month}-${_day}`
};
dateList[i] = obj;
}
}
if (hasBack) {
return dateList;
}
this.setData({
dateList1: dateList,
});
},
// 一天被点击时
selectChange(e) {
const year = e.currentTarget.dataset.year;
const month = e.currentTarget.dataset.month;
const day = e.currentTarget.dataset.day;
const selectDay = {
year: year,
month: month,
day: day,
};
if (
this.data.open &&
(this.data.selectDay.year !== year ||
this.data.selectDay.month !== month)
) {
if (
year * 12 + month >
this.data.selectDay.year * 12 + this.data.selectDay.month
) {
// 下个月
if (this.data.oldCurrent == 2)
this.setData({
swiperCurrent: 0,
});
else
this.setData({
swiperCurrent: this.data.oldCurrent + 1,
});
} else {
// 点击上个月
if (this.data.oldCurrent == 0)
this.setData({
swiperCurrent: 2,
});
else
this.setData({
swiperCurrent: this.data.oldCurrent - 1,
});
}
this.setData({
['selectDay.day']: day,
},
() => {
this.triggerEventSelectDay();
}
);
} else if (this.data.selectDay.day !== day) {
this.setData({
selectDay: selectDay,
},
() => {
this.triggerEventSelectDay();
}
);
}
},
// 选择某天时触发的事件
triggerEventSelectDay() {
if (
!this.data.disabledDateList[
'disabled' +
this.data.selectDay.year +
'M' +
this.data.selectDay.month +
'D' +
this.data.selectDay.day
]
) {
this.triggerEvent('selectDay', this.data.selectDay);
}
},
// 更新日历列表
updateList(date, offset, index) {
const setDate = new Date(
date.getFullYear(),
date.getMonth() + offset * 1
); //取得当前日期的上个月日期
this.getIndexList({
setYear: setDate.getFullYear(),
setMonth: setDate.getMonth(),
dateIndex: index,
});
},
// 获取排班数据
// getSchedules() {
// let _this = this;
// let user = this.data.user
// let oParams = {}
// oParams.hospitalId = user.hospitalId
// console.log(new Date(_this.data.currentMonth).format('YYYY-MM'))
// oParams.month = new Date(_this.data.currentMonth).format('YYYY-MM')
// GET_HOSPITAL_SCHEDULES(oParams).then(res => {
// let obj = res.data || [];
// let options = {};
// obj.map((k) => {
// let i = moment(k.appointmentTime).format("YYYY-M-DD");
// if (options[i]) {
// options[i].push(k);
// } else {
// options[i] = [k];
// }
// });
// console.log(options)
// console.log(_this.data.currentSelect)
// let list = options[_this.data.currentSelect] || []
// _this.setData({
// scheduList: options
// })
// console.log(list)
// _this.triggerEvent('change', list)
// })
// },
refresh() {
let { selectDay } = this.data
const selectDate = new Date(
selectDay.year,
selectDay.month - 1,
selectDay.day
)
this.updateList(selectDate, 0, 1);
},
// 选中日历
dayOnSelect(e) {
let o = e.currentTarget.dataset
let options = this.data.scheduList
let full = o.full;
let list = options[full] || []
this.setData({
currentSelect: full,
selectDay: o,
showCurrentMonth: `${o.year}年${o.month}月${o.day}日`
// isShow: false
})
// this.triggerEvent('change', list)
this.triggerEventSelectDay();
wx.$util.pointRecord(26)
},
// 收起/展开
handleUpOrDown() {
this.setData({
isShow: !this.data.isShow
})
},
// 打开日期选择
openPicker() {
this.setData({
showPopup: true
})
},
// 关闭日期选择
onClose() {
this.setData({
showPopup: false
})
},
// 保存日期选择
onConfirm(e) {
console.log(e)
console.log(this.data.currentSelect)
let n = this.data.currentSelect
let y = new Date(e.detail).format('yyyy')
let m = new Date(e.detail).format('MM')
let d = new Date(e.detail).format('dd')
let _day = {
year: y,
month: m,
day: d,
full: `${y}-${m}-${d}`
}
console.log(`${y}-${m}-${d}`)
this.setData({
showPopup: false,
currentMonth: e.detail,
showCurrentMonth: new Date(e.detail).format('yyyy年MM月dd日'),
currentSelect: `${y}-${m}-${d}`,
selectDay: _day
})
// this.getSchedules()
this.updateList(new Date(e.detail), 0, 1)
},
// 触摸开始事件
touchStart: function (e) {
touchStartX = e.touches[0].pageX; // 获取触摸时的原点
touchStartY = e.touches[0].pageY; // 获取触摸时的原点
// 使用js计时器记录时间
interval = setInterval(function () {
time++;
}, 100);
},
// 触摸移动事件
touchMove: function (e) {
touchMoveX = e.touches[0].pageX;
touchMoveY = e.touches[0].pageY;
},
// 触摸结束事件
touchEnd: function (e) {
let _this = this
var moveX = touchMoveX - touchStartX
var moveY = touchMoveY - touchStartY
if (Math.sign(moveX) == -1) {
moveX = moveX * -1
}
if (Math.sign(moveY) == -1) {
moveY = moveY * -1
}
if (moveX <= moveY) { // 上下
// 向上滑动
if (touchMoveY - touchStartY <= -30 && time < 10) {
console.log("向上滑动")
let h = _this.data.swiperHeight
let hInterval = setInterval(function () {
if (h <= 96) {
clearInterval(hInterval)
return false;
}
h -= 26
_this.setData({
swiperHeight: h
})
}, 5)
}
// 向下滑动
if (touchMoveY - touchStartY >= 30 && time < 10) {
console.log('向下滑动 ');
let h = _this.data.swiperHeight
let o = _this.data.dateList1.length / 7 * 98 + 18
let hInterval = setInterval(function () {
if (h >= o) {
clearInterval(hInterval)
return false;
}
h += 26
_this.setData({
swiperHeight: h
})
}, 5)
}
}
clearInterval(interval); // 清除setInterval
time = 0;
},
},
lifetimes: {
// 加载事件
ready() {
let now = this.data.defaultTime ?
new Date(this.data.defaultTime) :
new Date();
let year = now.getFullYear()
let month = now.getMonth() + 1 < 10 ? '0' + (now.getMonth() + 1) : now.getMonth() + 1
let day = now.getDate() < 10 ? '0' + now.getDate() : now.getDate()
let today = `${year}-${month}-${day}`
// let selectDay = {
// year: year,
// month: month,
// day:day,
// };
this.setData({
nowDay: {
year: year,
month: month,
day: day,
},
currentSelect: today,
today: today,
showCurrentMonth: new Date(`${year}/${month}/${day}`).format('yyyy年MM月dd日')
});
// let user = getStorageSync('user');
// this.setData({
// user
// })
// this.getSchedules()
this.setMonth(year, month, day);
// this.updateList(now, -1, 0);
this.updateList(now, 0, 1);
//this.updateList(now, 1, 2);
this.setSwiperHeight(1);
},
},
observers: {
// 重新设置打开状态
defaultOpen(value) {
this.setData({
open: value,
});
},
// // 切换日期
// changeTime(value) {
// // 检测切换日期
// if (!value) return;
// this.witchDate(new Date(value));
// },
},
});