<template>
  <div style="display: flex; justify-content: space-between">
    <a-space :size="20" style="flex-wrap: wrap">
      <a-tabs tabPosition="top" v-model:activeKey="active" @change="onTabs">
        <a-tab-pane :key="0" tab="任务大厅" />
        <a-tab-pane :key="1" tab="已领取" />
      </a-tabs>
    </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"
      />
      <SelectCompany
        :placeholder="`按客户筛选`"
        v-model:value="where.companyName"
        @done="chooseCompanyName"
      />
      <!--      <SelectApp-->
      <!--        :placeholder="`按应用筛选`"-->
      <!--        v-model:value="where.appName"-->
      <!--        @done="chooseApp"-->
      <!--      />-->
      <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 { Company } from '@/api/system/company/model';
  import SelectCompany from '@/components/SelectCompany/index.vue';
  // import SelectApp from '@/components/SelectApp/index.vue';
  import DictSelect from '@/components/DictSelect/index.vue';
  import { App } from '@/api/oa/app/model';
  import { useUserStore } from '@/store/modules/user';
  import { ref } from 'vue';

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

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

  const userStore = useUserStore();
  const active = ref<number>(0);

  const chooseCompanyName = (item: Company) => {
    where.companyId = item.companyId;
    where.companyName = item.companyName;
    search();
  };

  const chooseApp = (item: App) => {
    where.appId = item.appId;
    where.appName = item.appName;
    search();
  };

  const onTabs = () => {
    if (active.value == 1) {
      where.commander = userStore.info?.userId;
    } else {
      where.commander = undefined;
      where.progress = undefined;
    }
    search();
  };

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

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