-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdateDisplay.vue
118 lines (113 loc) · 2.82 KB
/
dateDisplay.vue
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
<template>
<div class="mu-date-display">
<div class="mu-date-display-year">
<div class="mu-date-display-slideIn-wrapper">
<div class="mu-date-display-year-title">
<span>{{startYear}}</span>
<span v-if="startYear !== endYear">{{endYear}}</span>
</div>
</div>
</div>
<div class="mu-date-display-monthday">
<transition :name="'mu-date-display-' + slideType" v-for="(displayDate, index) in displayDates.startDate" :key="index">
<div class="date startDate mu-date-display-slideIn-wrapper" :key="dateTimeFormat.formatDisplay(displayDate)">
<div class="mu-date-display-monthday-title">
{{dateTimeFormat.formatDisplay(startDate)}}
</div>
</div>
</transition>
<div class="hyphen">-</div>
<transition :name="'mu-date-display-' + slideType" v-for="(displayDate, index) in displayDates.endDate" :key="index">
<div class="date endDate mu-date-display-slideIn-wrapper" :key="dateTimeFormat.formatDisplay(displayDate)">
<div class="mu-date-display-monthday-title">
{{dateTimeFormat.formatDisplay(endDate)}}
</div>
</div>
</transition>
</div>
</div>
</template>
<script>
import { addYears } from '../../../es/dateUtils';
export default {
name: 'dateDisplay',
props: {
dateTimeFormat: {
type: Object,
},
startDate: {
type: Date,
},
endDate: {
type: Date,
},
},
data() {
return {
displayDates: {
startDate: [this.startDate],
endDate: [this.endDate],
},
slideType: 'next',
};
},
computed: {
startYear() {
return this.startDate && this.startDate.getFullYear();
},
endYear() {
return this.endDate && this.endDate.getFullYear();
},
},
methods: {
replaceSelected(date, type) {
const oldDate = this.displayDates[type][0] || addYears(new Date(), type === 'startDate' ? -100 : 100);
this.slideType = date.getTime() > oldDate.getTime() ? 'next' : 'prev';
this.displayDates[type].push(date);
this.displayDates[type].splice(0, 1);
},
},
watch: {
startDate(val) {
if (val) {
this.replaceSelected(val, 'startDate');
}
},
endDate(val) {
if (val) {
this.replaceSelected(val, 'endDate');
}
},
},
};
</script>
<style lang="scss">
.mu-date-display {
.mu-date-display-year-title {
position: relative;
&>span:nth-child(2) {
position: absolute;
left: 60%;
}
}
.mu-date-display-monthday {
.date {
width: 40%;
text-align: center;
}
.startDate {
left: 0;
}
.endDate {
left: 60%;
}
.hyphen {
position: absolute;
left: 40%;
width: 20%;
text-align: center;
display: inline-block;
}
}
}
</style>