123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import React,{useState} from 'react';
- import {
- ProFormSelect,
- ProFormText,
- ModalForm,
- ProFormDependency
- } from '@ant-design/pro-form';
- import { getMainDistrictList } from './service';
- const UpdateForm = (props) => {
- const { updateModalVisible, updateModalVisibleChange, values, onSubmit } = props;
- const [selectedHosp,setSelectedHosp] = useState({});
- // console.log({values});
- return (
- <>
- {
- JSON.stringify(values) !== '{}' && <ModalForm
- title="编辑医院"
- width="800px"
- initialValues={{ ...values }}
- labelCol={{ span: 3, offset: 3 }}
- layout={'horizontal'}
- visible={updateModalVisible}
- onVisibleChange={(visible) => updateModalVisibleChange(visible)}
- onFinish={(value) => onSubmit({ ...values, ...value,parentName:selectedHosp.name})}
- >
- <ProFormText
- label="医院名"
- rules={[
- {
- required: true,
- message:'医院名是必填项',
- },
- ]}
- width="sm"
- name="name"
- />
- <ProFormSelect
- // initialValue={parseInt(values.isHospital)}
- rules={[
- {
- required: true,
- message:'请选择是否为主院',
- },
- ]}
- options={[
- {
- value: 0,
- label: '是',
- },
- {
- value: 1,
- label: '否',
- },
- ]}
- width="xs"
- name="isHospital"
- label="是否为主院"
- />
- <ProFormDependency name={['isHospital']}>
- {({ isHospital }) => {
- return isHospital == 0 ? (
- <ProFormText
- label="医院标识"
- rules={[
- {
- required: false,
- message:'',
- },
- ]}
- width="sm"
- name="sign"
- />
- ) : <></>;
- }}
- </ProFormDependency>
- <ProFormDependency name={['isHospital']}>
- {({ isHospital }) => {
- return isHospital == 1 ? (
- <ProFormSelect
- name="parentId"
- label="选择主医院"
- request={async () =>{
- const resp = await getMainDistrictList();
- const {status,data,} = resp;
-
- if(status == 200){
- return data.map(item=>({
- label:item.name,
- value:item.id
- }))
- }
- }}
- fieldProps={{
- onChange: async (val) => {
- const resp = await getMainDistrictList();
- const {status,data,} = resp;
- if(status==200){
- const needItem = data.filter(item => item.id == val);
- needItem.length>0&&setSelectedHosp(needItem[0]);
- }
-
- },
- }}
- placeholder="请选择主医院"
- width='sm'
- rules={[{ required: true, message: '请选择主医院' }]}
- />
- ) : <></>
- }}
- </ProFormDependency>
- </ModalForm>
- }
- </>
- );
- };
- export default UpdateForm;
|