index.js 18 KB

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