<template>
    <el-autocomplete
        style="width:100%"
        v-model="model" 
        :placeholder="placeholder"
        :fetch-suggestions="handleSearch"
        @select="handleSelect" 
    ></el-autocomplete>
</template>
<script>
import Api from "~/service/Api";
export default {
    props:{
        url:{
            type:String
        },
        placeholder:{
            type:String,
            default:"请输入"
        },
        text:{
            type:String
        },
        dataConfig:{
            type:Object,
            default: ()=>{}
        }
    },
    data(){
        return {
            model:this.dataConfig
        }
    },
    methods:{
        async handleSearch(qs,cb){
            var list = [{}];
            let cond = {'cond':qs}
            let rtnmsg = await Api.post(this.url,cond);
            if(rtnmsg.code == 0){
                for(let item of rtnmsg.data){
                    item.value = item[this.text]
                }
            }
            list = rtnmsg.data
            cb(list)
        },
        handleSelect(item){
            this.$emit('select',item)
        }
    }
}
</script>