index_1.vue
1.4 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
<template>
<view class="ncc-time-range">
<u-input type="select" :select-open="selectShow" v-model="innerValue" :placeholder="placeholder"
@click="openSelect"></u-input>
<time-range :defaultTime="defaultTime" v-model="selectShow" @confirm="selectConfirm">
</time-range>
</view>
</template>
<script>
import timeRange from './time-range.vue'
export default {
name: 'ncc-time-range',
components: {
timeRange
},
model: {
prop: 'value',
event: 'input'
},
props: {
value: {
type: Array,
default: () => []
},
placeholder: {
type: String,
default: '请选择时间范围'
},
disabled: {
type: Boolean,
default: false
}
},
data() {
return {
defaultTime: [],
selectShow: false,
innerValue: '',
}
},
watch: {
value(val) {
this.setDefault()
}
},
created() {
this.setDefault()
},
methods: {
setDefault() {
if (this.value.length === 2) {
this.defaultTime = this.value
this.innerValue = this.value[0] + '-' + this.value[1]
} else {
this.innerValue = ''
this.defaultTime = []
}
},
openSelect() {
if (this.disabled) return
this.selectShow = true
},
selectConfirm(e) {
// #ifdef MP-WEIXIN
this.innerValue = e[0] + '-' + e[1]
// #endif
this.$emit('input', e)
}
}
}
</script>
<style lang="scss" scoped>
.ncc-time-range {
width: 100%;
}
</style>