소스 검색

Merge remote-tracking branch 'origin/dev' into dev

zhouna 3 년 전
부모
커밋
47b3a7ac4a

+ 10 - 2
src/api/request.js

@@ -24,10 +24,18 @@ const request = {
 
 
     //用户管理相关接口
-    getHospitalTree:"/security-center/userManage/getHospitalTree",
+    getUserPage: '/security-center/userManage/getUserPage',//用户列表
+    getHospitalTree: "/security-center/userManage/getHospitalTree",
     addUser: '/security-center/userManage/addUser',//添加用户
+    updateUser: '/security-center/userManage/updateUser',//修改用户
     getUserById: '/security-center/userManage/getUserById',//查看用户
     disableUser: '/security-center/userManage/disableUser',//禁用用户
+    deleteUser: '/security-center/userManage/deleteUser',//删除用户
+
+
+    //数据权限相关接口
     getDataAuthPage: '/security-center/dataAuthManage/getDataAuthPage',//数据权限列表
-};
+    disableAuth: '/security-center/dataAuthManage/disableAuth',//禁用
+    getDoctorPage: '/security-center/dataAuthManage/getDoctorPage',//医生列表
+}
 export default request;

+ 234 - 0
src/components/DataManager/AddData.js

@@ -0,0 +1,234 @@
+import { useEffect, useState, useContext } from 'react';
+import { Form, Input, Button, Steps, Tabs, Space, Switch, Breadcrumb, Radio, TreeSelect, Tree, Tag } from 'antd';
+import './index.less';
+import DataContext from './data-context';
+import apiObj from '@api/index';
+import backIcon from "@images/back.png";
+import DoctorList from "./doctorList"
+const { post, api, xPost } = apiObj;
+const { SHOW_PARENT } = TreeSelect;
+const { Step } = Steps;
+const { TabPane } = Tabs;
+function AddData(props) {
+  const { back } = props;
+  const [value, setValue] = useState('1');
+  const [treeRloe, setTreeRloe] = useState([]);
+  const [tags, setTags] = useState(['Unremovable', 'Tag 2', 'Tag 3']);
+  const [form] = Form.useForm();
+  const layout = {
+    labelCol: { span: 3 },
+    wrapperCol: { span: 20 },
+  };
+  const treeData = [
+    {
+      title: '0-0',
+      key: '0-0',
+      children: [
+        {
+          title: '0-0-0',
+          key: '0-0-0',
+          children: [
+            {
+              title: '0-0-0-0',
+              key: '0-0-0-0',
+            },
+            {
+              title: '0-0-0-1',
+              key: '0-0-0-1',
+            },
+            {
+              title: '0-0-0-2',
+              key: '0-0-0-2',
+            },
+          ],
+        },
+        {
+          title: '0-0-1',
+          key: '0-0-1',
+          children: [
+            {
+              title: '0-0-1-0',
+              key: '0-0-1-0',
+            },
+            {
+              title: '0-0-1-1',
+              key: '0-0-1-1',
+            },
+            {
+              title: '0-0-1-2',
+              key: '0-0-1-2',
+            },
+          ],
+        },
+        {
+          title: '0-0-2',
+          key: '0-0-2',
+        },
+      ],
+    },
+    {
+      title: '0-1',
+      key: '0-1',
+      children: [
+        {
+          title: '0-1-0-0',
+          key: '0-1-0-0',
+        },
+        {
+          title: '0-1-0-1',
+          key: '0-1-0-1',
+        },
+        {
+          title: '0-1-0-2',
+          key: '0-1-0-2',
+        },
+      ],
+    },
+    {
+      title: '0-2',
+      key: '0-2',
+    },
+  ];
+  const [expandedKeys, setExpandedKeys] = useState(['0-0-0', '0-0-1']);
+  const [checkedKeys, setCheckedKeys] = useState(['0-0-0']);
+  const [selectedKeys, setSelectedKeys] = useState([]);
+  const [autoExpandParent, setAutoExpandParent] = useState(true);
+
+
+  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) => {
+    console.log('onSelect', info);
+    setSelectedKeys(selectedKeysValue);
+  };
+  const validateMessages = {
+    required: '${label} is required!',
+    types: {
+      email: '${label} is not a valid email!',
+      number: '${label} is not a valid number!',
+    },
+    number: {
+      range: '${label} must be between ${min} and ${max}',
+    },
+  };
+  const onChange = e => {
+    console.log('radio checked', e.target.value);
+    setValue(e.target.value)
+  };
+  function callback(key) {
+    console.log(key);
+  }
+  const onFinish = (values: any) => {
+    console.log(values);
+  };
+  function swichChange(val) {
+    form.setFieldsValue({ status: val ? 1 : 0 })
+  }
+  return (
+    <>
+      <Breadcrumb separator="">
+        <Breadcrumb.Item><img className='back-icon' src={backIcon} onClick={back} alt="返回上一页" /></Breadcrumb.Item>
+        <Breadcrumb.Item>组织管理</Breadcrumb.Item>
+        <Breadcrumb.Separator />
+        <Breadcrumb.Item>新增子组织</Breadcrumb.Item>
+      </Breadcrumb>
+      <Form {...layout} name="nest-messages" onFinish={onFinish} validateMessages={validateMessages}>
+        <Form.Item name={['user', 'name']} label="数据权限名称" rules={[{ required: true }]}>
+          <Input placeholder="请填写数据权限名称" />
+        </Form.Item>
+        <Form.Item name={['user', 'email']} label="权限范围" rules={[{ type: 'email' }]}>
+          <Tabs defaultActiveKey="1" onChange={callback} >
+            <TabPane tab="AI终末质控系统" key="1">
+              <Radio.Group onChange={onChange} value={value} className="radio">
+                <Space direction="vertical">
+                  <Radio value={1}>全部组织</Radio>
+                  <Radio value={2}>全部科室</Radio>
+                  <Radio value={3}>全部科室除本科室外</Radio>
+                  <Radio value={4}>本科室</Radio>
+                  <Radio value={5}>本医疗组</Radio>
+                  <Radio value={6}>本人</Radio>
+                  <Radio value={7}>自定义</Radio>
+                </Space>
+              </Radio.Group>
+            </TabPane>
+            <TabPane tab="AI终末质控系统" key="2">
+              Content of Tab Pane 2
+            </TabPane>
+          </Tabs>
+        </Form.Item>
+        <Form.Item>
+          {tags.map((tag, index) => {
+            return (
+              <Tag>{tag}</Tag>
+            );
+          }
+          )
+          }
+        </Form.Item>
+
+        <Form.Item
+          name="roles"
+          label="所属角色"
+        >
+          <Tabs defaultActiveKey="1" onChange={callback} >
+            <TabPane tab="AI终末质控系统" key="1">
+              <DoctorList />
+            </TabPane>
+            <TabPane tab="AI终末质控系统" key="2">
+              <Tree
+                checkable
+                onExpand={onExpand}
+                expandedKeys={expandedKeys}
+                autoExpandParent={autoExpandParent}
+                onCheck={onCheck}
+                checkedKeys={checkedKeys}
+                onSelect={onSelect}
+                selectedKeys={selectedKeys}
+                treeData={treeData}
+              />
+            </TabPane>
+          </Tabs>
+        </Form.Item>
+        <Form.Item
+          name="roles"
+          label="所属角色"
+        >
+          <TreeSelect
+            showSearch={false}
+            treeData={treeRloe}
+            treeCheckable
+            showCheckedStrategy={SHOW_PARENT}
+            placeholder="请选择组织"
+            style={{ width: '100%' }}
+          />
+        </Form.Item>
+        <Form.Item
+          name="status"
+          valuePropName="checked"
+          label="当前状态"
+          rules={[{ required: true, message: '请选择状态' }]}
+        >
+          <Switch onChange={swichChange} />
+        </Form.Item>
+        <Form.Item wrapperCol={{ ...layout.wrapperCol, offset: 8 }}>
+          <Button type="primary" htmlType="submit">
+            Submit
+        </Button>
+        </Form.Item>
+      </Form>
+    </>
+  )
+}
+
+export default AddData;

