<!-- 搜索表单 -->
<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="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-select
      v-model:value="step"
      allow-clear
      placeholder="步骤"
      style="width: 140px"
      @change="handleSearch"
    >
      <a-select-option
        v-for="item in stepOptions"
        :key="item.value"
        :value="item.value"
      >
        {{ item.text }}
      </a-select-option>
    </a-select>
    <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, watch } from 'vue';
  import {
    PlusOutlined,
    CloudDownloadOutlined,
    DeleteOutlined
  } from '@ant-design/icons-vue';
  import type {
    CreditMpCustomer,
    CreditMpCustomerParam
  } from '@/api/credit/creditMpCustomer/model';

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

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

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

  const stepOptions = [
    { value: 0, text: '未受理' },
    { value: 1, text: '已受理' },
    { value: 2, text: '材料提交' },
    { value: 3, text: '合同签订' },
    { value: 4, text: '执行回款' },
    { value: 5, text: '完结' }
  ];

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

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

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

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

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