|
@@ -2,6 +2,7 @@ import { useEffect, useState, useContext } from 'react';
|
|
|
import { Form, Input, Button, Steps, Tabs, Space, Switch, Breadcrumb, Radio, TreeSelect, Tree, Tag, Card, message } from 'antd';
|
|
|
import './index.less';
|
|
|
import DataContext from './data-context';
|
|
|
+import MenuTree from './MenuTree';
|
|
|
import { useSelector } from 'react-redux'
|
|
|
import apiObj from '@api/index';
|
|
|
import utils from '@utils/index'
|
|
@@ -10,7 +11,7 @@ import DoctorList from "./doctorList"
|
|
|
import Item from 'antd/lib/list/Item';
|
|
|
const { post, api, xPost } = apiObj;
|
|
|
const { SHOW_PARENT } = TreeSelect;
|
|
|
-const { organizationData } = utils;
|
|
|
+const { unique } = utils;
|
|
|
const { Step } = Steps;
|
|
|
const { TabPane } = Tabs;
|
|
|
function AddData(props) {
|
|
@@ -21,30 +22,56 @@ function AddData(props) {
|
|
|
}, []);
|
|
|
const { back } = props;
|
|
|
const [form] = Form.useForm();
|
|
|
- const [value, setValue] = useState(['','']);
|
|
|
- const [key, setKey] = useState('0');
|
|
|
+ const [value, setValue] = useState([]);
|
|
|
+ const [key, setKey] = useState();
|
|
|
const [index, setIndex] = useState('0');
|
|
|
- const [selectedId, setSelectedId] = useState(['48-胡能杰']);
|
|
|
const [treeRloe, setTreeRloe] = useState([]);
|
|
|
- const [tags, setTags] = useState([]);
|
|
|
+ const [tags, setTags] = useState([[]]);
|
|
|
const [treeData, setTreeData] = useState([]);
|
|
|
- const layout = {
|
|
|
- labelCol: { span: 3 },
|
|
|
- wrapperCol: { span: 20 },
|
|
|
- };
|
|
|
- const [expandedKeys, setExpandedKeys] = useState(['0-0-0', '0-0-1']);
|
|
|
- const [checkedKeys, setCheckedKeys] = useState(['0-0-0']);
|
|
|
const [selectedKeys, setSelectedKeys] = useState([]);
|
|
|
const [orgList, setOrgList] = useState([]);
|
|
|
- const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
|
+ const [selectedRowKey, setSelectedRowKey] = useState([]);
|
|
|
const [autoExpandParent, setAutoExpandParent] = useState(true);
|
|
|
const { save, detail } = useContext(DataContext);
|
|
|
const staticInfo = useSelector(state => {
|
|
|
return state.staticInfo;
|
|
|
});
|
|
|
- const { dataList } = staticInfo;
|
|
|
+ // const { dataList } = staticInfo;
|
|
|
+ const dataList = [
|
|
|
+ {
|
|
|
+ "name": "1",
|
|
|
+ "val": "全部组织"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "2",
|
|
|
+ "val": "全部科室"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "3",
|
|
|
+ "val": "全部科室除本科室外"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "4",
|
|
|
+ "val": "本科室"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "5",
|
|
|
+ "val": "本医疗组"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "6",
|
|
|
+ "val": "本人"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "7",
|
|
|
+ "val": "自定义"
|
|
|
+ }
|
|
|
+ ]
|
|
|
const initialValues = detail || {
|
|
|
- status: '1'
|
|
|
+ status: '1',
|
|
|
+ };
|
|
|
+ const validateMessages = {
|
|
|
+ required: '${label}不能为空',
|
|
|
};
|
|
|
//获取当前用于所属角色
|
|
|
function getCreateRoles() {
|
|
@@ -63,13 +90,31 @@ function AddData(props) {
|
|
|
function getHospitalTree() {
|
|
|
post(api.getHospitalTree).then((res) => {
|
|
|
if (res.data.code === 200) {
|
|
|
- const data = res.data.data;
|
|
|
+ const data = res.data.data
|
|
|
let arr = data
|
|
|
- arr = organizationData(arr)
|
|
|
+ arr = structureTreeData(arr)
|
|
|
setTreeData(arr)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+ //数据转换为树形结构所需字段
|
|
|
+ function structureTreeData(arr) {
|
|
|
+ let list = []
|
|
|
+ arr.forEach(it => {
|
|
|
+ it.key = it.hospitalId
|
|
|
+ it.title = it.hospitalName
|
|
|
+ list.push({
|
|
|
+ children: it.depts,
|
|
|
+ title: it.hospitalName,
|
|
|
+ key: it.parentId + '-' + it.hospitalId + '-' + it.hospitalName
|
|
|
+ })
|
|
|
+ it.depts.forEach(its => {
|
|
|
+ its.key = it.parentId + '-' + it.hospitalId + '-' + its.deptId + '-' + its.deptName
|
|
|
+ })
|
|
|
+ })
|
|
|
+ arr = JSON.parse(JSON.stringify(list).replaceAll(/deptName/g, 'title').replaceAll(/deptId/g, 'key'))
|
|
|
+ return arr
|
|
|
+ }
|
|
|
//获取组织列表
|
|
|
function getOrgList() {
|
|
|
xPost(api.getUserHospitals).then((res) => {
|
|
@@ -78,8 +123,10 @@ function AddData(props) {
|
|
|
const { software } = data;
|
|
|
setOrgList(software);
|
|
|
setKey(software[0].id)
|
|
|
- // //默认显示第一个系统的组织
|
|
|
- // setHisList(software[0] ? software[0].hospitals : []);
|
|
|
+ software.forEach((it, index) => {
|
|
|
+ tags[index] = []
|
|
|
+ setTags([...tags])
|
|
|
+ })
|
|
|
} else {
|
|
|
message.warning(res.data.msg || '获取医院列表失败');
|
|
|
}
|
|
@@ -87,87 +134,122 @@ function AddData(props) {
|
|
|
message.error("接口出错");
|
|
|
});
|
|
|
}
|
|
|
- const onExpand = (expandedKeysValue) => {
|
|
|
- //console.log('onExpand', expandedKeysValue); // if not set autoExpandParent to false, if children expanded, parent can not collapse.
|
|
|
- // or, you can remove all expanded children keys.
|
|
|
- setExpandedKeys(expandedKeysValue);
|
|
|
- setAutoExpandParent(false);
|
|
|
- };
|
|
|
-
|
|
|
- const onCheck = (checkedKeysValue) => {
|
|
|
- // console.log('onCheck', checkedKeysValue);
|
|
|
- setCheckedKeys(checkedKeysValue);
|
|
|
- };
|
|
|
|
|
|
- const onSelect = (selectedKeysValue, info) => {
|
|
|
- setSelectedKeys(selectedKeysValue);
|
|
|
- };
|
|
|
- const validateMessages = {
|
|
|
- required: '${label}不能为空',
|
|
|
- };
|
|
|
const onChange = (e, i) => {
|
|
|
let val = value
|
|
|
const formData = form.getFieldsValue();
|
|
|
let arr = formData.softwareVOS;
|
|
|
- arr[i] = {
|
|
|
- id: key,
|
|
|
- dataAuthDetails: arr[i].dataAuthDetails,
|
|
|
- };
|
|
|
- console.log(arr)
|
|
|
+ arr[i].id = key
|
|
|
+ tags[index] = []
|
|
|
+ setTags([...tags])
|
|
|
+ selectedRowKey[index] = []
|
|
|
+ setSelectedRowKey([...selectedRowKey])
|
|
|
form.setFieldsValue({
|
|
|
softwareVOS: arr
|
|
|
});
|
|
|
- console.log(form.getFieldsValue())
|
|
|
val[i] = e.target.value
|
|
|
setValue([...val])
|
|
|
-
|
|
|
};
|
|
|
// 删除选择标签
|
|
|
- function delTag(i){
|
|
|
- console.log(i);
|
|
|
- console.log(tags);
|
|
|
- tags.splice(i)
|
|
|
- selectedRowKeys.splice(i)
|
|
|
+ function delTag(type, id, i) {
|
|
|
+ const formData = form.getFieldsValue();
|
|
|
+ if (type == 3) {
|
|
|
+ formData.softwareVOS[index].selectedRowKeys.forEach((item, inx) => {
|
|
|
+ if (item.split('-')[0] == id) {
|
|
|
+ formData.softwareVOS[index].selectedRowKeys.splice(inx)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else if (type == 1) {
|
|
|
+ formData.softwareVOS[index].softwareMenuIds.forEach((item, inx) => {
|
|
|
+ if (item.split('-')[1] == id) {
|
|
|
+ formData.softwareVOS[index].softwareMenuIds.splice(inx)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else if (type == 2) {
|
|
|
+ formData.softwareVOS[index].softwareMenuIds.forEach((item, inx) => {
|
|
|
+ if (item.split('-')[2] == id) {
|
|
|
+ formData.softwareVOS[index].softwareMenuIds.splice(inx)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ form.setFieldsValue({
|
|
|
+ softwareVOS: formData.softwareVOS
|
|
|
+ });
|
|
|
+ tags[index].splice(i)
|
|
|
setTags([...tags])
|
|
|
- setSelectedRowKeys([...selectedRowKeys])
|
|
|
- // setDelIndex(i)
|
|
|
- // DoctorList.alertEvevnt();
|
|
|
}
|
|
|
function callback(key) {
|
|
|
setKey(key.split('-')[0])
|
|
|
setIndex(key.split('-')[1])
|
|
|
}
|
|
|
function callbacks(keys) {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- function checkDoctEvent(selectedRowKeys){
|
|
|
- console.log(selectedRowKeys);
|
|
|
-
|
|
|
+ //医生选中
|
|
|
+ function checkDoctEvent(selectedRowKeys) {
|
|
|
const formData = form.getFieldsValue();
|
|
|
- let arr = []
|
|
|
let tag = []
|
|
|
- let ids = []
|
|
|
+ let arr = []
|
|
|
selectedRowKeys.forEach(it => {
|
|
|
arr.push({
|
|
|
- dataType:7,
|
|
|
- detailId:it.split('-')[0],
|
|
|
- detailType:3
|
|
|
+ dataType: 7,
|
|
|
+ detailId: it.split('-')[0],
|
|
|
+ detailType: 3
|
|
|
+ })
|
|
|
+ tag.push({
|
|
|
+ id: it.split('-')[0],
|
|
|
+ name: it.split('-')[1],
|
|
|
+ type: 3
|
|
|
})
|
|
|
- tag.push(it.split('-')[1])
|
|
|
- ids.push(it.split('-')[0])
|
|
|
});
|
|
|
-
|
|
|
- formData.dataAuthDetails[index] = arr
|
|
|
+ formData.softwareVOS[index].dataAuthDetails = arr
|
|
|
+ formData.softwareVOS[index].selectedRowKeys = selectedRowKeys
|
|
|
form.setFieldsValue({
|
|
|
- dataAuthDetails: formData.dataAuthDetails
|
|
|
+ softwareVOS: formData.softwareVOS
|
|
|
});
|
|
|
- setSelectedId([...ids])
|
|
|
- console.log(selectedId);
|
|
|
-
|
|
|
- setTags([...tag])
|
|
|
+ tags[index] = unique(tag)
|
|
|
+ setTags([...tags])
|
|
|
+ }
|
|
|
+ //树形结构选中事件
|
|
|
+ function checkTreeEvent(idsArr, sourceIds) {
|
|
|
+ const formData = form.getFieldsValue();
|
|
|
+ let tag = []
|
|
|
+ let arr = []
|
|
|
+ let result = idsArr.find(ele => ele.split('-').length == 3)
|
|
|
+ if (result) {
|
|
|
+ arr.push({
|
|
|
+ dataType: 7,
|
|
|
+ detailId: result.split('1')[1],
|
|
|
+ detailType: 1
|
|
|
+ })
|
|
|
+ tag.push({
|
|
|
+ id: result.split('-')[1],
|
|
|
+ name: result.split('-')[2],
|
|
|
+ type: 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ idsArr.forEach(it => {
|
|
|
+ arr.push({
|
|
|
+ dataType: 7,
|
|
|
+ detailId: it.split('1')[2],
|
|
|
+ detailType: 2
|
|
|
+ })
|
|
|
+ tag.push({
|
|
|
+ id: it.split('-')[2],
|
|
|
+ name: it.split('-')[3],
|
|
|
+ type: 2
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ formData.softwareVOS[index].dataAuthDetails = arr
|
|
|
+ formData.softwareVOS[index].softwareMenuIds = idsArr
|
|
|
+ form.setFieldsValue({
|
|
|
+ softwareVOS: formData.softwareVOS
|
|
|
+ });
|
|
|
+ tags[index] = unique(tag)
|
|
|
+ setTags([...tags])
|
|
|
}
|
|
|
const onFinish = value => {
|
|
|
- console.log(form.getFieldsValue())
|
|
|
save(form.getFieldsValue())
|
|
|
};
|
|
|
function swichChange(val) {
|
|
@@ -181,7 +263,7 @@ function AddData(props) {
|
|
|
<Breadcrumb.Separator />
|
|
|
<Breadcrumb.Item>新增子组织</Breadcrumb.Item>
|
|
|
</Breadcrumb>
|
|
|
- <Form {...layout} form={form} name="nest-messages" onFinish={onFinish} initialValues={initialValues} validateMessages={validateMessages}>
|
|
|
+ <Form labelCol={{ span: 4 }} wrapperCol={{ span: 18 }} form={form} name="nest-messages" onFinish={onFinish} initialValues={initialValues} validateMessages={validateMessages}>
|
|
|
<Form.Item name="name" label="数据权限名称" rules={[{ required: true }]}>
|
|
|
<Input placeholder="请填写数据权限名称" />
|
|
|
</Form.Item>
|
|
@@ -190,15 +272,15 @@ function AddData(props) {
|
|
|
{
|
|
|
orgList.map((it, i) => {
|
|
|
return (
|
|
|
- <TabPane tab={it.name} key={it.id+"-"+i}>
|
|
|
+ <TabPane tab={it.name} key={it.id + "-" + i}>
|
|
|
<Form.Item
|
|
|
key={i}
|
|
|
- name={['dataAuthDetails', i, 'dataType']} noStyle>
|
|
|
- <Radio.Group onChange={e => { onChange(e, i) }} value={value[i]} className="radio">
|
|
|
+ name={['softwareVOS', i, 'datatype']} noStyle>
|
|
|
+ <Radio.Group onChange={e => { onChange(e, i) }} className="radio">
|
|
|
<Space direction="vertical">
|
|
|
{dataList.map((Item) => {
|
|
|
return (
|
|
|
- <Radio value={Item.name}>{Item.val}</Radio>
|
|
|
+ <Radio key={i} value={Item.name}>{Item.val}</Radio>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
@@ -208,51 +290,120 @@ function AddData(props) {
|
|
|
<Form.Item key={i + "a"} hidden={true} name={['softwareVOS', i, 'id']} noStyle>
|
|
|
<Input />
|
|
|
</Form.Item>
|
|
|
+ <Form.Item key={i + "b"} hidden={true} name={['softwareVOS', i, 'dataAuthDetails']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "c"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
+ <Card title="已选中" extra={<a href="#">More</a>} >
|
|
|
+ {tags[index].map((tag, i) => {
|
|
|
+ return (
|
|
|
+ <Tag key={i} closable onClose={e => delTag(tag.type, tag.id, i)}>{tag.name}</Tag>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </Card>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "d"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
+ <Tabs defaultActiveKey="0" onChange={callbacks} >
|
|
|
+ <TabPane tab="可看医生" key="0">
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ name={['softwareVOS', i, 'selectedRowKeys']}
|
|
|
+ >
|
|
|
+ <DoctorList checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkDoct={(selectedRowKeys) => checkDoctEvent(selectedRowKeys)} />
|
|
|
+ </Form.Item>
|
|
|
+ </TabPane>
|
|
|
+ <TabPane tab="可看科室" key="1">
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ name={['softwareVOS', i, 'softwareMenuIds']}
|
|
|
+ >
|
|
|
+ <MenuTree data={treeData} checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkEv={(checkedKeys, sourceIds) => checkTreeEvent(checkedKeys, sourceIds)} />
|
|
|
+ </Form.Item>
|
|
|
+ </TabPane>
|
|
|
+ </Tabs>
|
|
|
+ </Form.Item>
|
|
|
</TabPane>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
</Tabs>
|
|
|
</Form.Item>
|
|
|
- {value[index] == 7 ?
|
|
|
- <Form.Item wrapperCol={{ offset: 3, span: 20 }} name={['dataAuthDetails', key, 'dataType']}>
|
|
|
- <Card title="已选中" extra={<a href="#">More</a>} >
|
|
|
- {tags.map((tag, i) => {
|
|
|
+
|
|
|
+ {/* {value[index] == 7 ?
|
|
|
+ <Form.Item wrapperCol={{ offset: 3, span: 20 }} >
|
|
|
+ {
|
|
|
+ orgList.map((it, i) => {
|
|
|
return (
|
|
|
- <Tag closable onClose={e=>delTag(i)}>{tag}</Tag>
|
|
|
- );
|
|
|
- })}
|
|
|
- </Card>
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ >
|
|
|
+ {
|
|
|
+ it.id == key ?
|
|
|
+ <Card title="已选中" extra={<a href="#">More</a>} >
|
|
|
+ {tags[index].map((tag, i) => {
|
|
|
+ return (
|
|
|
+ <Tag key={i} closable onClose={e => delTag(i)}>{tag}</Tag>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </Card>
|
|
|
+ :
|
|
|
+ null
|
|
|
+ }
|
|
|
+ </Form.Item>
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
</Form.Item>
|
|
|
:
|
|
|
null}
|
|
|
|
|
|
{value[index] == 7 ?
|
|
|
<Form.Item
|
|
|
- name={['softwareVOS', index, 'dataAuthDetails', index, 'detailId']}
|
|
|
wrapperCol={{ offset: 3, span: 20 }}
|
|
|
>
|
|
|
- <Tabs defaultActiveKey="0" onChange={callbacks} >
|
|
|
- <TabPane tab="可看医生" key="0">
|
|
|
- <DoctorList data={selectedId} checkDoct={(selectedRowKeys) => checkDoctEvent(selectedRowKeys)}/>
|
|
|
- </TabPane>
|
|
|
- <TabPane tab="可看科室" key="1">
|
|
|
- <Tree
|
|
|
- checkable
|
|
|
- onExpand={onExpand}
|
|
|
- expandedKeys={expandedKeys}
|
|
|
- autoExpandParent={autoExpandParent}
|
|
|
- onCheck={onCheck}
|
|
|
- checkedKeys={checkedKeys}
|
|
|
- onSelect={onSelect}
|
|
|
- selectedKeys={selectedKeys}
|
|
|
- treeData={treeData}
|
|
|
- />
|
|
|
- </TabPane>
|
|
|
- </Tabs>
|
|
|
+ {
|
|
|
+ orgList.map((it, i) => {
|
|
|
+ return (
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ >
|
|
|
+ {
|
|
|
+ it.id == key ?
|
|
|
+ <Tabs defaultActiveKey="0" onChange={callbacks} >
|
|
|
+ <TabPane tab="可看医生" key="0">
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ name={['softwareVOS', i, 'selectedRowKeys']}
|
|
|
+ >
|
|
|
+ <DataContext.Provider value={{ data: selectedRowKey[index] }}>
|
|
|
+ <DoctorList checkDoct={(selectedRowKeys) => checkDoctEvent(selectedRowKeys)} />
|
|
|
+ </DataContext.Provider>
|
|
|
+ </Form.Item>
|
|
|
+ </TabPane>
|
|
|
+ <TabPane tab="可看科室" key="1">
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ name={['softwareVOS', i, 'softwareMenuIds']}
|
|
|
+ valuePropName='checked'
|
|
|
+ getValueFromEvent={(checked) => {
|
|
|
+ console.log(321, checked)
|
|
|
+ return [];
|
|
|
+ }} noStyle>
|
|
|
+ <MenuTree data={treeData} checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkEv={(checkedKeys, sourceIds) => checkTreeEvent(checkedKeys, sourceIds)} />
|
|
|
+ </Form.Item>
|
|
|
+ </TabPane>
|
|
|
+ </Tabs>
|
|
|
+ :
|
|
|
+ null
|
|
|
+ }
|
|
|
+ </Form.Item>
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
</Form.Item>
|
|
|
:
|
|
|
- null}
|
|
|
+ null} */}
|
|
|
|
|
|
<Form.Item
|
|
|
name="roles"
|
|
@@ -276,7 +427,7 @@ function AddData(props) {
|
|
|
>
|
|
|
<Switch onChange={swichChange} />
|
|
|
</Form.Item>
|
|
|
- <Form.Item wrapperCol={{ ...layout.wrapperCol, offset: 8 }}>
|
|
|
+ <Form.Item wrapperCol={{ span: 20, offset: 8 }}>
|
|
|
<Button type="primary" htmlType="submit">
|
|
|
Submit
|
|
|
</Button>
|