<template>
    <a-date-picker class="dhc-ProDatePicker" popper-class="dhc-ProDatePicker_popper" v-model:value="valueFormat"
        format="YYYYMMDD" @change="handleChange" @focus="handleFocus" @blur="handleBlur" placeholder="选择日期"
        v-bind="$attrs">
    </a-date-picker>
</template>
<script>
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
// import moment from 'moment'
export default {
    name: 'ProDatePicker',
    props: {
        value: [String, Number],
        readIgnore: {
            type: String,
            default: null
        }
    },
    data () {
        return {
            svalue: typeof this.value == "number" ? this.value + "" : this.value,
        }
    },
    watch: {
        value (val, oldVal) {
            if (val != oldVal) {
                if (typeof this.value == "number") {
                    this.svalue = val + ""
                } else {
                    this.svalue = val
                }
            }
        },
        //判断值是否有改变
        svalue (val, oldVal) {
            if (val != oldVal) {
                this.$emit('input', val)
            }
        },
    },
    methods: {
        //绑定值被改变时的回调
        handleChange (currentValue) {
            this.$emit('change', currentValue)
        },
        //组件 Input 失去焦点时触发
        handleFocus (event) {
            this.$emit('focus', event)
        },
        //组件 Input 获得焦点时触发
        handleBlur (event) {
            this.$emit('blur', event)
        }
    },
    computed: {
        valueFormat () {
            return this.svalue ? dayjs(this.svalue, "YYYYMMDD") : ""
        },
        sysData () {
            let sysData = JSON.parse(sessionStorage.getItem('sysDate'))
            sysData = moment(sysData, "YYYYMMDD").format("YYYY-MM-DD")
            return this.$attrs['default-value'] ? this.$attrs['default-value'] : sysData
        }
    },
}
</script>
<style lang="less">
.dhc-ProDatePicker_popper .a-date-table {
    td.today span {
        color: #606266;
        font-weight: normal;
    }

    td.default span {
        color: #1890ff;
        font-weight: bold;
    }

}
</style>
