index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import { useEffect, useState } from 'react';
  2. import { useSelector } from 'react-redux'
  3. import { Table, Modal, message, Menu, Breadcrumb, Dropdown, Space, Form, Input, Button, Row, Col, Select } from 'antd';
  4. import { DownOutlined, PlusOutlined } from '@ant-design/icons';
  5. import AddSubOrg from './AddSubOrg';
  6. import './index.less';
  7. import apiObj from '@api/index';
  8. import OrgContext from './org-context';
  9. import utils from '@utils/index'
  10. const { pickCheckedTreeIds, getValueFromEvent } = utils;
  11. const { post, api, xPost } = apiObj;
  12. const { Option } = Select;
  13. function OrgManager() {
  14. useEffect(() => {
  15. //监听resize事件
  16. // setTableHt(window.innerHeight - 260);
  17. // window.addEventListener('resize', () => {
  18. // setTableHt(window.innerHeight - 260);
  19. // });
  20. //刷新列表
  21. setOrgType(localStorage.getItem('type'))
  22. getTableData();
  23. //解绑事件
  24. // return function clear() {
  25. // window.removeEventListener("resize");
  26. // }
  27. }, []);
  28. const [dataSource, setDataSource] = useState([]); //列表数据
  29. // const [tableHt, setTableHt] = useState(300); //表格滚动高度
  30. const [visible, setVisible] = useState(false); //删除禁用确认弹窗显示
  31. const [addVisible, setAddVisible] = useState(false); //新增页面显示
  32. const [confirmLoading, setConfirmLoading] = useState(false);
  33. //弹窗类型:1删除 2有子组织、用户删除 3禁用 4有子组织、用户禁用 5重置密码
  34. const [modalType, setModalType] = useState(1);
  35. const [operId, setOperId] = useState(''); //当前操作的组织id
  36. const [orgId, setOrgId] = useState(''); //上级组织id
  37. const [orgName, setOrgName] = useState(''); //上级组织名称,新增修改用
  38. const [orgDetail, setOrgDetail] = useState(null);
  39. const [typeId, setTypeId] = useState('');
  40. const [orgType, setOrgType] = useState(localStorage.getItem('type'));
  41. // const [hisTypeList, setHisTypeList] = useState([]);
  42. const [type, setType] = useState('');
  43. //从state中取出状态、类型列表
  44. const staticInfo = useSelector(state => {
  45. return state.staticInfo;
  46. });
  47. const { hisTypeList, statusList } = staticInfo;
  48. const tipText = {
  49. 1: '确定要删除该组织?',
  50. 2: '当前组织内可能包含子组织或其相关用户,删除后所包含信息将一并被删除',
  51. 3: '确定要禁用该组织?',
  52. 4: '当前组织内可能包含子组织或其相关用户,禁用后所包含信息将一并被禁用',
  53. 5: '确定要重置该组织密码?',
  54. 6: '您还有内容未保存,确定要退出?',
  55. };
  56. //获取表格数据
  57. function getTableData(param = {}) {
  58. post(api.getHospitalListInfo, param).then((res) => {
  59. if (res.data.code === 200) {
  60. let data = res.data.data
  61. console.log('组织列表数据:', data);
  62. let obj = {};
  63. if (orgType == 4) {
  64. data.map((it, i) => {
  65. delete it.children
  66. it.depts.forEach(its => {
  67. its.hospitalId = it.hospitalId
  68. });
  69. it.children = it.depts
  70. });
  71. }
  72. setOrgId(data[0] ? data[0].hospitalId : '');
  73. setOrgName(data[0] ? data[0].hospitalName : '')
  74. setDataSource(data);
  75. }
  76. })
  77. }
  78. //启用/禁用
  79. function enable(flag, id, type) {
  80. const param = { HospitalId: id || operId, status: flag, type: type || typeId };
  81. xPost(api.disableHospital, param).then((res) => {
  82. if (res.data.code === 200) {
  83. getTableData();
  84. setVisible(false);
  85. message.success((flag ? '启用' : '禁用') + "成功");
  86. } else {
  87. message.warning(res.data.msg || '操作失败');
  88. }
  89. }).catch(() => {
  90. message.error("接口出错");
  91. });
  92. }
  93. //重置密码
  94. function onResetPsd() {
  95. const param = { HospitalId: operId };
  96. xPost(api.resetPassword, param).then((res) => {
  97. if (res.data.code === 200) {
  98. getTableData();
  99. setVisible(false)
  100. message.success("重置成功");
  101. } else {
  102. message.warning(res.data.msg || '操作失败');
  103. }
  104. }).catch(() => {
  105. message.error("接口出错");
  106. });
  107. }
  108. //删除
  109. function onDelete() {
  110. const param = { HospitalId: operId, type: typeId };
  111. xPost(api.deleteHospital, param).then((res) => {
  112. if (res.data.code === 200) {
  113. getTableData();
  114. setVisible(false);
  115. message.success("删除成功");
  116. } else {
  117. message.warning(res.data.msg || '操作失败');
  118. }
  119. }).catch(() => {
  120. message.error("接口出错");
  121. });
  122. }
  123. //显示弹窗
  124. function showModal(type, id, flag) {
  125. setModalType(type);
  126. setOperId(id);
  127. setVisible(true);
  128. setTypeId(flag)
  129. }
  130. //弹窗确认事件
  131. function handleOk() {
  132. if ("1,2".indexOf(modalType) > -1) {
  133. onDelete();
  134. } else if ("3,4".indexOf(modalType) > -1) {
  135. enable(0);
  136. } else if (modalType === 5) {
  137. onResetPsd();
  138. }
  139. }
  140. //弹窗取消
  141. function handleCancel() {
  142. setVisible(false);
  143. setAddVisible(false);
  144. }
  145. //新增子组织弹窗
  146. function showAddOrg() {
  147. setAddVisible(true);
  148. setType(1)
  149. setOrgDetail({
  150. parentId: orgId,
  151. parentName: orgName,
  152. status: 1,
  153. type: orgType == 4 ? '科室' : ''
  154. })
  155. }
  156. function getOrgDetail(id, type) {
  157. xPost(api.getHospitalById, { HospitalId: id, type: type }).then((res) => {
  158. const { data, code } = res.data;
  159. if (code === 200) {
  160. structDetail(data);
  161. //setOrgDetail(res.data.data);
  162. } else {
  163. message.warning(res.data.msg || '获取详情失败')
  164. }
  165. });
  166. }
  167. function structDetail(data) {
  168. const content = JSON.parse(JSON.stringify(data).replace(/getHospitalUserDTO/g, "addHospitalUserVO"));
  169. const menuData = content.getRoleDTO ? content.getRoleDTO.loginUserMenuResourceTree : [];
  170. content.confirmPsd = content.addHospitalUserVO.password
  171. let softwares = [], sids = [];
  172. for (let i = 0; i < menuData.length; i++) {
  173. const obj = pickCheckedTreeIds(menuData[i]);
  174. softwares.push(obj);
  175. sids.push(obj.id);
  176. }
  177. const fData = Object.assign({}, content, { softwares, sids });
  178. setOrgDetail(fData);
  179. }
  180. //修改子组织
  181. function editSubOrg(id, type, deptId) {
  182. if (orgType == 4) {
  183. getOrgDetail(deptId, type);
  184. } else {
  185. getOrgDetail(id, type);
  186. }
  187. setAddVisible(true);
  188. setType(2)
  189. setOperId(id);
  190. }
  191. //保存
  192. function addSubOrg(formData) {
  193. const param = formData;
  194. let url = api.addHospital
  195. const arr = formData.softwares.filter((it) => {
  196. if (Object.keys(it).length && it.softwareMenuIds && it.softwareMenuIds.length) {
  197. return it;
  198. }
  199. });
  200. if (orgType == 4) {
  201. param.type = 5
  202. param.addHospitalUserVO = {
  203. username:'122',
  204. password:'111'
  205. }
  206. param.softwares = [{
  207. id: 1,
  208. softwareMenuIds: ['1'],
  209. softwareResourceIds: ['2'],
  210. }]
  211. }else{
  212. formData.softwares = arr;
  213. }
  214. if (type == 2) {
  215. url = api.updateHospital
  216. param.id = operId
  217. }
  218. post(url, param).then((res) => {
  219. if (res.data.code === 200) {
  220. getTableData();
  221. setAddVisible(false);
  222. setOrgDetail(null)
  223. message.success("添加成功");
  224. } else {
  225. message.warning(res.data.msg || '操作失败');
  226. }
  227. }).catch(() => {
  228. message.error("接口出错");
  229. });
  230. }
  231. function goBack() {
  232. setAddVisible(false);
  233. setOrgDetail(null)
  234. }
  235. //表格渲染
  236. function RenderTable() {
  237. let columns
  238. if (orgType == 4) {
  239. columns = [
  240. {
  241. title: '组织机构层级', key: 'type', render: (row) => {
  242. if (row.children) {
  243. return row.hospitalName
  244. } else {
  245. return row.deptName;
  246. }
  247. }
  248. },
  249. { title: '类型', width: 150, key: 'type', dataIndex: 'typeName' },
  250. {
  251. title: '病区', key: 'type', render: (row) => {
  252. if (row.children) {
  253. return '-'
  254. } else {
  255. return row.regionName;
  256. }
  257. }
  258. },
  259. {
  260. title: '状态', width: 120, key: 'status', render: (row) => {
  261. if (row.children) {
  262. return '-'
  263. } else {
  264. return (<span className={(row.status === '1') ? 'Enable' : 'Disable'}>{row.statusName}</span>);
  265. }
  266. }
  267. },
  268. { title: '创建时间', width: 240, dataIndex: 'gmtCreate', key: 'gmtCreate' },
  269. {
  270. title: '操作', width: 240, key: 'operation', render: (row) => {
  271. //console.log(21,row)
  272. if (row.rootFlag) {
  273. return '-'
  274. }
  275. const menu = (
  276. <Menu>
  277. <Menu.Item key="0" onClick={() => showModal(5, row.hospitalId)}>重置密码</Menu.Item>
  278. <Menu.Item key="1" onClick={() => showModal((row.hasUserFlag || row.hasHospitalFlag ? 2 : 1), row.hospitalId, row.type)}>删除</Menu.Item>
  279. </Menu>
  280. );
  281. return (<Space size="middle">
  282. <a onClick={() => editSubOrg(row.hospitalId, row.type, row.deptId)}>修改</a>
  283. {row.status === '1' ? (<a className='disable' onClick={() => showModal(row.hasUserFlag || row.hasHospitalFlag ? 4 : 3, row.hospitalId, row.type)}>禁用</a>) : (<a onClick={() => enable(1, row.hospitalId, row.type)}>启用</a>)}
  284. <Dropdown overlay={menu} trigger={['click']}>
  285. <a className="ant-dropdown-link">
  286. 更多 <DownOutlined />
  287. </a>
  288. </Dropdown>
  289. </Space>)
  290. }
  291. },
  292. ];
  293. return (
  294. <Table
  295. pagination={false}
  296. scroll={{ y: 'calc(100vh - 320px)' }}
  297. className="components-table-demo-nested"
  298. rowKey={record => record.deptId}
  299. columns={columns}
  300. dataSource={dataSource}
  301. />
  302. )
  303. } else {
  304. columns = [
  305. { title: '组织机构层级', dataIndex: 'hospitalName', key: 'hospitalName' },
  306. {
  307. title: '类型', width: 150, key: 'type', render: (row) => {
  308. if (row.children) {
  309. return '-'
  310. } else {
  311. return row.typeName;
  312. }
  313. }
  314. },
  315. {
  316. title: '状态', width: 120, key: 'status', render: (row) => {
  317. if (row.children) {
  318. return '-'
  319. } else {
  320. return (<span className={(row.status === '1') ? 'Enable' : 'Disable'}>{row.statusName}</span>);
  321. }
  322. }
  323. },
  324. { title: '创建时间', width: 240, dataIndex: 'gmtCreate', key: 'gmtCreate' },
  325. {
  326. title: '操作', width: 240, key: 'operation', render: (row) => {
  327. //console.log(21,row)
  328. if (row.rootFlag) {
  329. return '-'
  330. }
  331. const menu = (
  332. <Menu>
  333. <Menu.Item key="0" onClick={() => showModal(5, row.hospitalId)}>重置密码</Menu.Item>
  334. <Menu.Item key="1" onClick={() => showModal((row.hasUserFlag || row.hasHospitalFlag ? 2 : 1), row.hospitalId, row.type)}>删除</Menu.Item>
  335. </Menu>
  336. );
  337. return (<Space size="middle">
  338. <a onClick={() => editSubOrg(row.hospitalId, row.type)}>修改</a>
  339. {row.status === '1' ? (<a className='disable' onClick={() => showModal(row.hasUserFlag || row.hasHospitalFlag ? 4 : 3, row.hospitalId, row.type)}>禁用</a>) : (<a onClick={() => enable(1, row.hospitalId, row.type)}>启用</a>)}
  340. <Dropdown overlay={menu} trigger={['click']}>
  341. <a className="ant-dropdown-link">
  342. 更多 <DownOutlined />
  343. </a>
  344. </Dropdown>
  345. </Space>)
  346. }
  347. },
  348. ];
  349. return (
  350. <Table
  351. pagination={false}
  352. className="components-table-demo-nested"
  353. rowKey={record => record.hospitalId}
  354. columns={columns}
  355. dataSource={dataSource}
  356. />
  357. )
  358. }
  359. }
  360. //筛选项渲染
  361. const [form] = Form.useForm();
  362. const onFinish = (values: any) => {
  363. getTableData(values);
  364. console.log('筛选项:', values);
  365. };
  366. const onReset = () => {
  367. form.resetFields();
  368. getTableData();
  369. };
  370. if (addVisible && orgDetail) {
  371. return (
  372. <OrgContext.Provider value={{ type, save: addSubOrg, detail: orgDetail }}>
  373. <AddSubOrg back={goBack} />
  374. </OrgContext.Provider>
  375. )
  376. }
  377. return (
  378. <div className='wrapper'>
  379. <div className="filter-box">
  380. <Form form={form} name="control-hooks" onFinish={onFinish}>
  381. <Row gutter={24}>
  382. <Col span={5} key={0}>
  383. <Form.Item name="hospitalName" label="组织名称" getValueFromEvent={getValueFromEvent}>
  384. <Input placeholder='组织名称' autoComplete="off"/>
  385. </Form.Item>
  386. </Col>
  387. <Col span={5} key={1}>
  388. <Form.Item name="type" label={orgType == 4 ? '所属病区' : '类型'}>
  389. <Select
  390. allowClear
  391. >
  392. {hisTypeList.map((item) => {
  393. return (
  394. <Option value={item.name} key={item.name}>{item.val}</Option>
  395. )
  396. })}
  397. </Select>
  398. </Form.Item>
  399. </Col>
  400. <Col span={5} key={2}>
  401. <Form.Item name="status" label="当前状态">
  402. <Select
  403. allowClear
  404. >
  405. {statusList.map((item) => {
  406. return (
  407. <Option value={item.name} key={item.name}>{item.val}</Option>
  408. )
  409. })}
  410. </Select>
  411. </Form.Item>
  412. </Col>
  413. <Col span={9} key={3}>
  414. <Form.Item>
  415. <Button type="primary" htmlType="submit">
  416. 查询
  417. </Button>
  418. <Button htmlType="button" onClick={onReset}>
  419. 重置
  420. </Button>
  421. </Form.Item>
  422. </Col>
  423. </Row>
  424. </Form>
  425. </div>
  426. <div className="table">
  427. <div className="table-header">
  428. <h2 className="table-title">组织管理</h2>
  429. <Button type="primary" icon={<PlusOutlined />} onClick={() => showAddOrg()}>新增子组织</Button>
  430. </div>
  431. <RenderTable />
  432. </div>
  433. <Modal
  434. title="提示"
  435. okText='确定'
  436. cancelText='取消'
  437. width={400}
  438. visible={visible}
  439. onOk={handleOk}
  440. confirmLoading={confirmLoading}
  441. onCancel={handleCancel}
  442. >
  443. <p>{tipText[modalType]}</p>
  444. </Modal>
  445. </div>
  446. )
  447. }
  448. export default OrgManager;