wyq před 3 roky
rodič
revize
672e322c73

+ 254 - 103
src/components/DataManager/AddData.js

@@ -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>

+ 34 - 0
src/components/DataManager/MenuTree.js

@@ -0,0 +1,34 @@
+import { Tree } from 'antd';
+import DataContext from './data-context';
+function MenuTree(props) {
+  const { data, checkEv, checkeds } = props;
+  //console.log(42,checkeds)
+  //菜单选中事件
+
+
+  function onCheck(checkedKeys, e) {
+    const { checkedNodes } = e;
+    let sourceIds = e.node.key.split('-').length
+    // if (sourceIds == 3){
+    //   checkedKeys = []
+    //   checkedKeys.push(e.node.key)
+    // }
+    checkEv(checkedKeys, sourceIds)
+  }
+  function onSelect() {
+
+  }
+  const treeData = data ? data : null;
+  const defaultCheckedKeys = checkeds.softwareMenuIds ? checkeds.softwareMenuIds.slice() : []
+  return (
+    <Tree
+      checkable
+      defaultCheckedKeys={defaultCheckedKeys}
+      onCheck={onCheck}
+      onSelect={onSelect}
+      treeData={treeData}
+    />
+  )
+}
+
+export default MenuTree;

+ 9 - 13
src/components/DataManager/doctorList.js

@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useContext, componentWillReceiveProps } from 'react';
 import { Form, Input, Button, Table, Select, Pagination, Space, TreeSelect, Tag } from 'antd';
 import { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
 import apiObj from '@api/index';
@@ -15,7 +15,7 @@ function DoctorList(props) {
     getHospitalTree()
   }, []);
   
-  const { data,checkDoct} = props;
+  const { checkeds,checkDoct } = props;
   const [form] = Form.useForm();
   const [doctorList, setDoctorList] = useState([]);
   const [name, setName] = useState("");
@@ -23,14 +23,13 @@ function DoctorList(props) {
   const [pages, setPages] = useState("1");
   const [current, setCurrent] = useState("5");
   const [treeData, setTreeData] = useState([]);
-  // const [selectedRowKeys, setSelectedRowKeys] = useState([]);
+  // const [selectedRowKeys, setSelectedRowKeys] = useState();
   const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
     depts: [],
     hospitals: []
   });
-  const selectedRowKeys = data
-
-  
+  const selectedRowKeys = checkeds.selectedRowKeys ? checkeds.selectedRowKeys.slice() : []
+  console.log(selectedRowKeys)
   //获取可看医生列表
   function getDoctorPage() {
     const param = {
@@ -78,7 +77,7 @@ function DoctorList(props) {
   const handlePhone = (event) => {
     setPhone(event.target.value)
   }
-  
+
   const columns = [
     { title: '姓名', dataIndex: 'name', key: 'index' },
     { title: '电话号码', dataIndex: 'mobilePhone', key: 'index' },
@@ -107,12 +106,10 @@ function DoctorList(props) {
     })
     setAddHospitalTreeVO(addHospitalTreeVO)
   };
-  function onSelectChange(selectedRowKeys){
-    console.log(selectedRowKeys);
-    
+  function onSelectChange(selectedRowKeys) {
     checkDoct(selectedRowKeys)
   }
-  function submit(){
+  function submit() {
     getDoctorPage()
   }
   return (
@@ -163,7 +160,7 @@ function DoctorList(props) {
           }}
           columns={columns}
           dataSource={doctorList}
-          rowKey={record => record.id +'-'+ record.name}
+          rowKey={record => record.id + '-' + record.name}
           pagination={{
             showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
             pageSizeOptions: ['15', '30', '60', '120'],
@@ -173,5 +170,4 @@ function DoctorList(props) {
     </div>
   )
 }
-
 export default DoctorList;

+ 4 - 4
src/components/DataManager/index.js

@@ -20,14 +20,15 @@ function DataManager() {
   const [modalType, setModalType] = useState("");
   const [msvisible, setMsvisible] = useState(false);
   const [type, setType] = useState("");
-  const [addVisible, setaddVisible] = useState("false");
+  const [addVisible, setaddVisible] = useState(false);
   const [dataDetail, setDataDetail] = useState(null);
   const [form] = Form.useForm();
   const tipText = {
     1: '确定要删除该数据权限?',
     2: '禁用后该用户将无法登录,确定要禁用该用户?',
   };
-
+  console.log(addVisible);
+  
   const showModal = (name, type, flag) => {
     setaddVisible(true)
     // setVisible(type);
@@ -63,7 +64,6 @@ function DataManager() {
   function addData(formData) {
     let url = api.addAuth;
     console.log(formData)
-    
     // const arr = formData.softwares.filter((it) => {
     //   if (Object.keys(it).length && it.softwareMenuIds && it.softwareMenuIds.length) {
     //     return it;
@@ -149,7 +149,7 @@ function DataManager() {
   if (addVisible) {
     return (
       <DataContext.Provider value={{ save: addData, detail: dataDetail }}>
-        <AddData back={goBack} />
+        <AddData back={goBack}/>
       </DataContext.Provider>
     )
   }

+ 2 - 1
src/components/DataManager/index.less

@@ -17,6 +17,7 @@
   }
 }
 .ant-tree-list-holder-inner{
-  height: 500px;
+  min-height: 100px;
+  max-height: 500px;
   overflow-y: auto;
 }

+ 0 - 1
src/components/UserManager/addUser.js

@@ -74,7 +74,6 @@ function AddUser(props) {
       depts: [],
       hospitals: []
     }
-    console.log(value)
     value.forEach(it => {
       let arr = it.split('-')
       let len = arr.length

+ 8 - 2
src/utils/index.js

@@ -46,7 +46,12 @@ function organizationData(arr) {
     arr = JSON.parse(JSON.stringify(list).replaceAll(/deptName/g, 'title').replaceAll(/deptId/g, 'value'))
     return arr
 }
-
+// 去重
+function unique(arr) {
+    return arr.filter(function (item, index, arr) {
+        return arr.indexOf(item, 0) === index;
+    });
+}
 //时间获取
 function getTimeDetail(){
     const d = new Date();
@@ -62,6 +67,7 @@ const obj = {
     handleResponse,
     pickCheckedTreeIds,
     organizationData,
-    getTimeDetail
+    getTimeDetail,
+    unique
 };
 export default obj;