gaoluyang
9 天以前 86966ec9a83b93decbd93fc8ce2be1882d4c9775
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
64
65
66
67
68
69
70
71
72
73
74
75
76
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
 
import { MesQcResultValueType } from '@vben/constants';
 
import { RadioGroup, Select } from 'ant-design-vue';
 
import { getSimpleDictTypeList } from '#/api/system/dict/type';
 
defineOptions({ name: 'QcIndicatorResultSpecificationInput' });
 
const props = withDefaults(
  defineProps<{
    modelValue?: string;
    resultType?: number;
  }>(),
  {
    modelValue: undefined,
    resultType: undefined,
  },
);
const emit = defineEmits<{
  'update:modelValue': [value?: string];
}>();
 
const fileOptions = [
  { label: '图片/照片', value: 'IMG' },
  { label: '文件', value: 'FILE' },
];
const dictTypeOptions = ref<{ name?: string; type?: string }[]>([]);
 
const innerValue = computed({
  get: () => props.modelValue,
  set: (value?: string) => emit('update:modelValue', value),
});
 
/** 加载字典类型选项(仅字典类型结果值需要) */
async function loadDictTypeOptions() {
  if (dictTypeOptions.value.length > 0) {
    return;
  }
  dictTypeOptions.value = await getSimpleDictTypeList();
}
 
watch(
  () => props.resultType,
  (value) => {
    if (value === MesQcResultValueType.DICT) {
      void loadDictTypeOptions();
    }
  },
  { immediate: true },
);
</script>
 
<template>
  <RadioGroup
    v-if="resultType === MesQcResultValueType.FILE"
    v-model:value="innerValue"
    :options="fileOptions"
  />
  <Select
    v-else-if="resultType === MesQcResultValueType.DICT"
    v-model:value="innerValue"
    :field-names="{ label: 'name', value: 'type' }"
    :filter-option="
      (input: string, option: any) =>
        (option.name as string).toLowerCase().includes(input.toLowerCase())
    "
    :options="dictTypeOptions"
    allow-clear
    class="w-full"
    placeholder="请选择字典类型"
    show-search
  />
</template>