TimerTabs.vue
2.7 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
<!-- com-timer-tabs-->
<template>
<div class="com-timer-tabs-container">
<van-tabs v-model="active" color="#3975C6" sticky @click="tabClickHandle">
<van-tab :title="date.title" v-for="date in dates" :key="date.value"></van-tab>
</van-tabs>
<van-calendar v-model="isShowCalendar" @confirm="onConfirm" :show-title="false" :color="color" type="range" :allow-same-day="true" :min-date="min" :max-date="max" :style="{ height: popHeight }" />
</div>
</template>
<script>
import { calendar } from '@/mixins'
import * as dayjs from 'dayjs'
function format(s, e) {
return {
startTime: s.format('YYYY-MM-DD 00:00:00'),
endTime: e.format('YYYY-MM-DD 23:59:59')
}
}
const aDates = Object.freeze([
{
title: '今天',
value: 0,
getDate() {
return format(dayjs().startOf('date'), dayjs().startOf('date'))
}
},
{
title: '本月',
value: 1,
getDate() {
return format(dayjs().startOf('month'), dayjs().endOf('month'))
}
},
{
title: '本周',
value: 2,
getDate() {
if (dayjs().day() == 0) {
return format(dayjs().add(-6, 'day'), dayjs())
} else {
return format(
dayjs()
.startOf('week')
.add(1, 'day'),
dayjs()
.endOf('week')
.add(1, 'day')
)
}
}
},
{
title: '自定义',
value: 3
}
])
export default {
name: 'TimerTabs',
mixins: [calendar],
props: ['value', 'onChange', 'minDate', 'maxDate'],
data() {
return {
dates: aDates,
active: 0,
tabIndex: 0
}
},
computed: {
min() {
return this.minDate || new Date(2020, 0, 1)
},
max() {
return this.maxDate || new Date()
}
},
mounted() {
this.$emit('update:value', aDates[this.tabIndex].getDate())
},
methods: {
onClickLeft() {},
onClickRight() {},
tabClickHandle(index) {
if (index === 3) {
this.isShowCalendar = true
return
}
this.broadcast(aDates[index].getDate())
},
dateChangeHandle(date) {
this.broadcast(date)
},
broadcast(value) {
this.$emit('update:value', value)
this.onChange && this.onChange(value)
},
onConfirm([start, end]) {
this.broadcast(format(dayjs(start), dayjs(end)))
document.getElementsByClassName('van-overlay')[0].click() //hack
}
}
}
</script>
<style lang="scss" scoped>
.com-timer-tabs-container {
// /deep/.self{
// .van-tabs{
// height: calc(100vh - 46px);
// display: flex;
// flex-direction: column;
// &__content{
// flex:1;
// overflow: auto;
// .van-tab__pane{
// height: 100%;
// }
// }
// }
// }
}
</style>