|
3 | 3 | <div class="vfc-close" @click="close()"></div>
|
4 | 4 | <div class="vfc-modal-time-mechanic">
|
5 | 5 | <div id="time-line" class="vfc-modal-time-line">
|
6 |
| - <span>{{ $parent.calendar.selectedDateTime }}</span> |
| 6 | + <span> |
| 7 | + <template v-if="$parent.fConfigs.isDateRange"> |
| 8 | + <span @click="startDateActive = true" :class="{'vfc-active': startDateActive}">{{ $parent.calendar.dateRange.start.dateTime}}</span><template |
| 9 | + v-if="$parent.calendar.dateRange.end.date"> -<span @click="startDateActive = false" |
| 10 | + :class="{'vfc-active': !startDateActive}">{{ this.$parent.calendar.dateRange.end.dateTime }}</span></template> |
| 11 | + </template> |
| 12 | + <template v-else> |
| 13 | + {{ $parent.calendar.selectedDateTime }} |
| 14 | + </template> |
| 15 | + </span> |
7 | 16 | </div>
|
8 | 17 | <div class="vfc-time-picker">
|
9 | 18 | <div class="vfc-time-picker__list vfc-time-picker__list--hours" ref="hourList">
|
10 |
| - <div class="vfc-time-picker__item" :class="{'vfc-time-picker__item--selected': ($parent.calendar.selectedHour === (i < 10 ? '0'+(i-1) : i))}" v-for="i in 23" @click="changeHour(i < 10 ? '0'+(i-1) : i)">{{ i < 10 ? '0'+(i-1) : i}}</div> |
| 19 | + <div class="vfc-time-picker__item" |
| 20 | + :class="{'vfc-time-picker__item--selected': checkHourActiveClass(i)}" v-for="i in 23" |
| 21 | + @click="changeHour(i < 10 ? '0'+(i-1) : i)">{{ i < 10 ? '0'+(i-1) : i}} |
| 22 | + </div> |
11 | 23 | </div>
|
12 | 24 | <div class="vfc-time-picker__list vfc-time-picker__list--minutes" ref="minuteList">
|
13 |
| - <div class="vfc-time-picker__item" :class="{'vfc-time-picker__item--selected': ($parent.calendar.selectedMinute === (i < 10 ? '0'+(i-1) : i))}" v-for="i in 59" @click="changeMinute(i < 10 ? '0'+(i-1) : i)">{{ i < 10 ? '0'+(i-1) : i}}</div> |
| 25 | + <div class="vfc-time-picker__item" |
| 26 | + :class="{'vfc-time-picker__item--selected': checkMinuteActiveClass(i)}" |
| 27 | + v-for="i in 59" @click="changeMinute(i < 10 ? '0'+(i-1) : i)">{{ i < 10 ? '0'+(i-1) : i}} |
| 28 | + </div> |
14 | 29 | </div>
|
15 | 30 | </div>
|
16 | 31 | </div>
|
|
20 | 35 | <script>
|
21 | 36 | export default {
|
22 | 37 | name: "TimePicker",
|
23 |
| - mounted () { |
| 38 | + data() { |
| 39 | + return { |
| 40 | + startDateActive: true |
| 41 | + } |
| 42 | + }, |
| 43 | + watch: { |
| 44 | + 'startDateActive': function(){ |
| 45 | + this.setStyles(); |
| 46 | + } |
| 47 | + }, |
| 48 | + mounted() { |
| 49 | + let startDate = this.$parent.calendar.dateRange.start.date; |
| 50 | + let endDate = this.$parent.calendar.dateRange.end.date; |
| 51 | +
|
| 52 | + if (startDate && startDate < endDate) { |
| 53 | + this.startDateActive = false; |
| 54 | + } else { |
| 55 | + this.startDateActive = true; |
| 56 | + } |
| 57 | +
|
24 | 58 | this.setSelectedDateTime();
|
25 | 59 | this.setStyles();
|
26 | 60 | },
|
|
29 | 63 | this.$parent.showTimePicker = false;
|
30 | 64 | },
|
31 | 65 | changeHour(hour) {
|
32 |
| - this.$parent.calendar.selectedHour = hour; |
| 66 | + if (this.$parent.fConfigs.isDateRange) { |
| 67 | + if (this.checkStartDate()) { |
| 68 | + this.$parent.calendar.dateRange.start.hour = hour; |
| 69 | + } else { |
| 70 | + this.$parent.calendar.dateRange.end.hour = hour; |
| 71 | + } |
| 72 | + } else { |
| 73 | + this.$parent.calendar.selectedHour = hour; |
| 74 | + } |
| 75 | +
|
33 | 76 | this.setSelectedDateTime();
|
34 | 77 | },
|
35 |
| - changeMinute(minute) |
36 |
| - { |
37 |
| - this.$parent.calendar.selectedMinute = minute; |
| 78 | + changeMinute(minute) { |
| 79 | + if (this.$parent.fConfigs.isDateRange) { |
| 80 | + if (this.checkStartDate()) { |
| 81 | + this.$parent.calendar.dateRange.start.minute = minute; |
| 82 | + } else { |
| 83 | + this.$parent.calendar.dateRange.end.minute = minute; |
| 84 | + } |
| 85 | + } else { |
| 86 | + this.$parent.calendar.selectedHour = hour; |
| 87 | + } |
| 88 | +
|
38 | 89 | this.setSelectedDateTime();
|
39 | 90 | },
|
40 | 91 | setSelectedDateTime() {
|
41 | 92 | this.$parent.calendar.selectedDateTime = this.$parent.calendar.selectedDate + " " + this.$parent.calendar.selectedHour + ':' + this.$parent.calendar.selectedMinute;
|
| 93 | + this.$parent.calendar.dateRange.start.dateTime = this.$parent.calendar.dateRange.start.date + " " + this.$parent.calendar.dateRange.start.hour + ':' + this.$parent.calendar.dateRange.start.minute; |
| 94 | + this.$parent.calendar.dateRange.end.dateTime = this.$parent.calendar.dateRange.end.date + " " + this.$parent.calendar.dateRange.end.hour + ':' + this.$parent.calendar.dateRange.end.minute; |
| 95 | + }, |
| 96 | + checkStartDate() { |
| 97 | + return this.startDateActive; |
| 98 | + }, |
| 99 | + checkHourActiveClass(i) { |
| 100 | + let hour; |
| 101 | + if (this.$parent.fConfigs.isDateRange) { |
| 102 | + if (this.checkStartDate()) { |
| 103 | + hour = this.$parent.calendar.dateRange.start.hour; |
| 104 | + } else { |
| 105 | + hour = this.$parent.calendar.dateRange.end.hour; |
| 106 | + } |
| 107 | + } else { |
| 108 | + hour = this.$parent.calendar.selectedHour; |
| 109 | + } |
| 110 | +
|
| 111 | + return hour === (i < 10 ? '0' + (i - 1) : i); |
| 112 | + }, |
| 113 | + checkMinuteActiveClass(i) { |
| 114 | + let minute; |
| 115 | + if (this.$parent.fConfigs.isDateRange) { |
| 116 | + if (this.checkStartDate()) { |
| 117 | + minute = this.$parent.calendar.dateRange.start.minute; |
| 118 | + } else { |
| 119 | + minute = this.$parent.calendar.dateRange.end.minute; |
| 120 | + } |
| 121 | + } else { |
| 122 | + minute = this.$parent.calendar.selectedMinute; |
| 123 | + } |
| 124 | +
|
| 125 | + return minute === (i < 10 ? '0' + (i - 1) : i); |
42 | 126 | },
|
43 | 127 | setStyles() {
|
44 | 128 | let container = this.$parent.$refs.mainContainer;
|
45 | 129 |
|
46 |
| - const selectedHour = this.$refs.hourList.querySelector('.vfc-time-picker__item--selected'); |
47 |
| - const selectedMinute = this.$refs.minuteList.querySelector('.vfc-time-picker__item--selected'); |
48 |
| - this.$refs.hourList.scrollTop = selectedHour ? selectedHour.offsetTop - container.clientHeight/2 : 0; |
49 |
| - this.$refs.minuteList.scrollTop = selectedMinute ? selectedMinute.offsetTop - container.clientHeight/2 : 0; |
| 130 | + this.$nextTick(function(){ |
| 131 | + const selectedHour = this.$refs.hourList.querySelector('.vfc-time-picker__item--selected'); |
| 132 | + const selectedMinute = this.$refs.minuteList.querySelector('.vfc-time-picker__item--selected'); |
| 133 | +
|
| 134 | + this.$refs.hourList.scrollTop = selectedHour ? selectedHour.offsetTop - container.clientHeight / 2 : 0; |
| 135 | + this.$refs.minuteList.scrollTop = selectedMinute ? selectedMinute.offsetTop - container.clientHeight / 2 : 0; |
| 136 | + }); |
50 | 137 |
|
51 | 138 | let timeLine = document.getElementById('time-line');
|
52 | 139 | document.getElementsByClassName('vfc-time-picker__list')[0].style.height = container.clientHeight - timeLine.clientHeight + 'px';
|
|
0 commit comments