<!-- 搜索表单 -->
<template>
  <div style="display: flex; justify-content: space-between">
    <a-space :size="10" style="flex-wrap: wrap; margin-right: 20px">
      <a-button
        type="primary"
        class="ele-btn-icon"
        @click="add"
      >
        <template #icon>
          <PlusOutlined />
        </template>
        <span>创建</span>
      </a-button>
      <a-radio-group v-model:value="where.version" @change="handleSearch">
        <a-radio-button :value="99">我的收藏</a-radio-button>
        <a-radio-button :value="88">回收站</a-radio-button>
      </a-radio-group>
      <a-radio-group v-model:value="where.version" @change="handleSearch">
        <a-radio-button :value="100">全部</a-radio-button>
        <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-group>
      <a-input-search
        allow-clear
        placeholder="请输入关键词"
        v-model:value="where.keywords"
        @pressEnter="search"
        @search="search"
      />
    </a-space>
  </div>
</template>

<script lang="ts" setup>
  import { PlusOutlined } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import { ref, watch } from 'vue';
  import { CompanyParam } from '@/api/system/company/model';
  import { openNew } from "@/utils/common";

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

  const emit = defineEmits<{
    (e: 'search', where?: CompanyParam): void;
    (e: 'add'): void;
    (e: 'remove'): void;
    (e: 'update', status?: number): void;
    (e: 'import'): void;
  }>();

  // 表单数据
  const { where } = useSearch<CompanyParam>({
    companyId: undefined,
    companyName: undefined,
    keywords: '',
    authentication: undefined,
    version: 99,
    province: '',
    city: '',
    region: '',
    collection: undefined
  });
  const tenantId = ref<number>();
  if (localStorage.getItem('TenantId')) {
    tenantId.value = Number(localStorage.getItem('TenantId'));
  }

  // 新增
  const add = () => {
    // emit('add');
    openNew(`https://www.gxwebsoft.com/login`);
  };

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

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

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