gaoluyang
昨天 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script lang="ts" setup>
import type { SelectValue } from 'ant-design-vue/es/select';
 
import type { MesTmToolTypeApi } from '#/api/mes/tm/tool/type';
 
import { onMounted, ref } from 'vue';
 
import { Select } from 'ant-design-vue';
 
import { getToolTypeSimpleList } from '#/api/mes/tm/tool/type';
 
withDefaults(
  defineProps<{
    allowClear?: boolean;
    disabled?: boolean;
    modelValue?: number;
    placeholder?: string;
  }>(),
  {
    allowClear: true,
    disabled: false,
    modelValue: undefined,
    placeholder: '请选择工具类型',
  },
);
const emit = defineEmits<{
  change: [row?: MesTmToolTypeApi.ToolType];
  'update:modelValue': [value?: number];
}>();
const list = ref<MesTmToolTypeApi.ToolType[]>([]); // 工具类型列表
 
/** 加载工具类型列表 */
async function getList() {
  list.value = await getToolTypeSimpleList();
}
 
/** 处理工具类型选择变化 */
function handleChange(value: SelectValue) {
  const toolTypeId = typeof value === 'number' ? value : undefined;
  emit('update:modelValue', toolTypeId);
  emit(
    'change',
    list.value.find((item) => item.id === toolTypeId),
  );
}
 
onMounted(getList);
</script>
 
<template>
  <Select
    :allow-clear="allowClear"
    :disabled="disabled"
    :field-names="{ label: 'name', value: 'id' }"
    :options="list"
    :placeholder="placeholder"
    :value="modelValue"
    class="w-full"
    option-filter-prop="name"
    show-search
    @change="handleChange"
  />
</template>