保誠-保戶業務員媒合平台
Tomas
2022-04-27 85c39644533f93559ccf51cc4c8dfa7388d36cd4
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
<template>
    <el-date-picker
        class="pam-date cursor--pointer"
        popper-class="pam-date-popper"
        v-model="dateValue"
        :clearable="false"
        type="date"
        :editable="false"
        format="yyyy/MM/dd"
        placeholder="選擇日期"
        prefix-icon="icon-down down-icon"
        :picker-options="pickerOptions"
        @change="changeDate"
    >
    </el-date-picker>
</template>
 
<script lang="ts">
import { Component, Emit, Prop, PropSync, Vue, Watch } from "nuxt-property-decorator";
 
@Component
export default class UiDatePicker extends Vue {
    dateValue: Date | string = '';
 
    @Prop()
    defaultValue!: string;
 
    @Prop({default: false})
    isPastDateDisabled!: boolean;
 
    @Prop({default: false})
    isFutureDateDisabled!: boolean;
 
    @Prop()
    disabledBeforeSpecificDate?: string;
 
    @Emit('changeDate')
    changeDate() {
        return this.dateValue;
    }
 
    @Watch('defaultValue', {immediate: true})
    updateDefault() {
        if (this.defaultValue) {
            this.dateValue = new Date(this.defaultValue);
            this.changeDate();
        }
    }
 
    get pickerOptions() {
        const date = new Date();
        const currentDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
 
        if (!!this.disabledBeforeSpecificDate) {
          const compareDate = new Date(this.disabledBeforeSpecificDate);
          return {
              disabledDate(time: Date) {
                  const pickedDate = `${time.getFullYear()}/${time.getMonth() + 1}/${time.getDate()}`;
                  return new Date(pickedDate).getTime() < compareDate.getTime();
              }
          }
        }
 
        if (this.isPastDateDisabled) {
            return {
                disabledDate(time: Date) {
                    const pickedDate = `${time.getFullYear()}/${time.getMonth() + 1}/${time.getDate()}`;
                    return new Date(pickedDate).getTime() < new Date(currentDate).getTime();
                }
            }
        }
 
        if (this.isFutureDateDisabled) {
            return {
                disabledDate(time: Date) {
                    const pickedDate = `${time.getFullYear()}/${time.getMonth() + 1}/${time.getDate()}`;
                    return new Date(pickedDate).getTime() > new Date(currentDate).getTime();
                }
            }
        }
    }
 
}
</script>