修改科室管理主界面科室分类和编辑科室的字典

This commit is contained in:
叶锦涛
2025-11-14 09:25:37 +08:00
parent a794cd0ce3
commit 8b848f787a

View File

@@ -177,14 +177,34 @@ initOption();
// 使用系统标准字典获取方法 // 使用系统标准字典获取方法
const { organization_class } = proxy.useDict('organization_class'); const { organization_class } = proxy.useDict('organization_class');
// 统一的科室分类字典处理函数
function processOrganizationClassDict(dictData) {
return dictData.map(item => ({
value: String(item.value), // 将值转换为字符串类型,确保与表单值类型一致
info: item.label // 使用dict_label的值作为显示文本
}));
}
// 监听字典数据变化 // 监听字典数据变化
watch(() => organization_class.value, (newVal) => { watch(() => organization_class.value, (newVal) => {
if (newVal && newVal.length > 0) { if (newVal && newVal.length > 0) {
// 转换为组件需要的格式使用dict_label作为label // 转换为组件需要的格式
classEnumOption.value = newVal.map(item => ({ classEnumOption.value = processOrganizationClassDict(newVal);
value: item.value,
info: item.label // 使用dict_label的值作为显示文本 // 同步更新表格中显示的科室分类文本,确保主界面显示与字典一致
})); if (organization.value && organization.value.length > 0) {
organization.value = organization.value.map(item => {
// 保留原有显示文本作为基础
const originalText = item.classEnum_dictText || '';
// 获取字典中的对应文本
const dictLabel = getDictLabel(item.classEnum);
// 只有在字典中找到匹配值时才替换,否则保留原有文本
return {
...item,
classEnum_dictText: dictLabel || originalText
};
});
}
} }
}, { immediate: true }); }, { immediate: true });
@@ -192,9 +212,17 @@ function initOption() {
if (orgTypeOption.value.length == 0) { if (orgTypeOption.value.length == 0) {
initOrgTypeOption().then((res) => { initOrgTypeOption().then((res) => {
orgTypeOption.value = res.data.organizationTypeOptions; orgTypeOption.value = res.data.organizationTypeOptions;
// 科室分类优先使用字典数据,如果没有再使用接口返回的数据
if (!classEnumOption.value || classEnumOption.value.length === 0) { // 优先使用系统标准字典数据,确保编辑和新增科室使用相同的分类字典
classEnumOption.value = res.data.organizationClassOptions || []; if (organization_class.value && organization_class.value.length > 0) {
classEnumOption.value = processOrganizationClassDict(organization_class.value);
} else if (res.data.organizationClassOptions && res.data.organizationClassOptions.length > 0) {
// 只有在字典数据不存在时才使用接口返回的数据作为备选
// 将接口返回的科室分类选项值也转换为字符串类型,保持一致性
classEnumOption.value = res.data.organizationClassOptions.map(item => ({
...item,
value: String(item.value)
}));
} }
}); });
} }
@@ -205,10 +233,41 @@ function reset() {
orgRef.value.resetFields(); orgRef.value.resetFields();
} }
// 从字典数据中查找对应的值,处理类型转换
function getDictLabel(value) {
if (!value || !organization_class.value || organization_class.value.length === 0) return '';
// 尝试进行类型转换比较,处理可能的字符串/数字不匹配问题
const stringValue = String(value);
const dict = organization_class.value.find(item => {
// 比较转换后的字符串值
return String(item.value) === stringValue;
});
return dict ? dict.label : '';
}
function getPageList() { function getPageList() {
loading.value = false; loading.value = false;
getList(queryParams.value).then((res) => { getList(queryParams.value).then((res) => {
organization.value = res.data.records; // 处理返回的科室数据,确保科室分类显示与系统标准字典一致
const processedData = res.data.records.map(item => {
// 保留原有显示文本作为基础
const originalText = item.classEnum_dictText || '';
// 如果系统标准字典存在,尝试使用字典中的文本覆盖原有文本
if (organization_class.value && organization_class.value.length > 0) {
const dictLabel = getDictLabel(item.classEnum);
// 只有在字典中找到匹配值时才替换,否则保留原有文本
return {
...item,
classEnum_dictText: dictLabel || originalText
};
}
return item;
});
organization.value = processedData;
total.value = res.data.total; total.value = res.data.total;
loading.value = false; loading.value = false;
}); });
@@ -233,7 +292,8 @@ function handelEdit(row) {
form.value.ybNo = row.ybNo; form.value.ybNo = row.ybNo;
form.value.ybName = row.ybName; form.value.ybName = row.ybName;
form.value.typeEnum = row.typeEnum; form.value.typeEnum = row.typeEnum;
form.value.classEnum = row.classEnum; // 确保科室分类值的类型正确,使其能正确匹配下拉选项中的值
form.value.classEnum = row.classEnum !== undefined ? String(row.classEnum) : undefined;
form.value.busNoParent = row.busNo.split('.').length > 1 ? row.busNo.split('.')[0] : undefined; form.value.busNoParent = row.busNo.split('.').length > 1 ? row.busNo.split('.')[0] : undefined;
}, 50); }, 50);
} }