<script lang="ts" setup name="OcTypeSelector">
import { getOcTypeByList } from '@/api/system/ocTypeApi'
const props = withDefaults(defineProps<{
  modelValue: number
}>(), {
  modelValue: 0,
})
const emit = defineEmits(['update:modelValue'])
interface OcType {
  ocTypeId: number
  ocTypeTitle: string
}
const ocTypeId = computed({
  get: () => {
    return props.modelValue
  },
  set: (val) => {
    emit('update:modelValue', val)
  },
})
const state = reactive({
  loading: false,
  dataList: [] as OcType[],
})

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

<template>
  <el-select v-model="ocTypeId" v-loading="state.loading" style="width: 100%" filterable placeholder="请选择分类" value-key="ocTypeId">
    <el-option key="0" label="请选择" :value="0" disabled />
    <el-option
      v-for="item in state.dataList"
      :key="item.ocTypeId"
      :label="item.ocTypeTitle"
      :value="item.ocTypeId"
    />
  </el-select>
</template>
