<!-- 选择下拉框 -->
<template>
  <a-select
    show-search
    optionFilterProp="label"
    :options="data"
    allow-clear
    :value="value"
    :placeholder="placeholder"
    @update:value="updateValue"
    @blur="onBlur"
  />
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { SelectProps } from 'ant-design-vue';
  import { pageEquipment } from '@/api/apps/equipment';

  const emit = defineEmits<{
    (e: 'update:value', value: string): void;
    (e: 'blur'): void;
  }>();

  withDefaults(
    defineProps<{
      value?: string;
      placeholder?: string;
      dictCode?: string;
    }>(),
    {
      placeholder: '请选择设备型号'
    }
  );

  // 字典数据
  const data = ref<SelectProps['options']>([]);
  pageEquipment({}).then((res) => {
    res?.list.map((d) => {
      data.value?.push({
        comments: d.comments,
        label: d.equipmentCode,
        text: d.equipmentCode,
        value: d.equipmentCode
      });
    });
  });
  /* 更新选中数据 */
  const updateValue = (value: string) => {
    console.log(value);
    emit('update:value', value);
  };
  /* 失去焦点 */
  const onBlur = () => {
    emit('blur');
  };
</script>
