fix(#578): 请修复 Bug #578:[一般] [患者管理] 修改患者信息时,级联省市区回显为空,且详细地址字段发生重复、循环拼接
根因: - Bug 1 — 级联省市区回显为空:** `patientAddDialog.vue` 的 `convertAddressToCodes` 函数是存根(stub),始终返回 `null`,导致回显时级联选择器无法选中任何值。 - ### 修改文件 - `src/views/charge/outpatientregistration/components/patientAddDialog.vue` - | 位置 | 改动 | - |---|---| - | `convertAddressToCodes` 函数 | 从存根替换为递归名称→代码查找(`findCodeByName`),使用 `options.value`(pcas 数据树)按名称匹配返回 code | - | `setFormData`(级联回显块后) | 新增地址前缀剥离逻辑:用 `addressProvince`+`addressCity`+`addressDistrict`+`addressStreet` 拼接前缀,从全地址 `address` 中去除前缀,使 `form.value.address` 只保留用户输入的详细地址部分(如"村道120号") | - ### 验证 - `npx eslint` — 0 errors, 仅 pre-existing warnings 修复: - 修改相关代码文件
This commit is contained in:
@@ -1685,6 +1685,17 @@ function setFormData(rowData) {
|
||||
selectedOptions.value = codes.filter((code) => code !== null);
|
||||
}
|
||||
}
|
||||
|
||||
// 从全地址中提取详细的用户输入部分(去除省市区前缀),避免保存时重复拼接
|
||||
const addressPrefix = [
|
||||
rowData.addressProvince,
|
||||
rowData.addressCity,
|
||||
rowData.addressDistrict,
|
||||
rowData.addressStreet,
|
||||
].filter(Boolean).join('');
|
||||
if (rowData.address && addressPrefix && rowData.address.startsWith(addressPrefix)) {
|
||||
form.value.address = rowData.address.substring(addressPrefix.length);
|
||||
}
|
||||
|
||||
// 设置患者 ID 信息 - 如果没有 patientIdInfoList 则创建一个
|
||||
if (!form.value.patientIdInfoList || form.value.patientIdInfoList.length === 0) {
|
||||
@@ -1727,11 +1738,19 @@ function setFormData(rowData) {
|
||||
|
||||
// 将地址转换为级联选择器所需的代码
|
||||
function convertAddressToCodes(addressParts) {
|
||||
const findCodeByName = (data, name) => {
|
||||
for (const item of data) {
|
||||
if (item.name === name) return item.code;
|
||||
if (item.children) {
|
||||
const result = findCodeByName(item.children, name);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return addressParts.map((part) => {
|
||||
if (!part) return null;
|
||||
// 这里需要根据实际的地址名称找到对应的代码
|
||||
// 由于数据结构的复杂性,这里先返回空值
|
||||
return null;
|
||||
return findCodeByName(options.value, part);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user