Преглед на файлове

组织管理部分接口对接,增加xPost方法

zhouna преди 3 години
родител
ревизия
14eca2b868
променени са 6 файла, в които са добавени 191 реда и са изтрити 27 реда
  1. 23 0
      src/api/index.js
  2. 8 2
      src/api/request.js
  3. 143 23
      src/components/OrgManager/index.js
  4. 1 1
      src/components/OrgManager/index.less
  5. 1 1
      src/store/reducers/tabPanes.js
  6. 15 0
      src/utils/index.js

+ 23 - 0
src/api/index.js

@@ -8,6 +8,28 @@ const post=(url,data)=>{
         data
     });
 };
+const xPost=(url,data)=>{
+    let param = new URLSearchParams();
+    for(let i in data){
+        param.append(i,data[i]);
+    }
+    return axios({
+        method:'post',
+        contentType:'application/x-www-form-urlencoded',
+        url:url,
+        data:param
+    });
+};
+// 导出
+const expJson = (url,data) =>{
+    return axios({
+        method:'post',
+        url,
+        data,
+        contentType: "application/vnd.ms-excel;charset=UTF-8" ,
+        responseType: 'blob' //必须添加,否则会乱码
+    });
+}
 
 const get=(url,data)=>{
     return axios({
@@ -33,6 +55,7 @@ axios.interceptors.request.use(function (req) {
 
 const obj = {
     post,
+    xPost,
     get,
     api,
 };

+ 8 - 2
src/api/request.js

@@ -1,6 +1,12 @@
 const request = {
-    getHospitalListInfo:'/security-center/hospitalManage/getHospitalListInfo',
     login:'/security-center/userManage/login',
-    getManagerBoxInfo:'/security-center/hospitalManage/getManagerBoxInfo',
+    //组织管理相关接口
+    getHospitalListInfo:'/security-center/hospitalManage/getHospitalListInfo',  //列表数据
+    getManagerBoxInfo:'/security-center/hospitalManage/getManagerBoxInfo',  //筛选下拉数据
+    disableHospital:'/security-center/hospitalManage/disableHospital',  //启用禁用
+    deleteHospital:'/security-center/hospitalManage/deleteHospital',    //删除组织
+    addHospital:'security-center/hospitalManage/addHospital', //添加组织
+    updateHospital:'/security-center/hospitalManage/updateHospital',   //修改
+    getHospitalById:'/security-center/hospitalManage/getHospitalById', //获取详情
 };
 export default request;

+ 143 - 23
src/components/OrgManager/index.js

@@ -1,53 +1,158 @@
 import {useEffect,useState} from 'react';
 import { useDispatch,useSelector } from 'react-redux'
-import { Table, Badge, Menu, Dropdown, Space, Form, Input, Button, Row, Col, Select } from 'antd';
+import { Table,Modal, message, Menu, Dropdown, Space, Form, Input, Button, Row, Col, Select } from 'antd';
 import { DownOutlined } from '@ant-design/icons';
 import './index.less';
 import apiObj from '@api/index';
+import utils from '@utils/index';
 
-const {post,api} = apiObj;
+const {post,api,xPost} = apiObj;
+const { handleResponse } = utils;
 const { Option } = Select;
 function OrgManager(){
     useEffect(() => {
+        getFilterList();
         getTableData();
     },[]);
 
     const [dataSource, setDataSource] = useState([]);
-    //const [filterData, setFilterData] = useState({});
+    const [typeList,setTypeList] = useState([]);
+    const [visible,setVisible] = useState(false);
+    const [confirmLoading, setConfirmLoading] = useState(false);
+    //弹窗类型:1删除 2有子组织删除 3有用户删除 4禁用 5有子组织禁用 6有用户禁用 7重置密码
+    const [modalType,setModalType] = useState(1);
+    const [operId,setOperId] = useState('');
+    const tipText={
+        1:'确定要删除该组织?',
+        2:'当前组织存在子组织,删除后子组织将一并被删除',
+        3:'当前组织或子组织存在用户,删除后用户将一并被删除',
+        4:'确定要禁用该组织?',
+        5:'当前组织存在子组织,禁用后子组织将一并被禁用',
+        6:'当前组织或子组织存在用户,禁用后用户将一并被禁用',
+        7:'确定要重置该组织密码?',
+    };
 
+    //获取筛选下拉数据
+    function getFilterList(){
+        post(api.getManagerBoxInfo).then((res)=>{
+            if(res.data.code===200){
+                const data = res.data.data;
+                setTypeList(data["类型"]);
+            }
+        })
+    }
+    //获取表格数据
     function getTableData(param={}){
-        //const param = filterData;
         post(api.getHospitalListInfo,param).then((res)=>{
             if(res.data.code===200){
                 const data = res.data.data;
-                setDataSource(data[0].hospitalDTOS);
+                setDataSource(data);
             }
 
         })
     }
-    function RenderTable(){
-        const menu = (
-            <Menu>
-                <Menu.Item key="0">重置密码</Menu.Item>
-                <Menu.Item key="1">禁用</Menu.Item>
-                <Menu.Item key="3">删除</Menu.Item>
-            </Menu>
-        );
+    //启用/禁用
+    function enable(flag) {
+        const param = {HospitalId:operId,status:flag};
+        xPost(api.disableHospital,param).then((res)=>{
+            if(res.data.code===200){
+                getTableData();
+                message.success((flag?'启用':'禁用')+"成功");
+            }else{
+                message.warning(res.data.msg||'操作失败');
+            }
+        }).catch(()=>{
+            message.error("接口出错");
+        });
+    }
+    //重置密码
+    function onResetPsd(){
+        const param = {HospitalId:operId};
+        xPost(api.disableHospital,param).then((res)=>{
+            if(res.data.code===200){
+                getTableData();
+                message.success("重置成功");
+            }else{
+                message.warning(res.data.msg||'操作失败');
+            }
+        }).catch(()=>{
+            message.error("接口出错");
+        });
+    }
+    //删除
+    function onDelete(){
+        const param = {HospitalId:operId};
+        xPost(api.deleteHospital,param).then((res)=>{
+            if(res.data.code===200){
+                getTableData();
+                message.success("删除成功");
+            }else{
+                message.warning(res.data.msg||'操作失败');
+            }
+        }).catch(()=>{
+            message.error("接口出错");
+        });
+    }
+    //显示弹窗
+    function showModal(type,id){
+        setModalType(type);
+        setOperId(id);
+        setVisible(true);
+    }
+    //弹窗确认事件
+    function handleOk(type){
+        if("1,2,3".indexOf(type)>-1){
+            onDelete();
+        }else if("4,5,6".indexOf(type)>-1){
+            enable(0);
+        }else if(type===7){
+            onResetPsd();
+        }
 
+    }
+    //弹窗取消
+    function handleCancel(){
+        setVisible(false);
+    }
+    //表格渲染
+    function RenderTable(){
         const columns = [
             { title: '组织机构层级', dataIndex: 'hospitalName', key: 'hospitalName' },
-            { title: '类型', dataIndex: 'type', key: 'type' },
-            { title: '状态', dataIndex: 'status', key: 'status' },
+            { title: '类型',  key: 'type',render:(row)=>{
+                    if(row.children){
+                        return '-'
+                    }else{
+                        return row.type;
+                    }
+                } },
+            { title: '状态',  key: 'status',render:(row)=>{
+                    if(row.children){
+                        return '-'
+                    }else{
+                        return row.status;
+                    }
+                } },
             { title: '创建时间', dataIndex: 'gmtCreate', key: 'gmtCreate' },
-            { title: '操作', key: 'operation', render: () => (<Space size="middle">
+            { title: '操作', key: 'operation', render: (row) => {
+                //console.log(21,row)
+                if(row.children){
+                    return '-'
+                }
+                const menu = (
+                    <Menu>
+                        <Menu.Item key="0" onClick={(row)=>showModal(7,row.hospitalId)}>重置密码</Menu.Item>
+                        <Menu.Item key="1" onClick={(row)=>showModal(1,row.hospitalId)}>删除</Menu.Item>
+                    </Menu>
+                );
+                return (<Space size="middle">
                     <a>修改</a>
-                    <a>启用</a>
+                    {row.status==='1'?(<a onClick={()=>showModal(4,row.hospitalId)}>禁用</a>):(<a onClick={()=>enable(row,1)}>启用</a>)}
                     <Dropdown overlay={menu} trigger={['click']}>
                         <a className="ant-dropdown-link">
                             更多 <DownOutlined />
                         </a>
                     </Dropdown>
-                </Space>) },
+                </Space>) }},
         ];
         return (
             <Table
@@ -58,14 +163,12 @@ function OrgManager(){
             />
         )
     }
-
+    //筛选项渲染
     const [form] = Form.useForm();
-
     const onFinish = (values: any) => {
         getTableData(values);
         console.log('筛选项:',values);
     };
-
     const onReset = () => {
         form.resetFields();
         getTableData();
@@ -82,13 +185,17 @@ function OrgManager(){
                             </Form.Item>
                         </Col>
                         <Col span={5} key={1}>
+
                             <Form.Item name="type" label="类型">
                                 <Select
                                     allowClear
                                 >
                                     <Option value="">全部</Option>
-                                    <Option value="female">集团医院</Option>
-                                    <Option value="other">医共体</Option>
+                                    {/*{typeList.map((item)=>{
+                                        return (
+                                            <Option value={item.value}>{item.name}</Option>
+                                        )
+                                    })}*/}
                                 </Select>
                             </Form.Item>
                         </Col>
@@ -116,7 +223,20 @@ function OrgManager(){
                     </Row>
                 </Form>
             </div>
+
             <RenderTable />
+            <Modal
+                title="提示"
+                okText='确定'
+                cancelText='取消'
+                width={400}
+                visible={visible}
+                onOk={handleOk}
+                confirmLoading={confirmLoading}
+                onCancel={handleCancel}
+            >
+                <p>{tipText[modalType]}</p>
+            </Modal>
         </div>
     )
 }

+ 1 - 1
src/components/OrgManager/index.less

@@ -3,7 +3,7 @@
 .container{
   background: #fff;
   margin:14px ;
-  padding:38px 28px;
+  padding:17px 28px;
 }
 .ant-table-thead > tr > th{
   background: @table-th-color;

+ 1 - 1
src/store/reducers/tabPanes.js

@@ -4,7 +4,7 @@ export const slice = createSlice({
     name: 'tabPanes',
     initialState: {
         activeTab: '',
-        panes:[{title:'111',content:'111',key:'111'}]
+        panes:[]
     },
     reducers: {
         close: (state,action) => {        //关闭tab

+ 15 - 0
src/utils/index.js

@@ -0,0 +1,15 @@
+import {message} from 'antd';
+//统一处理请求成功、失败
+
+function handleResponse(res,callback,error){
+    if(res.data.code===200){
+        callback()
+    }else{
+        message.warning('操作失败'||res.data.msg);
+        error();
+    }
+}
+const obj = {
+    handleResponse
+};
+export default obj;