<!-- 搜索表单 -->
<template>
  <div class="search">
    <a-space :size="10" style="flex-wrap: wrap">
      <a-button
        danger
        type="primary"
        class="ele-btn-icon"
        :disabled="selection.length === 0"
        @click="removeBatch"
      >
        <template #icon>
          <DeleteOutlined />
        </template>
        <span>批量删除</span>
      </a-button>
      <a-radio-group v-model:value="where.certificateType" @change="search">
        <a-radio-button value="idCard">身份认证</a-radio-button>
        <a-radio-button value="house">房屋认证</a-radio-button>
        <a-radio-button value="education">学历认证</a-radio-button>
        <a-radio-button value="car">车辆认证</a-radio-button>
      </a-radio-group>
      <a-radio-group v-model:value="where.status" @change="search">
        <a-radio-button :value="10">待审核</a-radio-button>
        <a-radio-button :value="20">已驳回</a-radio-button>
        <a-radio-button :value="30">已通过</a-radio-button>
      </a-radio-group>
      <a-input-search
        allow-clear
        placeholder="请输入搜索关键词"
        v-model:value="where.keywords"
        @pressEnter="search"
        @search="search"
        style="width: 196px"
      />
      <a-button @click="reset">重置</a-button>
    </a-space>
  </div>
</template>

<script lang="ts" setup>
  import { DeleteOutlined } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import { watch } from 'vue';
  import { CertificateParam } from '@/api/love/certficate/model';

  const props = withDefaults(
    defineProps<{
      // 选中的角色
      selection?: [];
    }>(),
    {}
  );

  const emit = defineEmits<{
    (e: 'search', where?: CertificateParam): void;
    (e: 'add'): void;
    (e: 'remove'): void;
  }>();

  // 表单数据
  const { where, resetFields } = useSearch<CertificateParam>({
    certificateId: undefined,
    certificateType: 'idCard',
    certificateName: undefined,
    status: undefined,
    keywords: undefined
  });

  /* 搜索 */
  const search = () => {
    emit('search', {
      ...where
    });
  };

  /*  重置 */
  const reset = () => {
    resetFields();
    search();
  };

  // 批量删除
  const removeBatch = () => {
    emit('remove');
  };

  watch(
    () => props.selection,
    () => {}
  );
</script>
