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
| <template>
| <el-date-picker
| v-model="selectValue"
| :type="type"
| :value-format="dateFormat"
| :placeholder="placeholder"
| :picker-options="pickerOptions"
| @change="onSelected">
| </el-date-picker>
| </template>
| <script>
|
| export default {
| name: 'ZtDatePicker',
| components: {},
| props: {
| value: [String, Date],
| type: {
| type: String,
| default: 'date'
| },
| format: String,
| max: { // 可选最大日期
| type: [String, Date],
| default: '2100-01-01'
| },
| min: { // 可选最小日期
| type: [String, Date],
| default: '1979-01-01'
| },
| placeholder: {
| type: String,
| default: '选择日期'
| }
| },
| data() {
| let that = this
| return {
| selectValue: '',
| pickerOptions: {
| disabledDate(date) {
| let d = date.getTime()
| let start = that.min instanceof Date ? that.min.getTime() : new Date(that.min.replace('/-/g', '/')).getTime()
| let end = that.max instanceof Date ? that.max.getTime() : new Date(that.max.replace('/-/g', '/')).getTime()
| return !(d >= start && d <= end)
| }
| }
| }
| },
| computed: {
| dateFormat() {
| if (this.format) {
| return this.format
| } else if (this.type === 'date') {
| return 'yyyy-MM-dd'
| } else if (this.type === 'datetime') {
| return 'yyyy-MM-dd HH:mm:ss'
| }
| }
| },
| watch: {
| value(val, oldval) {
| this.selectValue = val
| }
| },
| mounted() {
| },
| methods: {
| onSelected(data) {
| this.$emit('input', this.selectValue)
| }
| }
| }
| </script>
| <style lang="scss">
| .el-date-editor.el-input {
| width: 100%;
| }
| </style>
|
|