<template>
    <el-select v-model="deptCode">
        <el-option v-for="item in deptList"
                   :value="item.code"
                   :key="item.code"
                   :label="item.name"/>
    </el-select>
</template>

<script setup name='DeptSelect'>
import {getDept} from "@/api/public-api";

const props = defineProps({
    modelValue: {
        type: String,
        default: ''
    },
})

const emits = defineEmits(['update:modelValue', 'clear'])

const deptList = ref([])
const deptCode = computed({
    get: () => props.modelValue,
    set: (val) => {
        emits('update:modelValue', val)
    }
})


onMounted(() => {
    getDept().then(res => {
        deptList.value = res
    })
})

</script>

<style scoped lang="scss">

</style>
