<template>
  <el-select
    v-model="_value"
    :size="size" 
    remote
    :remote-method="onFetch"
    :placeholder="placeholder || '请选择客户公司'"
    :loading="loading"
    reserve-keyword
    filterable
    clearable
  >
    <el-option 
      v-for="item in list" 
      :key="item.id" 
      :value="item.id" 
      :label="item.title"
    />
  </el-select>
</template>


<script>
import asyncRequest from "@/apis/components/search"
export default {
  name:'SearchInvoiceTitle',
  props:['size', 'value' , 'placeholder', 'level'],
  data(){
    return {
      loading: false,
      list: []
    }
  },
  computed:{
    _value:{
        get(){
          return this.value
        },
        set(newVal){
          const current = this.list.find(({id}) => id === newVal)
          this.$emit('update:value', newVal)
          this.$emit('change', current)
        }
    }
  },
  methods:{
    async onFetch(title = ""){
      const {code, data} = await asyncRequest.title({ quick_search:title })
      if(code !== 1) return
      this.list = data.list
    }
  }
}
</script>
