|
@@ -0,0 +1,294 @@
|
|
|
+import {useEffect,useState} from 'react';
|
|
|
+/*import { useDispatch,useSelector } from 'react-redux'*/
|
|
|
+import { Table,Modal, message, Menu, Breadcrumb, Dropdown, Space, Form, Input, Button, Row, Col, Select } from 'antd';
|
|
|
+import { DownOutlined,PlusOutlined } from '@ant-design/icons';
|
|
|
+import AddSubOrg from './AddSubOrg';
|
|
|
+import './index.less';
|
|
|
+import apiObj from '@api/index';
|
|
|
+import OrgContext from './org-context';
|
|
|
+
|
|
|
+const {post,api,xPost} = apiObj;
|
|
|
+const { Option } = Select;
|
|
|
+function OrgManager(){
|
|
|
+ useEffect(() => {
|
|
|
+ getFilterList();
|
|
|
+ getTableData();
|
|
|
+ },[]);
|
|
|
+
|
|
|
+ const [dataSource, setDataSource] = useState([]);
|
|
|
+ const [typeList,setTypeList] = useState([]);
|
|
|
+ const [visible,setVisible] = useState(false);
|
|
|
+ const [addVisible,setAddVisible] = useState(false);
|
|
|
+ const [confirmLoading, setConfirmLoading] = useState(false);
|
|
|
+ //弹窗类型:1删除 2有子组织、用户删除 3禁用 4有子组织、用户禁用 5重置密码
|
|
|
+ const [modalType,setModalType] = useState(1);
|
|
|
+ const [modalTitle,setModalTitle] = useState(1);
|
|
|
+ const [operId,setOperId] = useState('');
|
|
|
+ const [orgId,setOrgId] = useState('');
|
|
|
+ const [orgName,setOrgName] = useState('');
|
|
|
+
|
|
|
+ const tipText={
|
|
|
+ 1:'确定要删除该组织?',
|
|
|
+ 2:'当前组织内可能包含子组织或其相关用户,删除后所包含信息将一并被删除',
|
|
|
+ 3:'确定要禁用该组织?',
|
|
|
+ 4:'当前组织内可能包含子组织或其相关用户,禁用后所包含信息将一并被禁用',
|
|
|
+ 5:'确定要重置该组织密码?',
|
|
|
+ };
|
|
|
+
|
|
|
+ //获取筛选下拉数据
|
|
|
+ function getFilterList(){
|
|
|
+ post(api.getManagerBoxInfo).then((res)=>{
|
|
|
+ if(res.data.code===200){
|
|
|
+ const data = res.data.data;
|
|
|
+ setTypeList(data[43]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //获取表格数据
|
|
|
+ function getTableData(param={}){
|
|
|
+ post(api.getHospitalListInfo,param).then((res)=>{
|
|
|
+ if(res.data.code===200){
|
|
|
+ const data = res.data.data;
|
|
|
+ setOrgId(data[0]?data[0].hospitalId:'');
|
|
|
+ setOrgName(data[0]?data[0].hospitalName:'')
|
|
|
+ setDataSource(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //启用/禁用
|
|
|
+ function enable(flag,id) {
|
|
|
+ const param = {HospitalId:id||operId,status:flag};
|
|
|
+ xPost(api.disableHospital,param).then((res)=>{
|
|
|
+ if(res.data.code===200){
|
|
|
+ getTableData();
|
|
|
+ setVisible(false);
|
|
|
+ message.success((flag?'启用':'禁用')+"成功");
|
|
|
+ }else{
|
|
|
+ message.warning(res.data.msg||'操作失败');
|
|
|
+ }
|
|
|
+ }).catch(()=>{
|
|
|
+ message.error("接口出错");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //重置密码
|
|
|
+ function onResetPsd(){
|
|
|
+ const param = {HospitalId:operId};
|
|
|
+ xPost(api.resetPassword,param).then((res)=>{
|
|
|
+ if(res.data.code===200){
|
|
|
+ getTableData();
|
|
|
+ setVisible(false)
|
|
|
+ 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();
|
|
|
+ setVisible(false);
|
|
|
+ message.success("删除成功");
|
|
|
+ }else{
|
|
|
+ message.warning(res.data.msg||'操作失败');
|
|
|
+ }
|
|
|
+ }).catch(()=>{
|
|
|
+ message.error("接口出错");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //显示弹窗
|
|
|
+ function showModal(type,id){
|
|
|
+ setModalType(type);
|
|
|
+ setOperId(id);
|
|
|
+ setVisible(true);
|
|
|
+ }
|
|
|
+ //弹窗确认事件
|
|
|
+ function handleOk(){
|
|
|
+ if("1,2".indexOf(modalType)>-1){
|
|
|
+ onDelete();
|
|
|
+ }else if("3,4".indexOf(modalType)>-1){
|
|
|
+ enable(0);
|
|
|
+ }else if(modalType===5){
|
|
|
+ onResetPsd();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //弹窗取消
|
|
|
+ function handleCancel(){
|
|
|
+ setVisible(false);
|
|
|
+ setAddVisible(false);
|
|
|
+ }
|
|
|
+ //新增子组织弹窗
|
|
|
+ function showAddModal(title){
|
|
|
+ setModalTitle(title);
|
|
|
+ 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 RenderTable(){
|
|
|
+ const columns = [
|
|
|
+ { title: '组织机构层级', dataIndex: 'hospitalName', key: 'hospitalName' },
|
|
|
+ { 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: (row) => {
|
|
|
+ //console.log(21,row)
|
|
|
+ if(row.children){
|
|
|
+ return '-'
|
|
|
+ }
|
|
|
+ const menu = (
|
|
|
+ <Menu>
|
|
|
+ <Menu.Item key="0" onClick={()=>showModal(5,row.hospitalId)}>重置密码</Menu.Item>
|
|
|
+ <Menu.Item key="1" onClick={()=>showModal((row.hasUserFlag||row.hasHospitalFlag?2:1),row.hospitalId)}>删除</Menu.Item>
|
|
|
+ </Menu>
|
|
|
+ );
|
|
|
+ return (<Space size="middle">
|
|
|
+ <a>修改</a>
|
|
|
+ {row.status==='1'?(<a onClick={()=>showModal(row.hasUserFlag||row.hasHospitalFlag?4:3,row.hospitalId)}>禁用</a>):(<a onClick={()=>enable(1,row.hospitalId)}>启用</a>)}
|
|
|
+ <Dropdown overlay={menu} trigger={['click']}>
|
|
|
+ <a className="ant-dropdown-link">
|
|
|
+ 更多 <DownOutlined />
|
|
|
+ </a>
|
|
|
+ </Dropdown>
|
|
|
+ </Space>) }},
|
|
|
+ ];
|
|
|
+ return (
|
|
|
+ <Table
|
|
|
+ pagination={false}
|
|
|
+ className="components-table-demo-nested"
|
|
|
+ rowKey={record => record.hospitalId}
|
|
|
+ expandable={{defaultExpandAllRows:true}}
|
|
|
+ columns={columns}
|
|
|
+ dataSource={dataSource}
|
|
|
+ />
|
|
|
+ )
|
|
|
+ }
|
|
|
+ //筛选项渲染
|
|
|
+ const [form] = Form.useForm();
|
|
|
+ const onFinish = (values: any) => {
|
|
|
+ getTableData(values);
|
|
|
+ console.log('筛选项:',values);
|
|
|
+ };
|
|
|
+ const onReset = () => {
|
|
|
+ form.resetFields();
|
|
|
+ getTableData();
|
|
|
+ };
|
|
|
+ return (
|
|
|
+ <div className='container'>
|
|
|
+ <div className="filter-box">
|
|
|
+ <Form form={form} name="control-hooks" onFinish={onFinish}>
|
|
|
+ <Row gutter={24}>
|
|
|
+ <Col span={5} key={0}>
|
|
|
+ <Form.Item name="hospitalName" label="组织名称">
|
|
|
+ <Input placeholder='组织名称'/>
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ <Col span={5} key={1}>
|
|
|
+
|
|
|
+ <Form.Item name="type" label="类型">
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ >
|
|
|
+ <Option value="">全部</Option>
|
|
|
+ {typeList.map((item)=>{
|
|
|
+ return (
|
|
|
+ <Option value={item.name} key={item.name}>{item.val}</Option>
|
|
|
+ )
|
|
|
+ })}
|
|
|
+ </Select>
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ <Col span={5} key={2}>
|
|
|
+ <Form.Item name="status" label="当前状态">
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ >
|
|
|
+ <Option value="">全部</Option>
|
|
|
+ <Option value="1">启用</Option>
|
|
|
+ <Option value="0">禁用</Option>
|
|
|
+ </Select>
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ <Col span={9} key={3}>
|
|
|
+ <Form.Item>
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ 查询
|
|
|
+ </Button>
|
|
|
+ <Button htmlType="button" onClick={onReset}>
|
|
|
+ 重置
|
|
|
+ </Button>
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ <div className="table">
|
|
|
+ <div className="table-header">
|
|
|
+ <Breadcrumb>
|
|
|
+ <Breadcrumb.Item>组织管理</Breadcrumb.Item>
|
|
|
+ </Breadcrumb>
|
|
|
+ <Button type="primary" icon={<PlusOutlined />} onClick={()=> showAddModal('新增子组织')}>新增子组织</Button>
|
|
|
+ </div>
|
|
|
+ <RenderTable />
|
|
|
+ </div>
|
|
|
+ <Modal
|
|
|
+ title="提示"
|
|
|
+ okText='确定'
|
|
|
+ cancelText='取消'
|
|
|
+ width={400}
|
|
|
+ visible={visible}
|
|
|
+ onOk={handleOk}
|
|
|
+ confirmLoading={confirmLoading}
|
|
|
+ onCancel={handleCancel}
|
|
|
+ >
|
|
|
+ <p>{tipText[modalType]}</p>
|
|
|
+ </Modal>
|
|
|
+ <Modal
|
|
|
+ title={modalTitle}
|
|
|
+ footer={null}
|
|
|
+ width={690}
|
|
|
+ visible={addVisible}
|
|
|
+ confirmLoading={confirmLoading}
|
|
|
+ onCancel={handleCancel}
|
|
|
+ >
|
|
|
+ <OrgContext.Provider value={{orgId,orgName,typeList,save:addSubOrg}}>
|
|
|
+ <AddSubOrg />
|
|
|
+ </OrgContext.Provider>
|
|
|
+ </Modal>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default OrgManager;
|