<script lang="ts" setup name="GroupCatSelector">
import { getGroupCatByList } from '@/api/system/groupCatApi'
const emit = defineEmits(['update:modelValue'])
interface Group {
  groupCatId: number
  groupCatTitle: number
}
const state = reactive({
  loading: false,
  groupCatId: 0,
  dataList: [] as Group[],
})

const getData = async () => {
  state.loading = true
  const { data } = await getGroupCatByList()
  state.loading = false
  state.dataList = data
}
const onChange = () => {
  emit('update:modelValue', state.groupCatId)
}
onMounted(() => {
  getData ()
})
</script>

<template>
  <el-select v-model="state.groupCatId" v-loading="state.loading" style="width: 100%" filterable placeholder="请选择部门类别" value-key="groupCatId" @change="onChange">
    <el-option
      v-for="item in state.dataList"
      :key="item.groupCatId"
      :label="item.groupCatTitle"
      :value="item.groupCatId"
    />
  </el-select>
</template>
