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

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

const infoList = ref()

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

const emits = defineEmits(['changeName', 'change', 'changeObj'])

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