+ 4 - 0
src/components/DataManager/data-context.js

@@ -0,0 +1,4 @@
+import { createContext } from 'react';
+const DataContext = createContext(null);
+
+export default DataContext;

+ 174 - 0
src/components/DataManager/doctorList.js

@@ -0,0 +1,174 @@
+import React, { useState, useEffect } 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';
+const { post, api, xPost } = apiObj;
+const { Option } = Select;
+const { SHOW_PARENT } = TreeSelect;
+function DoctorList() {
+  useEffect(() => {
+    getDoctorPage();
+    getHospitalTree()
+  }, []);
+  const [doctorList, setDoctorList] = useState([]);
+  const [name, setName] = useState("");
+  const [phone, setPhone] = useState("");
+  const [pages, setPages] = useState("1");
+  const [current, setCurrent] = useState("5");
+  const [treeData, setTreeData] = useState([]);
+  const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
+    depts: [],
+    hospitals: []
+  });
+  const [form] = Form.useForm();
+
+  //获取可看医生列表
+  function getDoctorPage() {
+    const param = {
+      pages: pages,
+      current: current,
+      mobilePhone: phone,
+      name: name,
+      depts: addHospitalTreeVO.depts,
+      hospitals: unique(addHospitalTreeVO.hospitals)
+    }
+    post(api.getDoctorPage, param).then((res) => {
+      if (res.data.code === 200) {
+        const data = res.data.data;
+        setDoctorList(data.records);
+      }
+    })
+  }
+  //获取当前用户组织
+  function getHospitalTree() {
+    post(api.getHospitalTree).then((res) => {
+      if (res.data.code === 200) {
+        const data = res.data.data;
+        let arr = data[0].children ? data[0].children[0].children : []
+        setTreeData(arr)
+      }
+    })
+  }
+  // 处理组织结构数据
+  function organizationData(arr) {
+    let list = []
+    arr.forEach(item => {
+      list.push({
+        children: item.depts,
+        title: item.hospitalName,
+        value: item.parentId + '-' + item.hospitalId
+      })
+      item.depts.forEach(its => {
+        its.value = item.parentId + '-' + item.hospitalId + '-' + its.deptId
+      })
+    })
+    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;
+    });
+  }
+  const onFinish = (value) => {
+    getDoctorPage(value);
+  };
+  const onReset = () => {
+    form.resetFields();
+    getDoctorPage();
+  };
+  const handleName = (event) => {
+    setName(event.target.value)
+  }
+  const handlePhone = (event) => {
+    setPhone(event.target.value)
+  }
+  
+  const columns = [
+    { title: '姓名', dataIndex: 'name', key: 'index' },
+    { title: '电话号码', dataIndex: 'mobilePhone', key: 'index' },
+    { title: '所属组织', dataIndex: 'hospitalName', key: 'index' },
+  ]
+  const onChange = value => {
+    let addHospitalTreeVO = {
+      depts: [],
+      hospitals: []
+    }
+    value.forEach(it => {
+      let arr = it.split('-')
+      let len = arr.length
+      if (len == 3) {
+        addHospitalTreeVO.depts.push(arr[2])
+      } else {
+        addHospitalTreeVO.hospitals.push(arr[1])
+        organizationData(treeData).forEach(item => {
+          if (item.value.split('-')[1] == arr[1]) {
+            item.children.forEach(its => {
+              addHospitalTreeVO.depts.push(its.value.split('-')[2])
+            })
+          }
+        })
+      }
+    })
+    setAddHospitalTreeVO(addHospitalTreeVO)
+  };
+  function submit(){
+    getDoctorPage()
+  }
+  return (
+    <div className="wrapper">
+      <div className="doctor_header">
+        <div className="doctor_header_left">
+          <div className="left_item">
+            姓名:<Input placeholder="用户名" onChange={e => handleName(e)} style={{ width: 160 }} />
+          </div>
+          <div className="left_item">
+            手机号码:<Input placeholder="用户名" onChange={e => handlePhone(e)} style={{ width: 160 }} />
+          </div>
+          <div className="left_item">
+            所属组织:
+            <TreeSelect
+              showSearch={false}
+              treeData={organizationData(treeData)}
+              onChange={onChange}
+              treeCheckable
+              maxTagCount={1}
+              showCheckedStrategy={SHOW_PARENT}
+              placeholder="请选择组织"
+              style={{ width: 160 }}
+            />
+          </div>
+          <div className="left_item">
+            <Space size="middle">
+              <Button onClick={onReset}>
+                重置
+              </Button>
+              <Button type="primary" onClick={submit}>
+                查询
+              </Button>
+            </Space>
+          </div>
+        </div>
+      </div>
+
+      <div className="table">
+        <div className="table-header">
+          <span className="table-header-title">医生列表</span>
+        </div>
+
+        <Table
+          columns={columns}
+          dataSource={doctorList}
+          rowKey={record => record.id}
+          pagination={{
+            showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
+            pageSizeOptions: ['15', '30', '60', '120'],
+            pageSize: 5,
+          }} />
+      </div>
+    </div>
+  )
+}
+
+export default DoctorList;

