updateForm.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React,{useState} from 'react';
  2. import {
  3. ProFormSelect,
  4. ProFormText,
  5. ModalForm,
  6. ProFormDependency
  7. } from '@ant-design/pro-form';
  8. import { getMainDistrictList } from './service';
  9. const UpdateForm = (props) => {
  10. const { updateModalVisible, updateModalVisibleChange, values, onSubmit } = props;
  11. const [selectedHosp,setSelectedHosp] = useState({});
  12. // console.log({values});
  13. return (
  14. <>
  15. {
  16. JSON.stringify(values) !== '{}' && <ModalForm
  17. title="编辑医院"
  18. width="800px"
  19. initialValues={{ ...values }}
  20. labelCol={{ span: 3, offset: 3 }}
  21. layout={'horizontal'}
  22. visible={updateModalVisible}
  23. onVisibleChange={(visible) => updateModalVisibleChange(visible)}
  24. onFinish={(value) => onSubmit({ ...values, ...value,parentName:selectedHosp.name})}
  25. >
  26. <ProFormText
  27. label="医院名"
  28. rules={[
  29. {
  30. required: true,
  31. message:'医院名是必填项',
  32. },
  33. ]}
  34. width="sm"
  35. name="name"
  36. />
  37. <ProFormSelect
  38. // initialValue={parseInt(values.isHospital)}
  39. rules={[
  40. {
  41. required: true,
  42. message:'请选择是否为主院',
  43. },
  44. ]}
  45. options={[
  46. {
  47. value: 0,
  48. label: '是',
  49. },
  50. {
  51. value: 1,
  52. label: '否',
  53. },
  54. ]}
  55. width="xs"
  56. name="isHospital"
  57. label="是否为主院"
  58. />
  59. <ProFormDependency name={['isHospital']}>
  60. {({ isHospital }) => {
  61. return isHospital == 0 ? (
  62. <ProFormText
  63. label="医院标识"
  64. rules={[
  65. {
  66. required: false,
  67. message:'',
  68. },
  69. ]}
  70. width="sm"
  71. name="sign"
  72. />
  73. ) : <></>;
  74. }}
  75. </ProFormDependency>
  76. <ProFormDependency name={['isHospital']}>
  77. {({ isHospital }) => {
  78. return isHospital == 1 ? (
  79. <ProFormSelect
  80. name="parentId"
  81. label="选择主医院"
  82. request={async () =>{
  83. const resp = await getMainDistrictList();
  84. const {status,data,} = resp;
  85. if(status == 200){
  86. return data.map(item=>({
  87. label:item.name,
  88. value:item.id
  89. }))
  90. }
  91. }}
  92. fieldProps={{
  93. onChange: async (val) => {
  94. const resp = await getMainDistrictList();
  95. const {status,data,} = resp;
  96. if(status==200){
  97. const needItem = data.filter(item => item.id == val);
  98. needItem.length>0&&setSelectedHosp(needItem[0]);
  99. }
  100. },
  101. }}
  102. placeholder="请选择主医院"
  103. width='sm'
  104. rules={[{ required: true, message: '请选择主医院' }]}
  105. />
  106. ) : <></>
  107. }}
  108. </ProFormDependency>
  109. </ModalForm>
  110. }
  111. </>
  112. );
  113. };
  114. export default UpdateForm;