<template>
    <a-form-model-item :label="attr.name" :prop="attr.alias">
        <a-time-picker v-if="setting.date_format === 'HH:mm:ss'"
                       :value="modelVal"
                       :valueFormat="setting.date_format"
                       :allowClear="true"
                       :format="setting.date_format"
                       :placeholder="placeholder"
                       :disabled="disabled"
                       @change="change"
        />
        <a-date-picker v-else
                       :value="modelVal"
                       :valueFormat="setting.date_format"
                       :allowClear="true"
                       :format="setting.date_format"
                       :placeholder="placeholder"
                       :disabled="disabled"
                       @change="change"
        />
    </a-form-model-item>
</template>

<script>
export default {
    name: "mix-date",
    model: {
        prop: "modelVal",
        event: 'change'
    },
    props: {
        modelVal: "",
        attr: {
            type: Object,
            default: () => {
            }
        }
    },
    data(){
        return {
            setting: {
                is_allow_null: true,
                tip: "请选择",
                date_format: "YYYY-MM-DD HH:mm:ss"
            },
            placeholder: "请选择",
            disabled: false
        }
    },
    created() {
        this.setting = this.attr.setting
        this.setDisable(this.attr.display)
        this.setPlaceholder(this.setting.tip)
    },
    methods: {
        setDisable(display) {
            if (display === 'r' || display === 'v') {
                this.disabled = true;
            } else if (display === 'h') {
                this.textType = 'hidden';
            } else if (display === 'w') {
                this.disabled = false;
            }
        },
        setPlaceholder(tip){
            this.placeholder = tip ? tip : "请输入"
        },
        change(time, timeString){
            if (time){
                this.$emit('change', time);
            }
        }
    }
}
</script>

<style scoped>

</style>
