<template>
    <el-date-picker
            v-model="value"
            @change="onChange"
            :picker-options="properties.pickerOptions"
            :editable="properties.editable"
            :disabled="properties.disabled"
            type="year"
            :format="formatEl"
            :placeholder="properties.placeholder"
    />
</template>

<script>
import DateUtil from "../../../util/pattern/date";
import StringUtil from "../../../../util/pattern/string";
import mixin from "./mixin";
    export default {
        name: "datePickerYear",
        mixins: [mixin],
        data() {
            return {
                data:{},
                value:"",
                formatEl:null,
                properties: {}
            };
        },
        created() {
            this.initProperties({
                placeholder:'请选择',
	            editable:true,
	            disabled: false,
                format:'YYYY',
                pickerOptions:{}
            });
            this.formatEl = StringUtil.replace(this.properties.format,{
                "Y":"y",
                "M":"M",
                "D":"d",
                "H":"H",
            });
        },
        methods: {
            init(value){
                this.value=value;
            },
            onChange(){
                let model=this.value ? DateUtil.dateFmt(this.properties.format, this.value) : null;
                this.$emit("update:model",model);
                this.$emit("change",model)
            }
        }
    };
</script>
