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


<script>

import asyncRequest from "@/apis/components/search"
export default {
  name:'SearchActivityType',
  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(keyword = ""){
      const {code, data} = await asyncRequest.actType({ name: keyword })
      if(code !== 1) return
      this.list = data.list
    }
  }
}
</script>
