<template>
  <CheckGroup
    :list="infoList"
    @change="handleChange"
    :default-value="defaultInfo"
    value-key="id"
    label-key="name"
    v-bind="$attrs"
  />
</template>

<script lang="ts" setup>
import { getUniversityFeature } from '@/service/index/api'
import CheckGroup from '@/pages-sub/components/check-group/CheckGroup.vue'

const infoList = ref()

getUniversityFeature().then((res) => {
  if (res.code === 200) {
    infoList.value = res.result as { id: number; name: string }[]
  }
})

const defaultInfo = ref<string[]>([])

const emits = defineEmits(['changeName'])

const handleChange = (val: any) => {
  const names = infoList.value.filter((item) => val.includes(item.id)).map((item) => item.name)
  emits('changeName', names)
}
</script>
