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. 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. getTableData();
  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;