<!-- 搜索表单 -->
<template>
  <div class="search">
    <a-space :size="10" style="flex-wrap: wrap">
      <a-button
        danger
        type="primary"
        class="ele-btn-icon"
        :disabled="selection && selection.length === 0"
        @click="removeBatch"
      >
        <template #icon>
          <DeleteOutlined />
        </template>
        <span>批量删除</span>
      </a-button>
      <a-radio-group v-model:value="where.applyStatus" @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-button :value="40">已打款</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 { ref, watch } from 'vue';
  import { OrderGoodsParam } from '@/api/order/goods/model';
  import { MerchantWithdrawParam } from '@/api/merchant/withdraw/model';

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

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

  // 表单数据
  const { where, resetFields } = useSearch<MerchantWithdrawParam>({
    id: undefined,
    applyStatus: undefined,
    keywords: undefined
  });

  // 日期范围选择
  const dateRange = ref<[string, string]>(['', '']);

  /* 搜索 */
  const search = () => {
    const [d1, d2] = dateRange.value ?? [];
    where.deliveryTimeStart = d1 ? d1 + ' 00:00:00' : undefined;
    where.deliveryTimeEnd = d2 ? d2 + ' 00:00:00' : undefined;
    emit('search', {
      ...where
    });
  };

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

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

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