<template>
    <el-date-picker style="width: 100%;"
                    ref="datePicker"
            v-model="value"
            @change="onChange"
            @focus="$emit('focus')"
            :format="formatEl"
            :placeholder="propertys.placeholder"
    />
</template>

<script>
    export default {
    name: "datePicker",
    data() {
        return {
            data:{},
            value:"",
            formatEl:null,
            propertys:{},
        };
    },
    props: {
        model:{
            type:String,
            default:""
        },
        getData:{
            type:Function,
        },
        property:{
            type:Object,
            default:()=>{}
        }
    },
    created() {
        MapUtil.setDftValue(this.propertys,{
            placeholder:'请选择',
            format:'YYYY-MM-DD',
            ...this.property
        });
        this.formatEl=filters.veToElDateFormat(this.propertys.format||"YYYY-MM-DD");
        },
    methods: {
        init(value){
            this.value=value;
            this.$refs.datePicker.focus()
        },
        onChange(){
            let model=this.value ? DateUtil.dateFmt(this.propertys.format, this.value) : null;
            this.$emit("update:model",model);
            this.$emit("change",model)
        },
        /**
         * 组件数据提交
         */
        submit(){
            let vm=this;
            vm.$emit("submit",{
                sucess:()=>{
                },
                error:(obj)=>{//obj 错误信息
                    this.$message(obj.msg)
                }
            });
        },
    }
};
</script>

