添加移除弃选体检套餐选项功能
This commit is contained in:
@@ -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<ApiResponse<RemoveOptionalResponse>> {
|
||||
const response = await axiosInstance.post<
|
||||
ApiResponse<RemoveOptionalResponse>
|
||||
>("exam-optional-remove", {
|
||||
physical_exam_id,
|
||||
combination_code_ids,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// 导出axios实例,以便需要时进行自定义配置
|
||||
export { axiosInstance };
|
||||
|
||||
@@ -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<testType[]>([]);
|
||||
const handleConfirm = () => {
|
||||
const [selectedId, setSelectedId] = React.useState<number | null>(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<number | null>(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 (
|
||||
<div className="u4-root">
|
||||
|
||||
Reference in New Issue
Block a user