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

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

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