更新结构
This commit is contained in:
@@ -33,28 +33,72 @@ const UI6: React.FC = () => {
|
||||
}
|
||||
const res = await getPackagItemDetail(id_no as string);
|
||||
if (res.Status === 200) {
|
||||
localStorage.setItem("package_code", res.Data.packagItemInfo.package_code || "");
|
||||
localStorage.setItem("selectedExamId", res.Data.packagItemInfo.physical_exam_id.toString() || "0");
|
||||
// 处理数据:将 project_id 和 project_name 字符串分离为数组
|
||||
const processedData = res.Data.listPackDetail.map((item: any) => {
|
||||
// 将 project_id 字符串按中文顿号分割为数组
|
||||
const project_ids = item.project_id
|
||||
? item.project_id.split("、").map((id: string) => id.trim()).filter((id: string) => id)
|
||||
localStorage.setItem(
|
||||
"package_code",
|
||||
res.Data.packagItemInfo.package_code || ""
|
||||
);
|
||||
localStorage.setItem(
|
||||
"selectedExamId",
|
||||
res.Data.packagItemInfo.physical_exam_id.toString() || "0"
|
||||
);
|
||||
|
||||
// 处理数据:按科室合并检查项目
|
||||
const departmentMap = new Map<
|
||||
number,
|
||||
{
|
||||
department_id: number;
|
||||
department_name: string;
|
||||
project_ids: string[];
|
||||
project_names: string[];
|
||||
}
|
||||
>();
|
||||
|
||||
res.Data.listPackDetail.forEach((item: any) => {
|
||||
const deptId = item.department_id;
|
||||
const deptName = item.department_name;
|
||||
|
||||
// 兼容旧格式(一个字符串里用顿号分隔)和新格式(每条记录一个项目)
|
||||
const projectIds: string[] = item.project_id
|
||||
? String(item.project_id)
|
||||
.split("、")
|
||||
.map((id: string) => id.trim())
|
||||
.filter((id: string) => id)
|
||||
: [];
|
||||
|
||||
// 将 project_name 字符串按中文顿号分割为数组
|
||||
const project_names = item.project_name
|
||||
? item.project_name.split("、").map((name: string) => name.trim()).filter((name: string) => name)
|
||||
const projectNames: string[] = item.project_name
|
||||
? String(item.project_name)
|
||||
.split("、")
|
||||
.map((name: string) => name.trim())
|
||||
.filter((name: string) => name)
|
||||
: [];
|
||||
|
||||
return {
|
||||
...item,
|
||||
project_ids,
|
||||
project_names,
|
||||
};
|
||||
if (!departmentMap.has(deptId)) {
|
||||
departmentMap.set(deptId, {
|
||||
department_id: deptId,
|
||||
department_name: deptName,
|
||||
project_ids: [],
|
||||
project_names: [],
|
||||
});
|
||||
}
|
||||
|
||||
const dept = departmentMap.get(deptId)!;
|
||||
|
||||
projectIds.forEach((id) => {
|
||||
if (!dept.project_ids.includes(id)) {
|
||||
dept.project_ids.push(id);
|
||||
}
|
||||
});
|
||||
|
||||
projectNames.forEach((name) => {
|
||||
if (!dept.project_names.includes(name)) {
|
||||
dept.project_names.push(name);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setListData(processedData);
|
||||
const mergedData = Array.from(departmentMap.values());
|
||||
|
||||
setListData(mergedData);
|
||||
setPackageInfo(res.Data.packagItemInfo);
|
||||
} else {
|
||||
alert(`获取列表数据失败: ${res.Message}`);
|
||||
|
||||
Reference in New Issue
Block a user