<!-- 搜索表单 -->
<template>
  <a-space>
    <!--    <a-space>-->
    <!--      <a-radio-group :defaultValue="score" @change="handleTabs">-->
    <!--        <a-radio-button :value="0">全部</a-radio-button>-->
    <!--        <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-space>-->
    <a-button
      danger
      type="primary"
      class="ele-btn-icon"
      :v-role="`dev`"
      @click="removeBatch"
      :disabled="props.selection.length === 0"
    >
      <template #icon>
        <DeleteOutlined />
      </template>
      <span>批量删除</span>
    </a-button>
    <a-input-search
      allow-clear
      placeholder="请输入用户昵称"
      v-model:value="where.keywords"
      @pressEnter="search"
      @search="search"
    />
    <!--    <a-button @click="reset">重置</a-button>-->
  </a-space>
</template>

<script lang="ts" setup>
  import { DeleteOutlined } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import type { AssetsParam } from '@/api/oa/assets/model';
  import { ref, watch } from 'vue';
  import { UserFeedbackParam } from '@/api/user/feedback/model';

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

  const props = defineProps<{
    // 勾选的项目
    selection?: [];
  }>();

  // 表单数据
  const { where } = useSearch<UserFeedbackParam>({
    keywords: '',
    id: undefined,
    userId: undefined
  });
  // 日期范围选择
  const dateRange = ref<[string, string]>(['', '']);
  /* 搜索 */
  const search = () => {
    const [d1, d2] = dateRange.value ?? [];
    emit('search', {
      ...where,
      createTimeStart: d1 ? d1 + ' 00:00:00' : '',
      createTimeEnd: d2 ? d2 + ' 23:59:59' : ''
    });
  };

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

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

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

  // 监听字典id变化
  watch(
    () => props.selection,
    () => {}
  );
</script>