+ 85 - 55
src/components/DataManager/index.js

@@ -1,24 +1,36 @@
 import React, { useState, useEffect } from 'react';
-import { Form, Input, Button, Table, Select, Pagination, Space, Modal,Row,Col } from 'antd';
+import { Form, Input, Button, Table, Select, Pagination, Space, Modal, message, Row, Col } from 'antd';
 import { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
 // import NormalPlayer from './testComponent/testComponent'
 import '@common/common.less';
 import apiObj from '@api/index';
-const { post, api } = apiObj;
+import DataContext from './data-context';
+import AddData from './AddData';
+
+const { post, api, xPost } = apiObj;
 const { Option } = Select;
-function UserManager() {
+function DataManager() {
   useEffect(() => {
     getDataAuthPage();
   }, []);
   const [userList, setUserList] = useState([]);
   const [title, setTitle] = useState("");
+  const [id, setId] = useState("");
   const [visible, setVisible] = useState(false);
-  const ChildrenChange = (val) => {//这个val就是子组件传来的
-    setVisible(false);
-  }
-  const showModal = (name, type) => {
+  const [modalType, setModalType] = useState("");
+  const [msvisible, setMsvisible] = useState(false);
+  const [type, setType] = useState("");
+  const [addVisible, setaddVisible] = useState("false");
+  const [form] = Form.useForm();
+  const tipText = {
+    1: '确定要删除该数据权限?',
+    2: '禁用后该用户将无法登录,确定要禁用该用户?',
+  };
+
+  const showModal = (name, type, flag) => {
     setVisible(type);
     setTitle(name);
+    setType(flag)
   }
   function getDataAuthPage(param = {}) {
     //const param = filterData;
@@ -29,19 +41,22 @@ function UserManager() {
       }
     })
   }
-  const disableUser = (userId, status) => {
+  //禁用启用
+  const disableAuth = (id, status) => {
     let params = {
-      userId: userId,
+      id: id,
       status: status
     }
-    post(api.disableUser, params).then((res) => {
+    xPost(api.disableAuth, params).then((res) => {
       if (res.data.code === 200) {
-        const data = res.data.data;
-        setUserList(data.records);
+        getDataAuthPage();
+        setMsvisible(false);
+        message.success((status ? '启用' : '禁用') + "成功");
+      } else {
+        message.warning(res.data.msg || '操作失败');
       }
     })
   };
-  const [form] = Form.useForm();
 
   const onFinish = (value) => {
     getDataAuthPage(value);
@@ -50,61 +65,76 @@ function UserManager() {
     form.resetFields();
     getDataAuthPage();
   };
-
-  function confirm() {
-    Modal.confirm({
-      title: '提示',
-      icon: <ExclamationCircleOutlined />,
-      content: 'Bla bla ...',
-      okText: '确认',
-      cancelText: '取消',
-      onOk() {
-        console.log('OK');
-      },
-      onCancel() {
-        console.log('Cancel');
-      },
-    });
-  }
+  const messageBox = (type, id) => {
+    setMsvisible(true)
+    setId(id)
+    setModalType(type)
+  };
   const columns = [
-    { title: '数据权限名称', dataIndex: 'key' },
-    { title: '所属角色', dataIndex: 'key' },
+    { title: '数据权限名称', dataIndex: 'name', key: 'index' },
+    { title: '所属角色', dataIndex: 'roleName', key: 'index' },
     {
-      title: '状态', dataIndex: 'key', render: (text, record) => (
+      title: '状态', dataIndex: 'status', key: 'status', render: (text, record) => (
         <Space size="middle">
-          {record.age == 1 ? (
-            <a>查看</a>
-          ) : (
-              <a >修改</a>
-            )}
+          {record.status == 1 ?
+            <span className="Enable">启用</span>
+            :
+            <span className="Disable">禁用</span>
+          }
         </Space>
       )
     },
     {
       title: '操作', dataIndex: 'key', render: (text, record) => (
         <Space size="middle">
-          <a>修改</a>
-          <a onClick={e => showModal('修改用户', true)} >禁用</a>
-          <a onClick={e => showModal('修改用户', true)} >删除</a>
+          <a onClick={e => showModal('查看用户', true, 3)}>修改</a>
+          {record.status === '1' ? (<a onClick={() => messageBox(2, record.id)}>禁用</a>) : (<a onClick={() => disableAuth(record.id, 1)}>启用</a>)}
+          <a onClick={e => showModal('修改用户', true, 1)} >删除</a>
         </Space>
       )
     }
   ]
-
-  const data = [];
-  for (let i = 0; i < 100; i++) {
-    data.push({
-      key: i,
-      name: 'John Brown',
-      age: i + 1,
-      street: 'Lake Park',
-      building: 'C',
-      number: 2035,
-      companyAddress: 'Lake Street 42',
-      companyName: 'SoftLake Co',
-      gender: 'M',
+  function showAddData() {
+    setaddVisible(true)
+  }
+  //保存
+  function addSubOrg(formData) {
+    console.log('保存参数:', formData);
+    const param = formData;
+    post(api.addHospital, param).then((res) => {
+      if (res.data.code === 200) {
+        // getTableData();
+        // setAddVisible(false);
+        message.success("添加成功");
+      } else {
+        message.warning(res.data.msg || '操作失败');
+      }
+    }).catch(() => {
+      message.error("接口出错");
     });
   }
+  //提示框确认事件
+  function handleOk() {
+    if (modalType == 2) {
+      disableAuth(id, 0)
+    } else if (modalType == 2) {
+      disableAuth(id, 0)
+    }
+  }
+  //提示框取消
+  function handleCancel() {
+    setMsvisible(false);
+  }
+  function goBack() {
+    setaddVisible(false)
+  }
+  if (addVisible) {
+    return (
+      <DataContext.Provider value={{ save: addSubOrg }}>
+        <AddData back={goBack} />
+      </DataContext.Provider>
+    )
+  }
   return (
     <div className="wrapper">
         <div className="filter-box">
@@ -161,7 +191,7 @@ function UserManager() {
 
         <Table
           columns={columns}
-          dataSource={data}
+          dataSource={userList}
           pagination={{
             showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
             pageSizeOptions: ['15', '30', '60', '120'],
@@ -176,4 +206,4 @@ function UserManager() {
   )
 }
 
-export default UserManager;
+export default DataManager;

+ 18 - 0
src/components/DataManager/index.less

@@ -0,0 +1,18 @@
+.radio{
+  margin: 13px 20px;
+}
+.doctor_header{
+ padding: 17px 0 0 20px;
+ .doctor_header_left{
+   display: flex;
+    .left_item{
+      margin-right: 44px;
+    }
+  }
+}
+.table-header{
+  padding:16px 0 6px 0!important;
+  .table-header-title{
+    font-size: 16px;
+  }
+}

+ 8 - 6
src/components/PageLayout/index.js

@@ -5,7 +5,7 @@ import AHeader from '../AHeader'
 import AMenu from '../AMenu'
 import ATabs from '../ATabs'
 import apiObj from '@api/index';
-import { setStatusList, setHisTypeList} from '@reducers/staticInfo';
+import { setStatusList, setHisTypeList, setTitleList, setDataList} from '@reducers/staticInfo';
 
 const {  Content, Sider } = Layout;
 const {post,api,xPost} = apiObj;
@@ -19,16 +19,18 @@ function PageLayout(){
     const staticInfo =useSelector(state => {
         return state.staticInfo;
     });
-    function getStaticInfos(){
-        const {hisTypeList,statusList} = staticInfo;
-        if([...hisTypeList,...statusList].length>0){
+    function getStaticInfos() {
+        const { hisTypeList, statusList, titleList, dataList } = staticInfo;
+        if ([...hisTypeList, ...statusList, ...titleList, ...dataList].length > 0) {
             return;
         }
-        post(api.getManagerBoxInfo).then((res)=>{
-            if(res.data.code===200){
+        post(api.getManagerBoxInfo).then((res) => {
+            if (res.data.code === 200) {
                 const data = res.data.data;
                 dispatch(setHisTypeList(data[43]));
                 dispatch(setStatusList(data[47]));
+                dispatch(setTitleList(data[40]));
+                dispatch(setDataList(data[48]));
             }
         })
     }

+ 125 - 81
src/components/UserManager/addUser.js

@@ -1,87 +1,53 @@
 import React, {
-  useState, useEffect, useRef, useImperativeHandle, forwardRef
+  useState, useEffect, useContext
 } from 'react';
-import { Modal, Form, Input, Select, Button, Switch, TreeSelect, message } from 'antd';
+import { Modal, Form, Input, Select, Button, Switch, TreeSelect, message, Space } from 'antd';
 import apiObj from '@api/index';
-const { post, api } = apiObj;
+import utils from '@utils/index'
+import UserContext from './user-context';
+import { useSelector } from 'react-redux'
+import Item from 'antd/lib/list/Item';
+const { post, api, xPost } = apiObj;
+const { organizationData } = utils;
 const { Option, OptGroup } = Select;
 const { SHOW_PARENT } = TreeSelect;
-
-const formItemLayout = {
-  labelCol: {
-    xs: { span: 36 },
-    sm: { span: 8 },
-  },
-  wrapperCol: {
-    xs: { span: 24 },
-    sm: { span: 16 },
-  },
-};
-const tailFormItemLayout = {
-  wrapperCol: {
-    xs: {
-      span: 24,
-      offset: 0,
-    },
-    sm: {
-      span: 16,
-      offset: 8,
-    },
-  },
-};
-function NormalPlayer(props, parentRef) {
-  const { title, visible, type } = props
-  const inputRef = useRef();
+function AddUser(props) {
+  useEffect(() => {
+    getHospitalTree();
+    getCreateRoles()
+  }, []);
+  const [form] = Form.useForm();
+  const { userId, type, formData } = useContext(UserContext);
   const [treeData, setTreeData] = useState([]);
   const [treeRloe, setTreeRloe] = useState([]);
   const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
     depts: [],
     hospitals: []
   });
-  const [form] = Form.useForm();
-  useEffect(() => {
-    getHospitalTree();
-    getCreateRoles()
-  }, []);
-  // 父组件获取的值
-  useImperativeHandle(parentRef, () => {
-    return {
-      form: form.getFieldsValue(),
-      addHospitalTreeVO
-    }
-  })
-  const hideModal = () => {
-    form.resetFields();
-  };
+  const staticInfo = useSelector(state => {
+    return state.staticInfo;
+  });
+  const { titleList } = staticInfo;
+  const initialValues = formData;
+  console.log(initialValues)
   //获取当前用户组织
   function getHospitalTree() {
     post(api.getHospitalTree).then((res) => {
       if (res.data.code === 200) {
         const data = res.data.data;
-        let arr = data[0].children ? data[0].children[0].children : []
+        let arr = data[0].children ? data[0].children : []
+        arr = organizationData(arr)
         setTreeData(arr)
       }
     })
   }
-  // 处理组织结构数据
-  function organizationData(arr) {
-    let list = []
-    arr.forEach(item => {
-      list.push({
-        children: item.depts,
-        title: item.hospitalName,
-        value: item.parentId + '-' + item.hospitalId
-      })
-      item.depts.forEach(its => {
-        its.value = item.parentId + '-' + item.hospitalId + '-' + its.deptId
-      })
-    })
-    arr = JSON.parse(JSON.stringify(list).replaceAll(/deptName/g, 'title').replaceAll(/deptId/g, 'value'))
-    return arr
-  }
+
   //获取当前用于所属角色
   function getCreateRoles() {
-    post(api.getCreateRoles).then((res) => {
+    const params = {
+      softwareId: ''
+    }
+    xPost(api.getCreateRoles, params).then((res) => {
       if (res.data.code === 200) {
         const data = res.data.data;
         let arr = JSON.parse(JSON.stringify(data).replaceAll(/name/g, 'title').replaceAll(/id/g, 'value'))
@@ -89,6 +55,12 @@ function NormalPlayer(props, parentRef) {
       }
     })
   }
+  // 去重
+  function unique(arr) {
+    return arr.filter(function (item, index, arr) {
+      return arr.indexOf(item, 0) === index;
+    });
+  }
   function swichChange(val) {
     form.setFieldsValue({ status: val ? 1 : 0 })
   }
@@ -105,17 +77,33 @@ function NormalPlayer(props, parentRef) {
       hospitals: []
     }
     value.forEach(it => {
-      let arr = it.split('-')
-      let len = arr.length
-      if (len == 3) {
-        addHospitalTreeVO.depts.push(arr[2])
-        addHospitalTreeVO.hospitals.push(arr[1])
+      if (JSON.stringify(it).indexOf("-") != -1) {
+        let arr = it.split('-')
+        let len = arr.length
+        if (len == 3) {
+          addHospitalTreeVO.depts.push(arr[2])
+          addHospitalTreeVO.hospitals.push(arr[1])
+        } else {
+          addHospitalTreeVO.hospitals.push(arr[1])
+          treeData.forEach(item => {
+            item.children && item.children.forEach(tit => {
+              if (tit.value.split('-')[1] == arr[1]) {
+                tit.children.forEach(its => {
+                  addHospitalTreeVO.depts.push(its.value.split('-')[2])
+                })
+              }
+            })
+          })
+        }
       } else {
-        addHospitalTreeVO.hospitals.push(arr[1])
-        organizationData(treeData).forEach(item => {
-          if (item.value.split('-')[1] == arr[1]) {
-            item.children.forEach(its => {
-              addHospitalTreeVO.depts.push(its.value.split('-')[2])
+        addHospitalTreeVO.hospitals.push(it)
+        treeData.forEach(item => { 
+          if (item.value == it){
+            item.children && item.children.forEach(its => {
+              addHospitalTreeVO.hospitals.push(its.value.split('-')[1])
+              its.children && its.children.forEach(lit => {
+                addHospitalTreeVO.depts.push(lit.value.split('-')[2])
+              })
             })
           }
         })
@@ -123,18 +111,59 @@ function NormalPlayer(props, parentRef) {
     })
     setAddHospitalTreeVO(addHospitalTreeVO)
   };
+  const onChangeRloe = value => {
+    form.setFieldsValue({ roles: value })
+  };
+  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 addUser(param) {
+    post(api.addUser, param).then((res) => {
+      if (res.data.code === 200) {
+        props.userChange()
+        message.success(res.data.message);
+        form.resetFields();
+      } else {
+        message.error(res.data.message);
+      }
+    })
+  }
+  function editUser(param) {
+    post(api.updateUser, 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 (
     <>
       <Form
-        {...formItemLayout}
+        labelCol={{ span: 6 }}
+        wrapperCol={{ span: 16 }}
         form={form}
         name="register"
-        scrollToFirstError
+        onFinish={onFinish}
+        initialValues={initialValues}
       >
         <Form.Item
           name="username"
           label="用户名"
-
           rules={[
             {
               required: true,
@@ -142,6 +171,7 @@ function NormalPlayer(props, parentRef) {
             },
           ]}
         >
+
           <Input placeholder="用户名是组织中唯一标识,请勿重复" disabled={type == 3 ? true : false} />
         </Form.Item>
         <Form.Item
@@ -211,7 +241,7 @@ function NormalPlayer(props, parentRef) {
         >
           <TreeSelect
             showSearch={false}
-            treeData={organizationData(treeData)}
+            treeData={treeData}
             onChange={onChange}
             treeCheckable
             showCheckedStrategy={SHOW_PARENT}
@@ -225,9 +255,11 @@ function NormalPlayer(props, parentRef) {
           label="职称"
         >
           <Select placeholder="请选择职称" disabled={type == 3 ? true : false}>
-            <Option value="male">Male</Option>
-            <Option value="female">Female</Option>
-            <Option value="other">Other</Option>
+            {titleList.map((item) => {
+              return (
+                <Option value={item.name} key={item.name}>{item.val}</Option>
+              )
+            })}
           </Select>
         </Form.Item>
         <Form.Item
@@ -245,8 +277,9 @@ function NormalPlayer(props, parentRef) {
             showSearch={false}
             treeData={treeRloe}
             treeCheckable
+            onChange={onChangeRloe}
             showCheckedStrategy={SHOW_PARENT}
-            placeholder="请选择组织"
+            placeholder="请选择角色"
             style={{ width: '100%' }}
             disabled={type == 3 ? true : false}
           />
@@ -265,8 +298,19 @@ function NormalPlayer(props, parentRef) {
         >
           <Switch onChange={swichChange} disabled={type == 3 ? true : false} />
         </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 forwardRef(NormalPlayer);
+
+export default AddUser;

+ 89 - 86
src/components/UserManager/index.js

@@ -1,13 +1,15 @@
 import React, { useState, useEffect, useRef } from 'react';
-import { Form, Input, Button, Table, Select, Pagination, Space, Menu, Dropdown, Modal, Row, Col, message } from 'antd';
+import { Form, Input, Button, Table, Select, Pagination, Space, Menu, Dropdown, Modal, Breadcrumb, message, Row, Col } from 'antd';
 import { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
-import NormalPlayer from './addUser'
+import AddUser from './addUser'
 import '@common/common.less';
 import apiObj from '@api/index';
+import utils from '@utils/index'
+import UserContext from './user-context';
 const { post, api, xPost } = apiObj;
+const { organizationData } = utils;
 const { Option } = Select;
 function UserManager() {
-  const parentRef = useRef();
   useEffect(() => {
     getUserPage();
   }, []);
@@ -18,32 +20,32 @@ function UserManager() {
   const [msvisible, setMsvisible] = useState(false);
   const [modalType, setModalType] = useState("");
   const [type, setType] = useState("");
+  const [formData, setFormData] = useState(null);
+  const [username, setUsername] = useState(null);
+
   const [form] = Form.useForm();
   const tipText = {
     1: '确定要删除该用户?',
     2: '禁用后该用户将无法登录,确定要禁用该用户?',
     3: '确定要重置该用户密码?',
   };
-  const ChildrenChange = (val) => {
-    setVisible(false);
-    getUserPage()
-  }
-  const getChildrenMsg = (result, msg) => {
-    // console.log(result, msg)
-    // 很奇怪这里的result就是子组件那bind的第一个参数this,msg是第二个参数
-  }
   //新增弹窗
-  const showModal = (name, type, flag) => {
+  const showModal = (name, type, flag, userId) => {
     setVisible(type);
     setTitle(name);
     setType(flag)
-    if (flag == 3) {
-      getUserById()
+    setUserId(userId)
+    if (flag == 1) {
+      setFormData({
+        status: '1'
+      })
+    }
+    if (flag == 3 || flag == 2) {
+      getUserById(userId)
     }
   }
   //表格数据
   function getUserPage(param = {}) {
-    //const param = filterData;
     post(api.getUserPage, param).then((res) => {
       if (res.data.code === 200) {
         const data = res.data.data;
@@ -52,12 +54,29 @@ function UserManager() {
     })
   }
   //查看用户
-  function getUserById() {
-    xPost(api.getUserById, { userId: 39 }).then((res) => {
+  function getUserById(userId) {
+    xPost(api.getUserById, { userId: userId }).then((res) => {
       if (res.data.code === 200) {
         const data = res.data.data;
-        // let arr = JSON.parse(JSON.stringify(data).replaceAll(/name/g, 'title').replaceAll(/id/g, 'value'))
-        // setTreeRloe(arr)
+        let roles = []
+        data.roles.forEach(item => {
+          roles.push(item.roleId)
+        })
+        const arr = {
+          username: data.username,
+          mobilePhone: data.mobilePhone,
+          password: data.password,
+          againpassword: data.password,
+          name: data.name,
+          idcard: data.idcard,
+          // addHospitalTreeVO: organizationData(data.hospitals[0].children[0].children),
+          titleId: data.titleId,
+          jobNo: data.jobNo,
+          roles: roles,
+          orderNo: data.orderNo,
+          status: data.status,
+        }
+        setFormData(arr)
       }
     })
   }
@@ -76,10 +95,6 @@ function UserManager() {
       message.error("接口出错");
     });
   }
-  // 启用/禁用用户
-  function enable(userId, status) {
-    disableUser(userId, status)
-  }
   //重置密码
   function onResetPsd() {
     // const param = { HospitalId: operId };
@@ -95,9 +110,9 @@ function UserManager() {
     // });
   }
   //删除
-  function onDelete() {
+  function deleteUser() {
     const param = { userId: userId };
-    xPost(api.deleteHospital, param).then((res) => {
+    xPost(api.deleteUser, param).then((res) => {
       if (res.data.code === 200) {
         getUserPage();
         message.success("删除成功");
@@ -108,16 +123,7 @@ function UserManager() {
       message.error("接口出错");
     });
   }
-  // 确定按钮
-  function addUser(param = {}) {
-    //const param = filterData;
-    post(api.addUser, param).then((res) => {
-      if (res.data.code === 200) {
-        message.success(res.data.message);
-        form.resetFields();
-      }
-    })
-  }
+
   const onFinish = (value) => {
     getUserPage(value);
   };
@@ -130,31 +136,11 @@ function UserManager() {
     setUserId(id)
     setModalType(type)
   };
-  // 新增
-  const submit = () => {
-    console.log(parentRef.current)
-    form
-      .validateFields()
-      .then((values) => {
-        let params = parentRef.current.form
-        parentRef.current.addHospitalTreeVO.hospitals = unique(parentRef.current.addHospitalTreeVO.hospitals)
-        params.addHospitalTreeVO = parentRef.current.addHospitalTreeVO
-        addUser(params)
-      })
-      .catch((info) => {
-        console.log('Validate Failed:', info);
-      });
-  }
-  // 去重
-  function unique(arr) {
-    return arr.filter(function (item, index, arr) {
-      return arr.indexOf(item, 0) === index;
-    });
-  }
+
   //提示框确认事件
   function handleOk() {
-    if (modalType == 2) {
-      disableUser(userId, 0)
+    if (modalType == 1) {
+      deleteUser(userId)
     } else if (modalType == 2) {
       disableUser(userId, 0)
     } else if (modalType == 3) {
@@ -165,6 +151,13 @@ function UserManager() {
   function handleCancel() {
     setMsvisible(false);
   }
+  function cancel() {
+    setVisible(false)
+    setFormData(null)
+  }
+  function userChange() {
+    setVisible(false)
+  }
   const columns = [
     { title: '用户名', dataIndex: 'username', key: 'index' },
     { title: '姓名', dataIndex: 'name', key: 'index' },
@@ -184,8 +177,8 @@ function UserManager() {
     {
       title: '操作', dataIndex: 'key', render: (text, record) => (
         <Space size="middle">
-          <a onClick={e => showModal('查看用户', true, 3)}>查看</a>
-          <a onClick={e => showModal('修改用户', true, 2)} >修改</a>
+          <a onClick={e => showModal('查看用户', true, 3, record.userId)}>查看</a>
+          <a onClick={e => showModal('修改用户', true, 2, record.userId)} >修改</a>
           <Dropdown overlay={menu.bind(this, record)} record={record}>
             <a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
               更多 <DownOutlined />
@@ -204,10 +197,10 @@ function UserManager() {
           </a>
         </Menu.Item>
         <Menu.Item key="1">
-          {record.status === '1' ? (<a onClick={() => messageBox(2, record.userId)}>禁用</a>) : (<a onClick={() => enable(record.userId, 1)}>启用</a>)}
+          {record.status === '1' ? (<a onClick={() => messageBox(2, record.userId)}>禁用</a>) : (<a onClick={() => disableUser(record.userId, 1)}>启用</a>)}
         </Menu.Item>
         <Menu.Item key="2">
-          <a target="_blank" rel="noopener noreferrer" href="https://www.aliyun.com">
+          <a target="_blank" onClick={() => messageBox(1, record.userId)}>
             删除
           </a>
         </Menu.Item>
@@ -216,7 +209,7 @@ function UserManager() {
   }
   return (
     <div className="wrapper">
-        <div className="filter-box">
+      <div className="filter-box">
         <Form
           form={form}
           name="normal_login"
@@ -224,16 +217,16 @@ function UserManager() {
           onFinish={onFinish}
           initialValues={{ status: '' }}
         >
-            <Row gutter={24}>
-              <Col span={6} key={0}>
-                <Form.Item label="用户名" name="username">
-                  <Input placeholder="用户名" />
-                </Form.Item>
-              </Col>
-              <Col span={6} key={1}>
-                <Form.Item label="姓名" name="name">
-                  <Input placeholder="姓名" />
-                </Form.Item>
+          <Row gutter={24}>
+            <Col span={6} key={0}>
+              <Form.Item label="用户名" name="username">
+                <Input placeholder="用户名" />
+              </Form.Item>
+            </Col>
+            <Col span={6} key={1}>
+              <Form.Item label="姓名" name="name">
+                <Input placeholder="姓名" />
+              </Form.Item>
             </Col>
             <Col span={8} key={2}>
               <Form.Item label="当前状态" name="status">
@@ -253,7 +246,7 @@ function UserManager() {
                   <Button type="primary" htmlType="submit">
                     查询
                 </Button>
-                <Button onClick={onReset}>
+                  <Button onClick={onReset}>
                     重置
                 </Button>
                 </Space>
@@ -262,9 +255,12 @@ function UserManager() {
           </Row>
         </Form>
       </div>
+
       <div className="table">
         <div className="table-header">
-            <h2 className="table-title">组织管理</h2>
+          <Breadcrumb>
+            <Breadcrumb.Item>用户管理</Breadcrumb.Item>
+          </Breadcrumb>
           <Button type="primary" icon={<PlusOutlined />} onClick={e => showModal('新增用户', true, 1)}>新增用户</Button>
         </div>
 
@@ -278,17 +274,24 @@ function UserManager() {
             pageSize: 5,
           }} />
       </div>
-      <Modal
-        title="提示"
-        okText='确定'
-        cancelText='取消'
-        width={400}
-        visible={visible}
-        onOk={submit}
-        onCancel={handleCancel}
-      >
-        <NormalPlayer title={title} visible={visible} type={type} ref={parentRef}></NormalPlayer>
-      </Modal>
+      {visible && formData ?
+        <Modal
+          title={title}
+          okText='确定'
+          cancelText='取消'
+          width={'45%'}
+          height={'50%'}
+          visible={visible}
+          onCancel={cancel}
+          footer={null}
+          forceRender={true}
+        >
+          <UserContext.Provider value={{ userId: userId, type: type, formData: formData }}>
+            <AddUser userChange={userChange} />
+          </UserContext.Provider>
+
+        </Modal>
+        : ''}
       <Modal
         title="提示"
         okText='确定'

+ 4 - 0
src/components/UserManager/user-context.js

@@ -0,0 +1,4 @@
+import { createContext } from 'react';
+const UserContext = createContext(null);
+
+export default UserContext;

+ 9 - 1
src/store/reducers/staticInfo.js

@@ -5,6 +5,8 @@ export const slice = createSlice({
     initialState: {
         hisTypeList:[],        //医院类型列表
         statusList:[],      //启/禁用状态列表
+        titleList:[],    //职称数据
+        dataList: [],    //数据范围
     },
     reducers: {
         setStatusList: (state,action) => {
@@ -13,9 +15,15 @@ export const slice = createSlice({
         setHisTypeList: (state,action) => {
             state.hisTypeList = action.payload;
         },
+        setTitleList: (state, action) => {
+            state.titleList = action.payload;
+        },
+        setDataList: (state, action) => {
+            state.dataList = action.payload;
+        },
     },
 });
 
-export const { setStatusList, setHisTypeList} = slice.actions;
+export const { setStatusList, setHisTypeList, setTitleList, setDataList} = slice.actions;
 
 export default slice.reducer;

+ 38 - 17
src/utils/index.js

@@ -1,35 +1,56 @@
-import {message} from 'antd';
+import { message } from 'antd';
 //统一处理请求成功、失败
 
-function handleResponse(res,callback,error){
-    if(res.data.code===200){
+function handleResponse(res, callback, error) {
+    if (res.data.code === 200) {
         callback()
-    }else{
-        message.warning('操作失败'||res.data.msg);
+    } else {
+        message.warning('操作失败' || res.data.msg);
         error();
     }
 }
 
-function pickCheckedTreeIds(data,menuIds=[],resourceIds=[]){
+function pickCheckedTreeIds(data, menuIds = [], resourceIds = []) {
     let arr = data.children;
-    if(data.relation==='1'){
-        data.softwareMenuId&&menuIds.push(data.softwareMenuId);
-        data.softwareResourceId&&resourceIds.push(data.softwareResourceId);
+    if (data.relation === '1') {
+        data.softwareMenuId && menuIds.push(data.softwareMenuId);
+        data.softwareResourceId && resourceIds.push(data.softwareResourceId);
     }
-    if(arr){
-        arr.map((it)=>{
-            pickCheckedTreeIds(it,menuIds,resourceIds);
+    if (arr) {
+        arr.map((it) => {
+            pickCheckedTreeIds(it, menuIds, resourceIds);
         });
     }
     return {
-        id:data.softwareId,
-        name:data.softwareName,
-        softwareMenuIds:menuIds,
-        softwareResourceIds:resourceIds
+        id: data.softwareId,
+        name: data.softwareName,
+        softwareMenuIds: menuIds,
+        softwareResourceIds: resourceIds
     }
 }
+// 处理组织结构数据
+function organizationData(arr) {
+    let list = []
+    arr.forEach(it => {
+        it.value = it.hospitalId
+        it.title = it.hospitalName
+        it.children && it.children.forEach(item => {
+            list.push({
+                children: item.depts,
+                title: item.hospitalName,
+                value: item.parentId + '-' + item.hospitalId
+            })
+            item.depts.forEach(its => {
+                its.value = item.parentId + '-' + item.hospitalId + '-' + its.deptId
+            })
+            it.children = JSON.parse(JSON.stringify(list).replaceAll(/deptName/g, 'title').replaceAll(/deptId/g, 'value'))
+        })
+    })
+    return arr
+}
 const obj = {
     handleResponse,
-    pickCheckedTreeIds
+    pickCheckedTreeIds,
+    organizationData
 };
 export default obj;