<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <a-input-search
      allow-clear
      placeholder="请输入关键词"
      v-model:value="where.keywords"
      @pressEnter="search"
      @search="search"
    />
    <FormSelect
      v-model:value="where.formId"
      :placeholder="`选择表单名称`"
      style="width: 220px"
      @change="chooseFormName"
    />
    <a-button @click="reset">重置</a-button>
    <a-button type="primary" class="ele-btn-icon">
      <span>导出xls</span>
    </a-button>
  </a-space>
</template>

<script lang="ts" setup>
  import { watch } from 'vue';
  import useSearch from '@/utils/use-search';
  import { FormRecordParam } from '@/api/cms/form-record/model';
  import { Form } from '@/api/cms/form/model';
  import {assignObject} from "ele-admin-pro";

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

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

  // 表单数据
  const { where, resetFields } = useSearch<FormRecordParam>({
    formRecordId: undefined,
    formId: undefined,
    phone: undefined,
    keywords: undefined
  });

  const chooseFormName = (id: number) => {
    where.formId = id;
    emit('search', where);
  };

  const search = () => {
    emit('search', where);
  };

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

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