<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
<!--    <a-button class="ele-btn-icon">-->
<!--      <template #icon>-->
<!--        <QrcodeOutlined />-->
<!--      </template>-->
<!--      <span>批量生产二维码</span>-->
<!--    </a-button>-->
    <!--    <a-space>-->
    <!--      <a-button @click="onTab(undefined)"-->
    <!--        >设备总数：{{ equipmentData.totalNum }}</a-button-->
    <!--      >-->
    <!--      <a-button @click="onTab(0)">闲置：{{ equipmentData.idleNum }}</a-button>-->
    <!--      <a-button @click="onTab(1)"-->
    <!--        >已达报废年限：{{ equipmentData.scrapNum }}</a-button-->
    <!--      >-->
    <!--      <a-button @click="onTab(2)"-->
    <!--        >已注销：{{ equipmentData.totalNum2 }}</a-button-->
    <!--      >-->
    <!--      <a-button @click="onTab(3)"-->
    <!--        >已转卖：{{ equipmentData.totalNum3 }}</a-button-->
    <!--      >-->
    <!--      <a-button @click="onTab(4)">在用：{{ equipmentData.totalNum4 }}</a-button>-->
    <!--      <a-button @click="onTab(5)"-->
    <!--        >已停工：{{ equipmentData.totalNum5 }}</a-button-->
    <!--      >-->
    <!--          <span>自有设备：3</span>-->
    <!--          <span>租赁设备：1</span>-->
    <!--    </a-space>-->
  </a-space>
</template>

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

  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 active = ref<any>(undefined);

  let equipmentData = reactive({
    totalNum: 0,
    idleNum: 0,
    scrapNum: 0,
    totalNum2: 0,
    totalNum3: 0,
    totalNum4: 0,
    totalNum5: 0
  });

  const getData = async () => {
    const res = await towerEquipmentData();
    for (let key in equipmentData) equipmentData[key] = res[key];
  };

  const onTab = (type: any) => {
    active.value = type;
    where.status = active.value;
    emit('search', {
      ...where
    });
  };

  /* 搜索 */
  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');
  };

  getData();

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

<style lang="less" scoped>
  .count {
    display: flex;
    .btn {
      margin: 0 12px;
      padding: 6px 18px;
      background-color: #f3f3f3;
      border-radius: 4px;
      cursor: pointer;
      display: flex;
      align-items: center;
      font-size: 16px;
      .divider {
        width: 4px;
        height: 15px;
        border-radius: 8px;
        margin-right: 8px;
        background-color: #16a90b;
      }
      .active {
        color: #16a90b;
      }
    }
  }
</style>
