更新结构
This commit is contained in:
@@ -33,28 +33,72 @@ const UI6: React.FC = () => {
|
|||||||
}
|
}
|
||||||
const res = await getPackagItemDetail(id_no as string);
|
const res = await getPackagItemDetail(id_no as string);
|
||||||
if (res.Status === 200) {
|
if (res.Status === 200) {
|
||||||
localStorage.setItem("package_code", res.Data.packagItemInfo.package_code || "");
|
localStorage.setItem(
|
||||||
localStorage.setItem("selectedExamId", res.Data.packagItemInfo.physical_exam_id.toString() || "0");
|
"package_code",
|
||||||
// 处理数据:将 project_id 和 project_name 字符串分离为数组
|
res.Data.packagItemInfo.package_code || ""
|
||||||
const processedData = res.Data.listPackDetail.map((item: any) => {
|
);
|
||||||
// 将 project_id 字符串按中文顿号分割为数组
|
localStorage.setItem(
|
||||||
const project_ids = item.project_id
|
"selectedExamId",
|
||||||
? item.project_id.split("、").map((id: string) => id.trim()).filter((id: string) => id)
|
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 projectNames: string[] = item.project_name
|
||||||
const project_names = item.project_name
|
? String(item.project_name)
|
||||||
? item.project_name.split("、").map((name: string) => name.trim()).filter((name: string) => name)
|
.split("、")
|
||||||
|
.map((name: string) => name.trim())
|
||||||
|
.filter((name: string) => name)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return {
|
if (!departmentMap.has(deptId)) {
|
||||||
...item,
|
departmentMap.set(deptId, {
|
||||||
project_ids,
|
department_id: deptId,
|
||||||
project_names,
|
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);
|
setPackageInfo(res.Data.packagItemInfo);
|
||||||
} else {
|
} else {
|
||||||
alert(`获取列表数据失败: ${res.Message}`);
|
alert(`获取列表数据失败: ${res.Message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user