|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useEffect, useRef, useMemo } from 'react';
|
|
|
+import React, { useEffect, useRef, useMemo, useState } from 'react';
|
|
|
import {
|
|
|
Form,
|
|
|
Input,
|
|
|
@@ -12,11 +12,14 @@ import { useIntl, FormattedMessage } from 'react-intl';
|
|
|
import { registerFormFields } from '@/validation/patient/registerSchema';
|
|
|
import NumberWithUnit from '@/components/NumberWithUnit';
|
|
|
import dayjs, { Dayjs } from 'dayjs';
|
|
|
-import { useSelector } from 'react-redux';
|
|
|
+import { useSelector, useDispatch } from 'react-redux';
|
|
|
import { RootState } from '@/states/store';
|
|
|
-import { PregnancyStatus, pregnancyStatusOptions } from '@/domain/patient/pregnancyStatus';
|
|
|
+import { setFormData } from '@/states/patient/register/formSlice';
|
|
|
+import {
|
|
|
+ PregnancyStatus,
|
|
|
+ pregnancyStatusOptions,
|
|
|
+} from '@/domain/patient/pregnancyStatus';
|
|
|
import { getGenderOptions } from '@/domain/patient/genderOptions';
|
|
|
-
|
|
|
interface BasicInfoFormProps {
|
|
|
style?: React.CSSProperties;
|
|
|
form?: FormInstance;
|
|
|
@@ -37,6 +40,9 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
const productName = useSelector(
|
|
|
(state: RootState) => state.product.productName
|
|
|
);
|
|
|
+ const dispatch = useDispatch();
|
|
|
+ const [pregnancyStatusFieldVisible, setPregnancyStatusFieldVisible] =
|
|
|
+ useState(false);
|
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
@@ -154,8 +160,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
<Form.Item
|
|
|
label={
|
|
|
<FormattedMessage
|
|
|
- id={productName === 'VETDROS' ? 'animal.register.patientName' : 'register.patientName'}
|
|
|
- defaultMessage={productName === 'VETDROS' ? 'animal.register.patientName' : 'register.patientName'}
|
|
|
+ id={
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientName'
|
|
|
+ : 'register.patientName'
|
|
|
+ }
|
|
|
+ defaultMessage={
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientName'
|
|
|
+ : 'register.patientName'
|
|
|
+ }
|
|
|
/>
|
|
|
}
|
|
|
name="patient_name"
|
|
|
@@ -165,8 +179,14 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
>
|
|
|
<Input
|
|
|
placeholder={intl.formatMessage({
|
|
|
- id: productName === 'VETDROS' ? 'animal.register.patientName.placeholder' : 'register.patientName.placeholder',
|
|
|
- defaultMessage: productName === 'VETDROS' ? 'animal.register.patientName.placeholder' : 'register.patientName.placeholder',
|
|
|
+ id:
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientName.placeholder'
|
|
|
+ : 'register.patientName.placeholder',
|
|
|
+ defaultMessage:
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientName.placeholder'
|
|
|
+ : 'register.patientName.placeholder',
|
|
|
})}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
@@ -192,8 +212,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
<Form.Item
|
|
|
label={
|
|
|
<FormattedMessage
|
|
|
- id={productName === 'VETDROS' ? 'animal.register.patientId' : 'register.patientId'}
|
|
|
- defaultMessage={productName === 'VETDROS' ? 'animal.register.patientId' : 'register.patientId'}
|
|
|
+ id={
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientId'
|
|
|
+ : 'register.patientId'
|
|
|
+ }
|
|
|
+ defaultMessage={
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientId'
|
|
|
+ : 'register.patientId'
|
|
|
+ }
|
|
|
/>
|
|
|
}
|
|
|
name="patient_id"
|
|
|
@@ -203,8 +231,14 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
>
|
|
|
<Input
|
|
|
placeholder={intl.formatMessage({
|
|
|
- id: productName === 'VETDROS' ? 'animal.register.patientId.placeholder' : 'register.patientId.placeholder',
|
|
|
- defaultMessage: productName === 'VETDROS' ? 'animal.register.patientId.placeholder' : 'register.patientId.placeholder',
|
|
|
+ id:
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientId.placeholder'
|
|
|
+ : 'register.patientId.placeholder',
|
|
|
+ defaultMessage:
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientId.placeholder'
|
|
|
+ : 'register.patientId.placeholder',
|
|
|
})}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
@@ -212,8 +246,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
<Form.Item
|
|
|
label={
|
|
|
<FormattedMessage
|
|
|
- id={productName === 'VETDROS' ? 'animal.register.patientSize' : 'register.patientSize'}
|
|
|
- defaultMessage={productName === 'VETDROS' ? 'animal.register.patientSize' : 'register.patientSize'}
|
|
|
+ id={
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientSize'
|
|
|
+ : 'register.patientSize'
|
|
|
+ }
|
|
|
+ defaultMessage={
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientSize'
|
|
|
+ : 'register.patientSize'
|
|
|
+ }
|
|
|
/>
|
|
|
}
|
|
|
name="patient_size"
|
|
|
@@ -224,8 +266,14 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
>
|
|
|
<Select
|
|
|
placeholder={intl.formatMessage({
|
|
|
- id: productName === 'VETDROS' ? 'animal.register.patientSize.placeholder' : 'register.patientSize.placeholder',
|
|
|
- defaultMessage: productName === 'VETDROS' ? 'animal.register.patientSize.placeholder' : 'register.patientSize.placeholder',
|
|
|
+ id:
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientSize.placeholder'
|
|
|
+ : 'register.patientSize.placeholder',
|
|
|
+ defaultMessage:
|
|
|
+ productName === 'VETDROS'
|
|
|
+ ? 'animal.register.patientSize.placeholder'
|
|
|
+ : 'register.patientSize.placeholder',
|
|
|
})}
|
|
|
defaultValue="Medium"
|
|
|
>
|
|
|
@@ -294,7 +342,25 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
validateTrigger={registerFormFields.patient_sex.trigger}
|
|
|
rules={registerFormFields.patient_sex.validation}
|
|
|
>
|
|
|
- <Select options={genderOptions} />
|
|
|
+ <Select
|
|
|
+ options={genderOptions}
|
|
|
+ onChange={(e) => {
|
|
|
+ const _PregnancyStatusFieldVisible = e === 'M';
|
|
|
+ setPregnancyStatusFieldVisible(_PregnancyStatusFieldVisible);
|
|
|
+ if (_PregnancyStatusFieldVisible) {
|
|
|
+ // 更新表单
|
|
|
+ form?.setFieldValue('pregnancy_status', PregnancyStatus.UNKNOWN);
|
|
|
+ // 手动同步更新 Redux store
|
|
|
+ const currentValues = form?.getFieldsValue();
|
|
|
+ dispatch(
|
|
|
+ setFormData({
|
|
|
+ ...currentValues,
|
|
|
+ pregnancy_status: PregnancyStatus.UNKNOWN,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ />
|
|
|
</Form.Item>
|
|
|
{/** 宠物专用 */}
|
|
|
{productName === 'VETDROS' && (
|
|
|
@@ -318,10 +384,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
})}
|
|
|
>
|
|
|
<Select.Option value="ALTERED">
|
|
|
- {intl.formatMessage({ id: 'register.sexNeutered.altered', defaultMessage: 'ALTERED' })}
|
|
|
+ {intl.formatMessage({
|
|
|
+ id: 'register.sexNeutered.altered',
|
|
|
+ defaultMessage: 'ALTERED',
|
|
|
+ })}
|
|
|
</Select.Option>
|
|
|
<Select.Option value="UNALTERED">
|
|
|
- {intl.formatMessage({ id: 'register.sexNeutered.unaltered', defaultMessage: 'UNALTERED' })}
|
|
|
+ {intl.formatMessage({
|
|
|
+ id: 'register.sexNeutered.unaltered',
|
|
|
+ defaultMessage: 'UNALTERED',
|
|
|
+ })}
|
|
|
</Select.Option>
|
|
|
</Select>
|
|
|
</Form.Item>
|
|
|
@@ -329,6 +401,7 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
{/** 人类专用 */}
|
|
|
{productName === 'DROS' && (
|
|
|
<Form.Item
|
|
|
+ hidden={pregnancyStatusFieldVisible}
|
|
|
label={
|
|
|
<FormattedMessage
|
|
|
id="register.pregnancyStatus"
|