<template>
  <CheckGroup
    :list="infoList"
    @change="handleChange"
    value-key="id"
    label-key="name"
    v-bind="$attrs"
    width="100%"
  />
</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 emits = defineEmits(['changeName', 'changeObj'])

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