From c50c0d04a4e922b34ef2a8af103160911fff9376 Mon Sep 17 00:00:00 2001 From: yuchenglong Date: Tue, 13 Jan 2026 15:05:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E9=99=A4=E5=BC=83?= =?UTF-8?q?=E9=80=89=E4=BD=93=E6=A3=80=E5=A5=97=E9=A4=90=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hisApi.ts | 23 +++++++++++++++++++ src/pages/U4/u4.tsx | 56 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/api/hisApi.ts b/src/api/hisApi.ts index 54557da..6d9a794 100644 --- a/src/api/hisApi.ts +++ b/src/api/hisApi.ts @@ -120,6 +120,11 @@ export interface SignInResponse { is_success: number; // 0-成功 1-失败 } +// 移除可选套餐响应 +export interface RemoveOptionalResponse { + is_success: number; // 1-成功 0-失败 +} + // 创建axios实例 function createAxiosInstance(baseURL: string): AxiosInstance { const instance = axios.create({ @@ -374,5 +379,23 @@ export async function signIn( return response.data; } +/** + * 10. 移除弃选体检套餐选项 + * @param physical_exam_id 体检ID + * @param combination_code_ids 组合代码(多个项目以逗号分割,例如:123,456) + */ +export async function removeOptionalItems( + physical_exam_id: number, + combination_code_ids: string +): Promise> { + const response = await axiosInstance.post< + ApiResponse + >("exam-optional-remove", { + physical_exam_id, + combination_code_ids, + }); + return response.data; +} + // 导出axios实例,以便需要时进行自定义配置 export { axiosInstance }; diff --git a/src/pages/U4/u4.tsx b/src/pages/U4/u4.tsx index 7f04c90..6c4b370 100644 --- a/src/pages/U4/u4.tsx +++ b/src/pages/U4/u4.tsx @@ -6,6 +6,7 @@ import DecorLine from "../../components/DecorLine"; import LongButton from "../../components/LongButton"; import radio0 from "../../assets/radio-0.png"; import radio1 from "../../assets/radio-1.png"; +import { removeOptionalItems } from "../../api/hisApi"; interface testType { id: number; title: string; @@ -19,8 +20,56 @@ const U4: React.FC = () => { const location = useLocation(); const optionalData = (location.state as any)?.optionalData; const [test, setTest] = React.useState([]); - const handleConfirm = () => { - navigate("/UI6"); + const [selectedId, setSelectedId] = React.useState(null); + const [isSubmitting, setIsSubmitting] = React.useState(false); + + const handleConfirm = async () => { + if (isSubmitting) return; // 防止重复提交 + + if (selectedId === null || !test.length) { + navigate("/UI6"); + return; + } + + setIsSubmitting(true); + + try { + // 找出未选择的项目 + const unselectedItems = test.filter((item) => item.id !== selectedId); + + // 如果有未选的项目,调用移除接口 + if (unselectedItems.length > 0) { + // 拼接未选项目的combination_code + const combinationCodeIds = unselectedItems + .map((item) => item.id) + .join(","); + + // 获取physical_exam_id + const physical_exam_id = test[0]?.exam_id; + + if (physical_exam_id) { + window.electronAPI.log( + "info", + `开始移除未选项目: ${combinationCodeIds}` + ); + // 调用移除接口 + await removeOptionalItems(physical_exam_id, combinationCodeIds); + window.electronAPI.log( + "info", + `成功移除未选项目: ${combinationCodeIds}` + ); + } + } else { + window.electronAPI.log("info", "没有未选项目需要移除"); + } + } catch (error) { + window.electronAPI.log("error", `移除未选项目失败: ${String(error)}`); + // 即使移除失败,也继续流程 + } finally { + // 无论成功或失败,都跳转到下一页 + setIsSubmitting(false); + navigate("/UI6"); + } }; React.useEffect(() => { if ( @@ -40,7 +89,6 @@ const U4: React.FC = () => { navigate("/UI6"); } }, []); - const [selectedId, setSelectedId] = React.useState(null); // 当 test 更新后,如果没有选择项则默认选择第一个 React.useEffect(() => { @@ -50,7 +98,7 @@ const U4: React.FC = () => { }, [test]); React.useEffect(() => { - console.log("选择的项目", selectedId); + window.electronAPI.log("info", `选择的项目: ${selectedId}`); }, [selectedId]); return (