<!-- 搜索表单 -->
<template>
  <div class="search">
    <a-space :size="10" style="flex-wrap: wrap">
      <!--      <a-button-->
      <!--        danger-->
      <!--        type="primary"-->
      <!--        class="ele-btn-icon"-->
      <!--        :disabled="selection.length === 0"-->
      <!--        @click="removeBatch"-->
      <!--      >-->
      <!--        <template #icon>-->
      <!--          <DeleteOutlined />-->
      <!--        </template>-->
      <!--        <span>批量删除</span>-->
      <!--      </a-button>-->
      <SelectUser
        :placeholder="`选择买家`"
        v-model:value="where.playerNickname"
        @done="chooseUserId"
      />
      <a-select
        v-model:value="where.scene"
        style="width: 180px"
        placeholder="请选择收益类型"
        allow-clear
        @change="handleWeek"
      >
        <a-select-option :value="10">推广收益</a-select-option>
        <a-select-option :value="20">团队收益</a-select-option>
        <a-select-option :value="40">区域业绩提成</a-select-option>
        <a-select-option :value="41">市级业绩提成</a-select-option>
        <a-select-option :value="42">省级级业绩提成</a-select-option>
        <a-select-option :value="50">充值收益</a-select-option>
        <a-select-option :value="60">门店服务费</a-select-option>
      </a-select>
      <a-input-search
        allow-clear
        placeholder="请输入订单号"
        v-model:value="where.keywords"
        @pressEnter="search"
        @search="search"
        style="width: 240px"
      />
      <a-button @click="reset">重置</a-button>
    </a-space>
  </div>
</template>

<script lang="ts" setup>
  import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import { ref, watch } from 'vue';
  import { OrderGoods, OrderGoodsParam } from '@/api/order/goods/model';
  import { countOrderGoods } from '@/api/apps/statistics';
  import { message } from 'ant-design-vue';
  import { Organization } from '@/api/system/organization/model';
  import { utils, writeFile } from 'xlsx';
  import { ProfitParam } from '@/api/love/profit/model';
  import { User } from "@/api/system/user/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<ProfitParam>({
    profitId: undefined,
    status: undefined,
    scene: undefined,
    keywords: undefined
  });
  // 下来选项
  // const categoryId = ref<number>(0);
  const post = ref<number>(0);
  const sign = ref<number>(0);
  const noSign = ref<number>(0);

  /* 搜索 */
  const search = () => {
    emit('search', {
      ...where
    });
  };

  const handleWeek = (index) => {
    where.scene = index;
    search();
  };

  const chooseUserId = (data: User) => {
    where.playerNickname = data.nickname;
    where.
    search();
  };

  /*  重置 */
  const reset = () => {
    resetFields();
    post.value = 0;
    sign.value = 0;
    noSign.value = 0;
    search();
  };

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

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