<template>
  <div style="display: flex; justify-content: space-between">
    <a-space style="flex-wrap: wrap">
      <a-radio-group v-model:value="where.status" @change="search">
        <a-radio-button value="0">待处理</a-radio-button>
        <a-radio-button value="1">已完成</a-radio-button>
      </a-radio-group>
      <a-button
        danger
        v-if="selection?.length"
        class="ele-btn-icon"
        @click="removeBatch"
      >
        <template #icon>
          <DeleteOutlined />
        </template>
        <span>批量删除</span>
      </a-button>
      <!--      <a-button v-if="selection?.length" danger @click="removeBatchClose"-->
      <!--        >批量关单</a-button-->
      <!--      >-->
    </a-space>
    <a-space :size="10" style="flex-wrap: wrap; margin-right: 20px">
      <DictSelect
        dict-code="taskType"
        v-model:value="where.taskType"
        :placeholder="`选择分类`"
        style="width: 200px"
        @change="search"
      />
      <SelectApp
        :placeholder="`按项目筛选`"
        v-model:value="where.appName"
        @done="chooseApp"
      />
      <a-input-search
        allow-clear
        placeholder="工单号|标题|项目名称"
        v-model:value="where.keywords"
        @pressEnter="search"
        @search="search"
      />
      <a-button @click="reset">重置</a-button>
    </a-space>
  </div>
</template>

<script lang="ts" setup>
  import { TaskParam } from '@/api/oa/task/model';
  import useSearch from '@/utils/use-search';
  import { DeleteOutlined } from '@ant-design/icons-vue';
  import { App } from '@/api/oa/app/model';
  import DictSelect from '@/components/DictSelect/index.vue';
  import { User } from '@/api/system/user/model';

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

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

  // 表单数据
  const { where, resetFields } = useSearch<TaskParam>({
    keywords: '',
    status: undefined,
    commander: undefined
  });

  const removeBatch = () => {
    emit('remove');
  };

  const chooseApp = (data: App) => {
    where.appName = data.appName;
    where.appId = data.appId;
    emit('search', where);
  };

  const chooseCommander = (data: User) => {
    console.log(data);
    where.nickname = data.nickname;
    where.commander = data.userId;
    emit('search', where);
  };

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

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

  if (props.status == undefined) {
    where.status = '0';
  }
</script>
