<template>
  <BasicModal
    :showCancelBtn="false"
    :showOkBtn="false"
    width="800px"
    v-bind="$attrs"
    @register="register"
    :title="title"
    helpMessage="点击最右侧选择按钮"
  >
    <Person v-if="title === '添加个人'" @select="select" />
    <Unit v-if="title === '添加单位'" @select="select" />
  </BasicModal>
</template>
<script lang="ts">
  import Person from './person/index.vue';
  import Unit from './unit/index.vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { defineComponent, reactive, toRefs } from 'vue';

  export default defineComponent({
    components: { BasicModal, Person, Unit },
    emits: ['select'],
    setup(_, { emit }) {
      const state = reactive({
        title: '',
      });
      const [register, { closeModal }] = useModalInner((data) => {
        state.title = data;
      });

      function select(data) {
        emit('select', data);
        closeModal();
      }
      return {
        register,
        select,
        ...toRefs(state),
      };
    },
  });
</script>
