<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
<!--    <a-button type="primary" class="ele-btn-icon" @click="add">-->
<!--      <template #icon>-->
<!--        <PlusOutlined />-->
<!--      </template>-->
<!--      <span>添加</span>-->
<!--    </a-button>-->
<!--    <a-button class="ele-btn-icon" @click="openImport">-->
<!--      <template #icon>-->
<!--        <CloudUploadOutlined />-->
<!--      </template>-->
<!--      <span>导入(多)</span>-->
<!--    </a-button>-->
    <a-button class="ele-btn-icon" @click="exportData">
      <template #icon>
        <CloudDownloadOutlined />
      </template>
      <span>导出</span>
    </a-button>
    <a-button
      danger
      class="ele-btn-icon"
      :disabled="!selection?.length"
      @click="remove"
    >
      <template #icon>
        <DeleteOutlined />
      </template>
      <span>批量删除</span>
    </a-button>
    <a-input-search
      allow-clear
      v-model:value="keywords"
      placeholder="请输入关键词"
      style="width: 220px"
      @search="handleSearch"
      @pressEnter="handleSearch"
    />
  </a-space>
</template>

<script lang="ts" setup>
  import { computed, ref } from 'vue';
  import {
    PlusOutlined,
    CloudUploadOutlined,
    CloudDownloadOutlined,
    DeleteOutlined
  } from '@ant-design/icons-vue';
  import type {
    CreditUser,
    CreditUserParam
  } from '@/api/credit/creditUser/model';

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

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

  const keywords = ref('');
  const selection = computed(() => props.selection || []);

  // 新增
  const add = () => {
    emit('add');
  };

  // 搜索
  const handleSearch = () => {
    emit('search', { keywords: keywords.value });
  };

  // 导入
  const openImport = () => {
    emit('importData');
  };

  // 导出
  const exportData = () => {
    emit('exportData');
  };

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