<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <a-button type="primary" class="ele-btn-icon">
      <template #icon>
        <QrcodeOutlined />
      </template>
      <span>批量生产二维码</span>
    </a-button>
    <a-alert type="success" style="margin-left: 105px">
      <template #icon><smile-outlined /></template>
      <template #message>
        <a-space>
          <span>设备总数：4</span>
          <span>在用数：1</span>
          <span>闲置数：1</span>
          <span>报废数：1</span>
          <span>转卖数：1</span>
          <span>注销数：0</span>
          <span>自有设备：3</span>
          <span>租赁设备：1</span>
        </a-space>
      </template>
    </a-alert>
  </a-space>
</template>

<script lang="ts" setup>
  import { QrcodeOutlined } from '@ant-design/icons-vue';
  import useSearch from '@/utils/use-search';
  import { ref, watch } from 'vue';
  import { TowerEquipmentParam } from '@/api/tower/equipment/model';

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

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

  // 表单数据
  const { where, resetFields } = useSearch<TowerEquipmentParam>({
    equipmentId: undefined,
    name: undefined,
    keywords: ''
  });
  // 下来选项
  const type = ref('keywords');
  // 搜索内容
  const searchText = ref('');
  // 日期范围选择
  // const dateRange = ref<[string, string]>(['', '']);
  // 状态
  const status = ref<number>();

  /* 搜索 */
  const search = () => {
    resetFields();
    // const [d1, d2] = dateRange.value ?? [];
    if (type.value == 'keywords') {
      where.keywords = searchText.value;
    }
    emit('search', {
      ...where
    });
  };

  // 发布设备
  const add = () => {
    emit('add');
  };

  const handleStatus = () => {
    emit('update', status.value);
  };

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

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