200 检验项目设置-》检验项目:下级医技类型字段未做成下拉选项并取值于检验类型字段选中项关联的子项
This commit is contained in:
@@ -245,18 +245,22 @@
|
|||||||
<el-table-column label="检验类型" min-width="120" align="center">
|
<el-table-column label="检验类型" min-width="120" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<template v-if="editingRowId === row.id">
|
<template v-if="editingRowId === row.id">
|
||||||
<el-select v-model="row.inspectionTypeId" placeholder="选择检验类型" size="small" style="width: 100%;" @change="(val) => { const selected = testTypes.find(t => t.id === val); row.testType = selected ? selected.label : ''; }">
|
<el-select v-model="row.inspectionTypeId" placeholder="选择检验类型" size="small" style="width: 100%;" filterable
|
||||||
|
clearable
|
||||||
|
@change="(val) => handleParentChange(val, row)">
|
||||||
<el-option label="选择检验类型" value="" />
|
<el-option label="选择检验类型" value="" />
|
||||||
|
<!-- 使用 name 作为显示,id 作为值 -->
|
||||||
<el-option
|
<el-option
|
||||||
v-for="type in testTypes"
|
v-for="item in parentTypeOptions"
|
||||||
:key="type.id"
|
:key="item.id"
|
||||||
:label="type.label"
|
:label="item.name"
|
||||||
:value="type.id"
|
:value="item.id"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</el-select>
|
</el-select>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
{{ row.testType }}
|
{{ row.testType || '-' }}
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -331,13 +335,32 @@
|
|||||||
<el-table-column label="下级医技类型" min-width="100" align="center">
|
<el-table-column label="下级医技类型" min-width="100" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<template v-if="editingRowId === row.id">
|
<template v-if="editingRowId === row.id">
|
||||||
<el-input v-model="row.subType" size="small" />
|
<el-select
|
||||||
|
v-model="row.subItemId"
|
||||||
|
placeholder="请先选大类"
|
||||||
|
size="small"
|
||||||
|
style="width: 100%"
|
||||||
|
filterable
|
||||||
|
clearable
|
||||||
|
:disabled="!row.inspectionTypeId"
|
||||||
|
:loading="row.loadingSubItems"
|
||||||
|
@change="handleEditRow"
|
||||||
|
>
|
||||||
|
<!-- 数据源来自行内动态加载的 subItemOptions -->
|
||||||
|
<el-option
|
||||||
|
v-for="item in (row.subItemOptions || [])"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
{{ row.sub医技Type || '-' }}
|
{{ row.subItemName || '-' }}
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="备注" min-width="100" align="center">
|
<el-table-column label="备注" min-width="100" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<template v-if="editingRowId === row.id">
|
<template v-if="editingRowId === row.id">
|
||||||
@@ -1041,6 +1064,121 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// 【修复】级联下拉框逻辑 (包含直接请求代码)
|
||||||
|
// ==============================
|
||||||
|
|
||||||
|
// 1. 定义响应式数据
|
||||||
|
const parentTypeOptions = ref([]);
|
||||||
|
|
||||||
|
// 2. 【核心】直接发送请求的方法
|
||||||
|
// 这里直接使用 request 工具,不依赖外部 api 文件
|
||||||
|
const fetchInspectionTypesRequest = (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/system/inspection-type/list', // 你的后端接口地址
|
||||||
|
method: 'get',
|
||||||
|
params: params
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3. 加载所有顶级大类
|
||||||
|
const loadParentTypes = async () => {
|
||||||
|
try {
|
||||||
|
// 【发送请求】不传参数,获取所有数据
|
||||||
|
const res = await fetchInspectionTypesRequest({});
|
||||||
|
|
||||||
|
let allData = [];
|
||||||
|
// 兼容多种返回格式
|
||||||
|
if (res.code === 200) {
|
||||||
|
if(res.data && Array.isArray(res.data)) allData = res.data;
|
||||||
|
else if(res.data && res.data.rows) allData = res.data.rows;
|
||||||
|
else if(res.data && res.data.data && Array.isArray(res.data.data)) allData = res.data.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤:只保留 parentId 为 null/undefined 的记录作为“大类”
|
||||||
|
parentTypeOptions.value = allData.filter(item =>
|
||||||
|
item.parentId === null || item.parentId === undefined || item.parentId === ''
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error('网络异常,加载大类失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 4. 处理大类改变,联动加载子类
|
||||||
|
const handleParentChange = async (selectedId, row) => {
|
||||||
|
// A. 更新当前行的显示名称
|
||||||
|
const selected = parentTypeOptions.value.find(t => t.id === selectedId);
|
||||||
|
row.inspectionTypeName = selected ? selected.name : '';
|
||||||
|
|
||||||
|
// B. 【重要】重置下级数据
|
||||||
|
row.subItemId = '';
|
||||||
|
row.subItemName = '';
|
||||||
|
row.subItemOptions = [];
|
||||||
|
|
||||||
|
if (!selectedId) return;
|
||||||
|
|
||||||
|
// C. 设置加载状态
|
||||||
|
row.loadingSubItems = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 【发送请求】传入 parentId 参数获取子类
|
||||||
|
const res = await fetchInspectionTypesRequest({ parentId: selectedId });
|
||||||
|
|
||||||
|
let subData = [];
|
||||||
|
if (res.code === 200) {
|
||||||
|
if(res.data && Array.isArray(res.data)) subData = res.data;
|
||||||
|
else if(res.data && res.data.rows) subData = res.data.rows;
|
||||||
|
else if(res.data && res.data.data && Array.isArray(res.data.data)) subData = res.data.data;
|
||||||
|
|
||||||
|
row.subItemOptions = subData;
|
||||||
|
|
||||||
|
// 可选优化:如果子类只有一个,自动选中
|
||||||
|
if (subData.length === 1) {
|
||||||
|
row.subItemId = subData[0].id;
|
||||||
|
row.subItemName = subData[0].name;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ElMessage.info('该分类下暂无子项目');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error('加载子项目失败');
|
||||||
|
} finally {
|
||||||
|
row.loadingSubItems = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 5. 点击编辑按钮时触发
|
||||||
|
const handleEditRow = (row) => {
|
||||||
|
if (editingRowId.value && editingRowId.value !== row.id) {
|
||||||
|
ElMessage.warning('请先保存或取消当前正在编辑的行');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
editingRowId.value = row.id;
|
||||||
|
|
||||||
|
// 初始化行内属性
|
||||||
|
if (!row.subItemOptions) row.subItemOptions = [];
|
||||||
|
row.loadingSubItems = false;
|
||||||
|
|
||||||
|
// 回显名称
|
||||||
|
if (row.inspectionTypeId && !row.inspectionTypeName) {
|
||||||
|
const p = parentTypeOptions.value.find(i => i.id === row.inspectionTypeId);
|
||||||
|
if (p) row.inspectionTypeName = p.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.subItemId && row.subItemOptions.length > 0) {
|
||||||
|
const s = row.subItemOptions.find(i => i.id === row.subItemId);
|
||||||
|
if (s) row.subItemName = s.name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
// ... 其他初始化代码
|
||||||
|
loadParentTypes(); // <--- 确保这一行存在
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// 样本类型数据
|
// 样本类型数据
|
||||||
const sampleTypes = ref([
|
const sampleTypes = ref([
|
||||||
{ value: '血液', label: '血液' },
|
{ value: '血液', label: '血液' },
|
||||||
@@ -1154,7 +1292,7 @@ const loadObservationItems = async (resetPage = false) => {
|
|||||||
testType: item.inspectionTypeId_dictText || item.testType || '', // 优先使用字典翻译字段
|
testType: item.inspectionTypeId_dictText || item.testType || '', // 优先使用字典翻译字段
|
||||||
inspectionTypeId: item.inspectionTypeId || null, // 检验类型ID
|
inspectionTypeId: item.inspectionTypeId || null, // 检验类型ID
|
||||||
package: '',
|
package: '',
|
||||||
sampleType: item.specimenCode_dictText || '',
|
sampleType: item.specimenCode || '',
|
||||||
amount: parseFloat(item.retailPrice || 0),
|
amount: parseFloat(item.retailPrice || 0),
|
||||||
sortOrder: item.sortOrder || null,
|
sortOrder: item.sortOrder || null,
|
||||||
serviceRange: item.serviceRange || '全部',
|
serviceRange: item.serviceRange || '全部',
|
||||||
@@ -1782,7 +1920,7 @@ const saveItem = async (item) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.testType) {
|
if (!item.inspectionTypeId) {
|
||||||
ElMessage.error('检验类型不能为空');
|
ElMessage.error('检验类型不能为空');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user