75 lines
1.8 KiB
Vue
Raw Normal View History

2025-10-30 18:15:17 +08:00
<!--仪器组件的封装-->
<template>
2025-10-31 18:07:30 +08:00
<SelectTable v-model:data="modelValue" :fields="fields" :tableData="instrOptions" label="yqmc" :size="props.size"
value="yq" objKey="yq" :border="true" :width="props.width" placeholder="请选择仪器" :clearable="props.clearable"
@getDataValue="getDataValue" />
</template>
<script setup lang="ts">
import SelectTable from '@/components/SelectTable/index.vue';
import { getGroupInstrdList } from '@/api/liswork/work/LisWork';
2025-10-31 18:07:30 +08:00
import { Emits, Props, Field } from '@/types';
2025-10-31 09:47:06 +08:00
import { ref, watch, onMounted } from 'vue';
2025-10-31 18:07:30 +08:00
2025-10-31 09:47:06 +08:00
const modelValue = ref<string | null>('');
2025-10-31 18:07:30 +08:00
const props = withDefaults(defineProps<{
width?: string | number,
size?: string,
clearable?: boolean,
instrGroup?: string | number, //部门组代号
2025-12-08 17:49:43 +08:00
data: string | undefined
2025-10-31 18:07:30 +08:00
}>(), {
width: '100%',
size: 'default',
2025-12-08 17:49:43 +08:00
clearable: false,
data: ''
2025-10-31 18:07:30 +08:00
})
const instrOptions = ref<Array<{ yq: string; yqmc: string }>>([]);
const fields = ref(
[
2025-10-31 09:47:06 +08:00
{ prop: 'yq', label: '代号', width: 80, enablePinyinSearch: true },
{ prop: 'yqmc', label: '名称', width: 150, enablePinyinSearch: true },
2025-10-31 18:07:30 +08:00
]
)
2025-10-30 18:15:17 +08:00
const emits = defineEmits<Emits>();
2025-10-31 09:47:06 +08:00
const getYqConfig = () => {
2025-10-31 18:07:30 +08:00
const data = {
lisgroup: props.instrGroup
}
getGroupInstrdList(data)
.then((res: any) => {
if (res.code == 0) {
instrOptions.value = res.data.map((item: any) => ({
yq: item.yq.trim(),
yqmc: item.yqmc
}))
}
})
}
2025-10-30 18:15:17 +08:00
const getDataValue = (val: any) => {
2025-10-31 18:07:30 +08:00
emits('update:data', val.yq);
2025-10-30 18:15:17 +08:00
emits('getDataValue', val);
};
2025-11-03 12:12:47 +08:00
watch(() => props.data, (val) => {
modelValue.value = val;
});
onMounted(() => {
2025-10-31 09:47:06 +08:00
// 初始化时同步一次父级值(如果有)到内部 modelValue
if (props.data !== undefined && props.data !== null) {
modelValue.value = props.data as any;
}
2025-10-31 18:07:30 +08:00
getYqConfig();
});
2025-10-30 18:15:17 +08:00
</script>