|
@@ -2,7 +2,8 @@ import { useEffect, useState, useContext } from 'react';
|
|
|
import { Form, Input, Button, Steps, Tabs, Space, Switch, Breadcrumb, Radio, TreeSelect, Tree, Tag, Card, message, Modal } from 'antd';
|
|
|
import './index.less';
|
|
|
import DataContext from './data-context';
|
|
|
-import MenuTree from './MenuTree';
|
|
|
+import SelectedTag from '@common/SelectedTag.js';
|
|
|
+import MyDeptStruct from '@common/MyDeptStruct.js';
|
|
|
import { useSelector } from 'react-redux'
|
|
|
import apiObj from '@api/index';
|
|
|
import utils from '@utils/index'
|
|
@@ -17,7 +18,7 @@ const { Step } = Steps;
|
|
|
const { TabPane } = Tabs;
|
|
|
function AddData(props) {
|
|
|
useEffect(() => {
|
|
|
- getHospitalTree()
|
|
|
+ //getHospitalTree()
|
|
|
getOrgList()
|
|
|
if (type == 3) {
|
|
|
setValue(val)
|
|
@@ -27,17 +28,22 @@ function AddData(props) {
|
|
|
const [form] = Form.useForm();
|
|
|
const [isChange, setIsChange] = useState(false);
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
+
|
|
|
+ const [checkedUser, setCheckedUser] = useState([]); //指定用户选中项
|
|
|
+ const [checkedUserIds, setCheckedUserIds] = useState([]); //指定用户选中项id
|
|
|
+ const [checkedDepts, setCheckedDepts] = useState([]); //指定科室选中项
|
|
|
+ const [checkedDeptIds, setCheckedDeptIds] = useState([]); //指定科室选中的科室项id
|
|
|
+ const [checkedHosIds, setCheckedHosIds] = useState([]); //指定科室选中的医院项id
|
|
|
+ const [checkedTreeItems, setCheckedTreeItems] = useState([]); //指定科室选中的树结构
|
|
|
+ const [receiverError,setReceiverError]=useState(false); //接收者校验状态
|
|
|
+
|
|
|
const [value, setValue] = useState([]);
|
|
|
const [key, setKey] = useState();
|
|
|
const [index, setIndex] = useState('0');
|
|
|
const [treeRloe, setTreeRloe] = useState([]);
|
|
|
const [tags, setTags] = useState([[]]);
|
|
|
- const [treeData, setTreeData] = useState([]);
|
|
|
- const [selectedKeys, setSelectedKeys] = useState([]);
|
|
|
const [orgList, setOrgList] = useState([]);
|
|
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
|
- const [softwareId, setSoftwareId] = useState([]);
|
|
|
- const [autoExpandParent, setAutoExpandParent] = useState(true);
|
|
|
const { save, formData, type, val, tag } = useContext(DataContext);
|
|
|
const staticInfo = useSelector(state => {
|
|
|
return state.staticInfo;
|
|
@@ -73,49 +79,7 @@ function AddData(props) {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- //获取当前用户组织
|
|
|
- function getHospitalTree() {
|
|
|
- post(api.getHospitalTree).then((res) => {
|
|
|
- if (res.data.code === 200) {
|
|
|
- const data = res.data.data
|
|
|
- let arr = structureTreeData(data)
|
|
|
- setTreeData(arr)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- //数据转换为树形结构所需字段
|
|
|
- function structureTreeData(arr) {
|
|
|
- arr.forEach(item => {
|
|
|
- item.key = item.hospitalId + '-' + item.hospitalName
|
|
|
- item.title = item.hospitalName
|
|
|
- if (!item.children && item.depts) {
|
|
|
- item.depts.forEach(it => {
|
|
|
- it.key = item.hospitalId + '-' + it.deptId + '-' + it.deptName
|
|
|
- })
|
|
|
- item.children = JSON.parse(JSON.stringify(item.depts).replace(/deptName/g, 'title').replace(/deptId/g, 'key'))
|
|
|
- return
|
|
|
- }
|
|
|
- if (item.children) {
|
|
|
- structureTreeData(item.children)
|
|
|
- }
|
|
|
- })
|
|
|
- return 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) => {
|
|
@@ -263,36 +227,113 @@ function AddData(props) {
|
|
|
getTags()
|
|
|
}
|
|
|
//树形结构选中事件
|
|
|
- function checkTreeEvent(idsArr) {
|
|
|
- const formData = form.getFieldsValue();
|
|
|
- let arr = formData.softwareVOS[index].dataAuthDetails ? formData.softwareVOS[index].dataAuthDetails : []
|
|
|
- let result = idsArr.filter(ele => {
|
|
|
- return ele.split('-').length == 2
|
|
|
- })
|
|
|
- if (result) {
|
|
|
- result.forEach(it => {
|
|
|
- arr.push({
|
|
|
- dataType: 7,
|
|
|
- detailId: it.split('-')[0],
|
|
|
- detailType: 1
|
|
|
- })
|
|
|
- })
|
|
|
- } else {
|
|
|
- idsArr.forEach(it => {
|
|
|
- arr.push({
|
|
|
- dataType: 7,
|
|
|
- detailId: it.split('-')[1],
|
|
|
- detailType: 2
|
|
|
- })
|
|
|
- })
|
|
|
+ //选中科室
|
|
|
+ function handleCheckDept(checks,e){
|
|
|
+ setCheckedTreeItems(checks);
|
|
|
+ //排序,短的在前长的在后,为去重做准备
|
|
|
+ const posArr = [...e.checkedNodesPositions].sort((a,b)=>{
|
|
|
+ return a.pos.length-b.pos.length;
|
|
|
+ });
|
|
|
+ //console.log('排序后:',posArr);
|
|
|
+ const checkedDepts = structureDeptTag(posArr);
|
|
|
+ let deptIdsArr=[...checkedDepts.deptIds];
|
|
|
+ let deptArr=[...checkedDepts.deptObj];
|
|
|
+ let hosIdsArr=[...checkedDepts.hosIds];
|
|
|
+ let hosArr=[...checkedDepts.hosObj];
|
|
|
+ setCheckedDepts(hosArr.concat(deptArr)); //显示的排序可能需要再考虑一下
|
|
|
+ setCheckedDeptIds(deptIdsArr);
|
|
|
+ setCheckedHosIds(hosIdsArr);
|
|
|
+ //validateReceiver(checkedUserIds.length+deptIdsArr.length+hosIdsArr.length);
|
|
|
+ form.setFieldsValue({sendDepts:deptIdsArr,sendHospitals:hosIdsArr});
|
|
|
+ }
|
|
|
+ //格式化选中科室数据
|
|
|
+ function structureDeptTag(pos){ //全选传医院id,非全选传科室id
|
|
|
+ let tempPos=[],hosIds=[],hosArr=[],len=0,deptIds=[],deptArr=[],temp=[],tempKey='';
|
|
|
+ let it=null,checks=[];
|
|
|
+ for(let i=0;i<pos.length;i++){
|
|
|
+ it=pos[i];
|
|
|
+ tempKey=it.node.key;
|
|
|
+ if(it.pos==='0-0'){ //全选了平台,终止遍历
|
|
|
+ temp = tempKey.split("-");
|
|
|
+ hosArr.push({id:temp[0],name:temp[1],key:tempKey});
|
|
|
+ hosIds.push(temp[0]);
|
|
|
+ setCheckedTreeItems([tempKey]);
|
|
|
+ return {hosIds:hosIds,hosObj:hosArr,deptIds:deptIds,deptObj:deptArr};
|
|
|
+ }
|
|
|
+ //如果当前节点的pos包含了tempPos里的某个数据,说明该节点的父节点已被选中并记录,自身则不需要记录
|
|
|
+ if(!(tempPos.includes(it.pos.substr(0,5))||tempPos.includes(it.pos.substr(0,7)))){
|
|
|
+ tempPos.push(it.pos); //记录需要展示的节点pos,作为去重的依据
|
|
|
+ temp = tempKey.split("-");
|
|
|
+ len=temp.length;
|
|
|
+ //记录选中的节点id,从已选中标签中删除时控制树形结构选中状态用
|
|
|
+ checks.push(tempKey);
|
|
|
+ setCheckedTreeItems(checks);
|
|
|
+ //医院id存入sendHospitals,科室id存入sendDepts
|
|
|
+ if(len===2){
|
|
|
+ hosArr.push({id:temp[0],name:temp[1],key:tempKey});
|
|
|
+ hosIds.push(temp[0]);
|
|
|
+ }else{
|
|
|
+ deptArr.push({id:temp[2],name:temp[1]+"-"+temp[3],key:tempKey});
|
|
|
+ deptIds.push(temp[2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {hosIds:hosIds,hosObj:hosArr,deptIds:deptIds,deptObj:deptArr};
|
|
|
+ }
|
|
|
+ //删除已选用户/科室
|
|
|
+ function handleTagDel(idx,type){ //type=1指定用户,type=2指定科室
|
|
|
+ if(idx===undefined){ //无入参,清空所有
|
|
|
+ //情况树状结构选中状态
|
|
|
+ setCheckedTreeItems([]);
|
|
|
+ //清空用户
|
|
|
+ setCheckedUser([]);
|
|
|
+ setCheckedUserIds([]);
|
|
|
+ //清空科室
|
|
|
+ setCheckedDepts([]);
|
|
|
+ setCheckedDeptIds([]);
|
|
|
+ setCheckedHosIds([]);
|
|
|
+ form.setFieldsValue({sendUsers:[],sendDepts:[],sendHospitals:[]});
|
|
|
+ //校验状态更新
|
|
|
+ setReceiverError(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //const idx=checkedUserIds.findIndex((it)=>it===id);
|
|
|
+ if(type===1){
|
|
|
+ let checkedIdsArr=[...checkedUserIds];
|
|
|
+ let checkedUserArr=[...checkedUser];
|
|
|
+ checkedIdsArr.splice(idx,1);
|
|
|
+ checkedUserArr.splice(idx,1);
|
|
|
+ setCheckedUser(checkedUserArr);
|
|
|
+ setCheckedUserIds(checkedIdsArr);
|
|
|
+ form.setFieldsValue({sendUsers:checkedIdsArr});
|
|
|
+ //校验状态更新--在判断外面不好判断,直接放里面
|
|
|
+ setReceiverError(checkedIdsArr.length===0);
|
|
|
+ }else if(type===2){
|
|
|
+ //删除树结构中对应的选中状态
|
|
|
+ const ikey = checkedDepts[idx].key;
|
|
|
+ const tempItems = [...checkedTreeItems];
|
|
|
+ const index = tempItems.findIndex((it)=>it===ikey);
|
|
|
+ tempItems.splice(index,1);
|
|
|
+ setCheckedTreeItems(tempItems);
|
|
|
+ //console.log(ikey,index,checkedDepts,checkedTreeItems,tempItems)
|
|
|
+ //删除对应的显示数据及传参数据
|
|
|
+ let checkedDeptsArr=[...checkedDepts];
|
|
|
+ let checkedHosIdsArr=[...checkedHosIds];
|
|
|
+ let checkedDeptIdsArr=[...checkedDeptIds];
|
|
|
+ checkedDeptsArr.splice(idx,1);
|
|
|
+ checkedHosIdsArr.splice(idx,1);
|
|
|
+ checkedDeptIdsArr.splice(idx-checkedHosIdsArr.length,1);
|
|
|
+ setCheckedDepts(checkedDeptsArr); //选中的科室和医院合并过的
|
|
|
+ setCheckedHosIds(checkedHosIdsArr);
|
|
|
+ setCheckedDeptIds(checkedDeptIdsArr);
|
|
|
+ form.setFieldsValue({sendUsers:checkedUserIds,sendDepts:checkedDeptIdsArr,sendHospitals:checkedHosIdsArr});
|
|
|
+ //校验状态更新--在判断外面不好判断,直接放里面
|
|
|
+ setReceiverError(checkedDeptsArr.length===0);
|
|
|
+ }
|
|
|
+ //校验状态更新
|
|
|
+ //setReceiverError(checkedUserIds.length+);
|
|
|
}
|
|
|
- formData.softwareVOS[index].dataAuthDetails = unique(arr)
|
|
|
- formData.softwareVOS[index].softwareMenuIds = idsArr
|
|
|
- form.setFieldsValue({
|
|
|
- softwareVOS: formData.softwareVOS
|
|
|
- });
|
|
|
- getTags()
|
|
|
- }
|
|
|
//获取已选中标签
|
|
|
|
|
|
function getTags() {
|
|
@@ -392,13 +433,14 @@ function AddData(props) {
|
|
|
<Input />
|
|
|
</Form.Item>
|
|
|
<Form.Item key={i + "c"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
- <Card title="已选中" extra={<span onClick={delAll} className='del-all'><img className='del-icon' src={del} />清空所有</span>} >
|
|
|
+ {/*<Card title="已选中" extra={<span onClick={delAll} className='del-all'><img className='del-icon' src={del} />清空所有</span>} >
|
|
|
{tags[index].map((tag, i) => {
|
|
|
return (
|
|
|
<Tag key={i} closable onClose={e => delTag(tag.type, tag.id, i)}>{tag.name}</Tag>
|
|
|
);
|
|
|
})}
|
|
|
- </Card>
|
|
|
+ </Card>*/}
|
|
|
+ <SelectedTag userData={checkedUser} deptData={checkedDepts} delTag={handleTagDel}></SelectedTag>
|
|
|
</Form.Item>
|
|
|
<Form.Item key={i + "d"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
<Tabs defaultActiveKey="0" className='tab-content'>
|
|
@@ -413,7 +455,7 @@ function AddData(props) {
|
|
|
<Form.Item
|
|
|
name={['softwareVOS', i, 'softwareMenuIds']}
|
|
|
>
|
|
|
- <MenuTree data={treeData} checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkEv={(checkedKeys) => checkTreeEvent(checkedKeys)} />
|
|
|
+ <MyDeptStruct checkeds={checkedTreeItems} checkEv={handleCheckDept} />
|
|
|
</Form.Item>
|
|
|
</TabPane>
|
|
|
</Tabs>
|