<template>
    <el-select
            v-model="value"
            ref="remoteSelect"
            filterable
            remote
            class="remote-select"
            :clearable="propertys.clearable"
            @focus="$emit('focus')"
            reserve-keyword
            @change="() => {
                            onChange();
                        }"
            :placeholder="propertys.placeholder"
            :remote-method="(query)=>{
            propertys.remoteMethod(data,query)
        }"
    >
        <el-option
                v-for="ite in data.options"
                :key="ite.id"
                :label="ite.name"
                :value="ite.id"
        ></el-option>
    </el-select>
</template>

<script>

    export default {
        name: "remoteSelect",
        data() {
            return {
                value: "",
                data: {
                    options: []
                },
                propertys:{},
            };
        },
        props: {
            model: {
                type: String,
                default: ""
            },
            property: {
                type: Object,
                default:()=>{}
            },
        },
        created() {
            MapUtil.setDftValue(this.propertys, {
                clearable: true,
                placeholder: '请输入',
                remoteMethod(item) {
                    item.options = []
                },
                ...this.property
            });
        },
        methods: {
            init(value) {
                this.value = value;
                this.$refs.remoteSelect.focus();
            },
            /**
             * 获取应该显示的文本
             */
            getLabel() {
                let vm = this;
                return vm.$refs.select._data.selectedLabel;
            },
            onChange() {
                this.$emit("update:model", this.value);
                this.$emit("change", this.value);
            },
            /**
             * 组件数据提交
             */
            submit(){
                let vm=this;
                vm.$emit("submit",{
                    sucess:()=>{
                    },
                    error:(obj)=>{//obj 错误信息
                        this.$message(obj.msg)
                    }
                });
            },
        }
    };
</script>
