import React, {
  useState, useEffect, useContext
} from 'react';
import {  Form, Input, Select, Button, Switch, TreeSelect, message, Space } from 'antd';
import apiObj from '@api/index';
import { organizationData } from '@utils/index'
import MedicalContext from './medical-context';
import { useSelector } from 'react-redux'
const { post, api, xPost } = apiObj;
const { Option } = Select;

function AddMedical(props){
	//加载下拉条件
	useEffect(() => {
	  // getHospitalTree();
	  // getCreateRoles()
	});
	const [form] = Form.useForm(); 
	const { formData } = useContext(MedicalContext); //中间组件传值过来的
	const initialValues = formData; //表单的值
	console.log(initialValues);
	
	const staticInfo = useSelector(state => {
	  return state.staticInfo;
	});
	const { titleList } = staticInfo; //上级科室
	
	const onFinish = values => {
	  let params = values
	  // addHospitalTreeVO.hospitals = unique(addHospitalTreeVO.hospitals)
	  // params.addHospitalTreeVO = addHospitalTreeVO
	  // if (type == 2) {
	  //   params.id = userId
	  //   editUser(params)
	  // } else {
	  //   addUser(params)
	  // }
	
	};
	//接收父组件的方法
	function cancel() {
	  props.userChange()
	}
	
	return (
		<>
			<Form
			  labelCol={{ span: 6 }}
			  wrapperCol={{ span: 16 }}
			  form={form}
			  name="register"
			  onFinish={onFinish}
			  initialValues={initialValues}
			>
				<Form.Item
				  name="username"
				  label="医疗组ID"
				>
					<Input placeholder="请输入医疗组ID" autoComplete='off'/>
				</Form.Item>
				<Form.Item
				  name="name"
				  label="医疗组名称"
				  rules={[
				    {
				      required: true,
				      message: '请输入医疗组名称',
				    },
				  ]}
				>
					<Input placeholder="请输入医疗组名称" autoComplete='off'/>
				</Form.Item>
				<Form.Item
				  name="titleId"
				  label="上级科室"
				>
				  
				    <Select placeholder="请选择上级科室">
				      {titleList.map((item) => {
				        return (
				          <Option value={item.name} key={item.name}>{item.val}</Option>
				        )
				      })}
				    </Select>
				</Form.Item>
				<Form.Item
				  name="titleId"
				  label="上级病区"
				>
				  
				    <Select placeholder="请选择上级病区">
				      {titleList.map((item) => {
				        return (
				          <Option value={item.name} key={item.name}>{item.val}</Option>
				        )
				      })}
				    </Select>
				</Form.Item>
				
				
				<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
				  <Space size="middle">
				    <Button htmlType="button" onClick={e => cancel()}>
				      取消
				  </Button>
				    <Button type="primary" htmlType="submit">
				      保存
				  </Button>
				  </Space>
				</Form.Item>
			</Form>
		</>
	)
}
export default AddMedical;