AppendViewModal.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import React, { useEffect } from 'react';
  2. import { Modal, Row, Col, message, Button, Space } from 'antd';
  3. import { useSelector, useDispatch } from 'react-redux';
  4. import { RootState, AppDispatch } from '@/states/store';
  5. import {
  6. clearSelectedViews,
  7. setModalOpen,
  8. appendViewsThunk,
  9. setCurrentBodyPart,
  10. } from '@/states/exam/appendViewSlice';
  11. import BodyPositionFilter from '@/pages/patient/components/bodyPositionFilter';
  12. import RegisterAvailableList from '@/pages/patient/components/register.available.list';
  13. import SelectedProtocolList from '@/pages/patient/components/register.selected.view.list';
  14. interface AppendViewModalProps {
  15. open: boolean;
  16. onCancel: () => void;
  17. work?: any; // 可选的检查信息,用于worklist页面调用
  18. studyId?: string; // 可选的study ID,用于worklist页面调用
  19. currentWork?: any; // 可选的当前工作信息,用于worklist页面调用
  20. onSuccess?: () => void; // 可选的成功回调,用于追加成功后执行额外操作
  21. }
  22. const AppendViewModal: React.FC<AppendViewModalProps> = ({
  23. open,
  24. onCancel,
  25. work,
  26. studyId,
  27. currentWork,
  28. onSuccess,
  29. }) => {
  30. console.log('[AppendViewModal] Rendering with open:', open);
  31. const dispatch = useDispatch<AppDispatch>();
  32. const selectedViews = useSelector(
  33. (state: RootState) => state.viewSelection.selectedViews
  34. );
  35. const selectedBodyPosition = useSelector(
  36. (state: RootState) => state.bodyPositionList.selectedBodyPosition
  37. );
  38. useEffect(() => {
  39. console.log(
  40. '[AppendViewModal] useEffect triggered, open:',
  41. open,
  42. 'selectedBodyPosition:',
  43. selectedBodyPosition,
  44. 'work:',
  45. work
  46. );
  47. if (open) {
  48. if (selectedBodyPosition) {
  49. // 正常检查页面:使用selectedBodyPosition
  50. const bodyPartId = selectedBodyPosition.body_part_id;
  51. dispatch(setCurrentBodyPart(bodyPartId));
  52. } else if (work) {
  53. // worklist页面:使用传入的work信息
  54. // 对于RIS数据,我们可能需要从其他地方获取bodyPart信息
  55. // 暂时设置为空,后面可以根据需要调整
  56. dispatch(setCurrentBodyPart(null));
  57. }
  58. }
  59. }, [open, selectedBodyPosition, work, dispatch]);
  60. const handleConfirm = async (): Promise<void> => {
  61. if (selectedViews.length === 0) {
  62. message.warning('请至少选择一个体位');
  63. return;
  64. }
  65. // 确定study_id和currentWork
  66. let finalStudyId: string;
  67. let finalCurrentWork: any;
  68. if (selectedBodyPosition) {
  69. // 正常检查页面:使用selectedBodyPosition
  70. finalStudyId = selectedBodyPosition.work.StudyID;
  71. finalCurrentWork = selectedBodyPosition.work;
  72. } else if (studyId && currentWork) {
  73. // worklist页面:使用传入的参数
  74. finalStudyId = studyId;
  75. finalCurrentWork = currentWork;
  76. } else {
  77. message.error('未找到当前检查信息');
  78. return;
  79. }
  80. console.log(`[AppendViewModal] Appending views to Study ID: ${finalStudyId} 传递来的studyId:${studyId}`, selectedViews);
  81. try {
  82. await dispatch(
  83. appendViewsThunk({
  84. study_id: finalStudyId,
  85. views: selectedViews,
  86. currentWork: finalCurrentWork,
  87. })
  88. ).unwrap();
  89. message.success(`成功追加 ${selectedViews.length} 个体位`);
  90. //dispatch(setModalOpen(false));
  91. //onCancel();
  92. // 调用成功回调
  93. if (onSuccess) {
  94. onSuccess();
  95. }
  96. } catch (error) {
  97. message.error('追加体位失败');
  98. console.error('[AppendViewModal] Error appending views:', error);
  99. }
  100. };
  101. const handleCancel = (): void => {
  102. dispatch(clearSelectedViews());
  103. dispatch(setCurrentBodyPart(null));
  104. onCancel();
  105. };
  106. return (
  107. <Modal
  108. title="追加体位"
  109. open={open}
  110. onCancel={handleCancel}
  111. width="90%"
  112. style={{ top: 20 }}
  113. footer={
  114. <Space>
  115. <Button onClick={handleCancel}>取消</Button>
  116. <Button
  117. type="primary"
  118. onClick={handleConfirm}
  119. disabled={selectedViews.length === 0}
  120. >
  121. 确认追加 {selectedViews.length > 0 && `(${selectedViews.length})`}
  122. </Button>
  123. </Space>
  124. }
  125. >
  126. <Row style={{ height: '70vh' }}>
  127. {/* 中间:体型结构区域 */}
  128. <Col
  129. span={8}
  130. style={{ height: '100%', borderRight: '1px solid #f0f0f0' }}
  131. >
  132. <BodyPositionFilter />
  133. </Col>
  134. {/* 右侧:待选择 + 已选择 */}
  135. <Col span={16} style={{ height: '100%' }}>
  136. <Row style={{ height: '100%' }}>
  137. <Col span={24} style={{ height: '50%' }}>
  138. <RegisterAvailableList />
  139. </Col>
  140. <Col span={24} style={{ height: '50%' }}>
  141. <SelectedProtocolList />
  142. </Col>
  143. </Row>
  144. </Col>
  145. </Row>
  146. </Modal>
  147. );
  148. };
  149. export default AppendViewModal;