<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <a-button type="primary" class="ele-btn-icon" @click="openAdd">
      <template #icon>
        <PlusOutlined />
      </template>
      <span>新增商品</span>
    </a-button>
    <a-input-search
      allow-clear
      v-model:value="where.productName"
      placeholder="商品名称"
      style="width: 200px"
      @search="reload"
      @pressEnter="reload"
    />
    <a-select
      allow-clear
      v-model:value="where.status"
      placeholder="状态"
      style="width: 120px"
      @change="reload"
    >
      <a-select-option :value="1">上架</a-select-option>
      <a-select-option :value="0">下架</a-select-option>
    </a-select>
  </a-space>
</template>

<script lang="ts" setup>
  import { PlusOutlined } from '@ant-design/icons-vue';
  import { ShopPointsProductParam } from '@/api/shop/shopPointsProduct';
  import useSearch from '@/utils/use-search';

  const props = withDefaults(
    defineProps<{
      selection?: any[];
    }>(),
    {}
  );

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

  // 表单数据
  const { where } = useSearch<ShopPointsProductParam>({
    productName: '',
    status: undefined
  });

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

  const openAdd = () => {
    emit('add');
  };
</script>
