<script setup>
import {businessCustomInterence} from '@/api/modules/businessCustom'

const value=defineModel('value')
const emits=defineEmits(['change'])

const props=defineProps({
  placeholder:{
    type:String,
    default:'请输入搜索'
  },
  multiple:{
    type:Boolean,
    default:false,
  },
  filterable:{
    type:Boolean,
    default:false,
  },
  clearable:{
    type:Boolean,
    default:false,
  },
  disabled:{
    type:Boolean,
    default:false,
  }
})

const options=ref([])
const loading=ref(false)

async function remoteMethod(search){
  loading.value=true
  const res=await businessCustomInterence.bussinessListAll({
    Keyword:search
  })
  loading.value=false
  if(res.Ret!=200) return
  options.value=res.Data.List||[]
}

// 默认获取一次
remoteMethod('')

function handleChange(value,context){
  emits('change',value,context)
}

</script>

<template>
  <t-select
    v-model="value"
    :multiple="props.multiple"
    :filterable="props.filterable"
    :placeholder="props.placeholder"
    :clearable="props.clearable"
    :loading="loading"
    :disabled="props.disabled"
    @search="remoteMethod"
    @change="handleChange"
  >
    <t-option 
      v-for="item in options" 
      :key="item.BusinessCode" 
      :value="item.BusinessCode" 
      :label="item.BusinessName"
    />
  </t-select>
</template>

<style lang="scss" scoped>

</style>