<script lang="ts" setup name="ModelSelector">
import { getModelByList } from '@/api/model/modelApi'
const props = withDefaults(defineProps<{
  modelValue: number
}>(), {
  modelValue: 0,
})
const emit = defineEmits(['update:modelValue'])
interface Model {
  modelId: number
  modelTitle: string
}
const modelId = computed({
  get: () => {
    return props.modelValue
  },
  set: (val) => {
    emit('update:modelValue', val)
  },
})
const state = reactive({
  loading: false,
  dataList: [] as Model[],
})

const getData = async () => {
  state.loading = true
  const { data } = await getModelByList({})
  state.loading = false
  state.dataList = data
}
onMounted(() => {
  getData ()
})
</script>

<template>
  <el-select v-model="modelId" v-loading="state.loading" style="width: 100%" filterable placeholder="请选择数据模型" value-key="modelId">
    <el-option key="0" label="请选择" :value="0" disabled />
    <el-option
      v-for="item in state.dataList"
      :key="item.modelId"
      :label="item.modelTitle"
      :value="item.modelId"
    />
  </el-select>
</template>
