import React, { useState, useEffect, useContext } from 'react'; import { Modal, Form, Input, Select, Button, Switch, TreeSelect, message, Space } from 'antd'; import apiObj from '@api/index'; import utils from '@utils/index' import FuncContext from './func-context'; import { useSelector } from 'react-redux' import Item from 'antd/lib/list/Item'; const { post, api, xPost } = apiObj; const { Option, OptGroup } = Select; const { organizationData } = utils; const { SHOW_PARENT } = TreeSelect; const { TextArea } = Input; function AddUser(props) { useEffect(() => { getHospitalTree(); }, []); const [form] = Form.useForm(); const { type,id,detail } = useContext(FuncContext); const [treeData, setTreeData] = useState([]); const [treeFunc, setTreeFunc] = useState([]); const staticInfo = useSelector(state => { return state.staticInfo; }); const { titleList } = staticInfo; const initialValues = detail //所属系统 function getHospitalTree() { xPost(api.getUserHospitals).then((res) => { if (res.data.code === 200) { const data = res.data.data.software const treeFunc = organizationData(data) setTreeFunc(treeFunc) } else { message.warning(res.data.msg || '获取医院列表失败'); } }) } function organizationData(arr) { arr.forEach(item => { item.value = item.id item.title = item.name }) return arr } function addAttr(data) { for (var j = 0; j < data.length; j++) { data[j].title = data[j].name //添加title属性 data[j].key = data[j].code //添加key属性 if (data[j].children.length > 0) { addAttr(data[j].children) } } return data } function swichChange(val) { form.setFieldsValue({ status: val ? 1 : 0 }) } const onChangeRloe = value => { form.setFieldsValue({ roles: value }) }; const onFinish = values => { const formData = form.getFieldValue() let params = values params.parentId = formData.parentId if (type == 2) { params.id = id updateMenu(params) } else { addMenu(params) } }; function addMenu(param) { post(api.addMenu, param).then((res) => { if (res.data.code === 200) { props.userChange() message.success(res.data.message); form.resetFields(); } else { message.error(res.data.message); } }) } function updateMenu(param) { post(api.updateMenu, param).then((res) => { if (res.data.code === 200) { props.userChange() message.success(res.data.message); form.resetFields(); } else { message.error(res.data.message); } }) } function cancel() { props.userChange() } return ( <>