fix bug529
This commit is contained in:
@@ -13,6 +13,11 @@ import java.math.BigDecimal;
|
||||
@Accessors(chain = true)
|
||||
public class RequestFormDetailQueryDto {
|
||||
|
||||
/**
|
||||
* 诊疗活动定义ID(wor_service_request.activity_id,与开立检验时项目字典的 id / adviceDefinitionId 一致,用于编辑回显)
|
||||
*/
|
||||
private Long activityId;
|
||||
|
||||
/** 医嘱名称 */
|
||||
private String adviceName;
|
||||
|
||||
|
||||
@@ -207,6 +207,8 @@ const loadAllData = async () => {
|
||||
}
|
||||
applicationListAll.value = res.data?.records || [];
|
||||
totalCount.value = res.data?.total || 0;
|
||||
// 检验项目列表为异步加载,编辑回显必须在数据就绪后执行,否则已选区一直为空
|
||||
applyEditTransferSelection()
|
||||
} catch (e) {
|
||||
proxy.$message.error('获取检验项目列表失败');
|
||||
applicationListAll.value = [];
|
||||
@@ -343,43 +345,70 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
// 编辑模式下,回显已有数据
|
||||
/** 编辑弹窗:根据申请单明细把右侧「已选择」与 transferValue 对齐(依赖 applicationListAll 已加载) */
|
||||
const applyEditTransferSelection = () => {
|
||||
const newData = props.editData
|
||||
if (!newData?.requestFormId || !newData.requestFormDetailList?.length) {
|
||||
return
|
||||
}
|
||||
if (!applicationListAll.value.length) {
|
||||
return
|
||||
}
|
||||
const selectedIds = []
|
||||
for (const detail of newData.requestFormDetailList) {
|
||||
const idFromDetail = detail.activityId ?? detail.adviceDefinitionId
|
||||
let matched = null
|
||||
if (idFromDetail != null && idFromDetail !== '') {
|
||||
matched = applicationListAll.value.find(
|
||||
(item) => String(item.adviceDefinitionId) === String(idFromDetail)
|
||||
)
|
||||
}
|
||||
if (!matched && detail.adviceName) {
|
||||
matched = applicationListAll.value.find((item) => item.adviceName === detail.adviceName)
|
||||
}
|
||||
if (!matched && detail.adviceName) {
|
||||
const norm = (s) => String(s || '').trim()
|
||||
matched = applicationListAll.value.find(
|
||||
(item) => norm(item.adviceName) === norm(detail.adviceName)
|
||||
)
|
||||
}
|
||||
if (matched) {
|
||||
selectedIds.push(matched.adviceDefinitionId)
|
||||
}
|
||||
}
|
||||
const uniq = [...new Set(selectedIds)]
|
||||
transferValue.value = uniq
|
||||
if (newData.requestFormDetailList.length && uniq.length === 0) {
|
||||
console.warn(
|
||||
'[LaboratoryTests] 申请单明细未能在项目字典中匹配到项,请核对 activityId / 项目名称',
|
||||
newData.requestFormDetailList
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑模式下,回显已有数据(表单来自 descJson;项目选择在字典加载后由 applyEditTransferSelection 完成)
|
||||
watch(
|
||||
() => props.editData,
|
||||
(newData) => {
|
||||
if (!newData || !newData.requestFormId) return;
|
||||
if (!newData || !newData.requestFormId) return
|
||||
|
||||
// 解析 descJson 回填表单
|
||||
if (newData.descJson) {
|
||||
try {
|
||||
const obj = JSON.parse(newData.descJson);
|
||||
const obj = JSON.parse(newData.descJson)
|
||||
Object.keys(form).forEach((key) => {
|
||||
if (obj[key] !== undefined) {
|
||||
form[key] = obj[key];
|
||||
form[key] = obj[key]
|
||||
}
|
||||
});
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('解析 descJson 失败:', e);
|
||||
console.error('解析 descJson 失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 回填已选项目
|
||||
if (newData.requestFormDetailList && newData.requestFormDetailList.length > 0) {
|
||||
// 从全部数据中匹配已选项目
|
||||
const selectedIds = [];
|
||||
newData.requestFormDetailList.forEach((detail) => {
|
||||
const matched = applicationListAll.value.find(
|
||||
(item) => item.adviceName === detail.adviceName
|
||||
);
|
||||
if (matched) {
|
||||
selectedIds.push(matched.adviceDefinitionId);
|
||||
}
|
||||
});
|
||||
transferValue.value = selectedIds;
|
||||
}
|
||||
applyEditTransferSelection()
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
{ immediate: true, deep: true }
|
||||
)
|
||||
|
||||
// 编辑模式下,applicationListAll 加载完成后重新回显已选项目
|
||||
watch(
|
||||
|
||||
Reference in New Issue
Block a user