index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Form, Input, Button, Table, Select, TreeSelect, Pagination, Space, Menu, Dropdown, Modal, Breadcrumb, message, Row, Col, Spin } from 'antd';
  3. import { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
  4. import AddUser from './AddPara'
  5. import '@common/common.less';
  6. import { useSelector } from 'react-redux'
  7. import apiObj from '@api/index';
  8. import UserContext from './para-context';
  9. import utils from '@utils/index'
  10. const { getValueFromEvent } = utils;
  11. const { post, api, xPost } = apiObj;
  12. const { Option } = Select;
  13. function DictManager() {
  14. useEffect(() => {
  15. getHospitalSet();
  16. getHospitalNames();
  17. }, []);
  18. const [dictList, setDictList] = useState([]);
  19. const [title, setTitle] = useState("");
  20. const [visible, setVisible] = useState(false);
  21. const [id, setParaId] = useState("");
  22. const [val, setParaVal] = useState("");
  23. const [hospitalName, setHospitalName] = useState([]);
  24. const [code, setParaCode] = useState("");
  25. const [status, setParaStatus] = useState("");
  26. const [remark, setParaRemark] = useState("");
  27. const [msvisible, setMsvisible] = useState(false);
  28. const [modalType, setModalType] = useState("");
  29. const [type, setType] = useState("");
  30. const [formData, setFormData] = useState(null);
  31. const [username, setUsername] = useState(null);
  32. const [roleList, setRoleList] = useState([]);
  33. const [size, setSize] = useState(15);
  34. const [HospitalNamesList, setHospitalNamesList] = useState([]);
  35. const [total, setTotal] = useState(0);
  36. const [current, setCurrent] = useState(1);
  37. const { organizationData } = utils;
  38. const { SHOW_PARENT } = TreeSelect;
  39. const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
  40. depts: [],
  41. hospitals: []
  42. });
  43. const [params, setParams] = useState({
  44. pages: 1,
  45. current: 1,
  46. size: 15,
  47. name: '',
  48. groupType: '',
  49. code: ''
  50. });
  51. const [query, setQuery] = useState({
  52. hospitalName: ''
  53. });
  54. const [form] = Form.useForm();
  55. const tipText = {
  56. 1: '确定要删除该参数?',
  57. 2: '禁用后该用户将无法登录,确定要禁用该参数?',
  58. 3: '确定要重置该用户密码?',
  59. };
  60. const staticInfo = useSelector(state => {
  61. return state.staticInfo;
  62. });
  63. let list = []
  64. let data = {
  65. pages: 1,
  66. current: 1,
  67. size: size
  68. }
  69. const {statusList } = staticInfo;
  70. let addHospitalTreeVOs = {
  71. depts: [],
  72. hospitals: [],
  73. }
  74. //新增弹窗
  75. const showModal = (title, type, flag, id, hospitalName, name, val, code, remark, status) => {
  76. setVisible(type);
  77. setType(flag)
  78. setParaId(id)
  79. setHospitalName(hospitalName)
  80. setParaVal(val)
  81. setTitle(title);
  82. setParaCode(code)
  83. setParaRemark(remark)
  84. setParaStatus(status)
  85. if (flag == 1) {
  86. setFormData({
  87. status: '1'
  88. })
  89. }
  90. if ( flag == 2) {
  91. setFormData({
  92. id: id,
  93. hospitalName: hospitalName,
  94. name: name,
  95. val: val,
  96. code: code,
  97. remark: remark,
  98. status: '1',
  99. })
  100. }
  101. }
  102. //表格数据
  103. function getHospitalSet(param) {
  104. post(api.getHospitalSet, param || params).then((res) => {
  105. if (res.data.code === 200) {
  106. const data = res.data.data;
  107. console.log('参数列表数据:', data);
  108. setDictList(data.records);
  109. setTotal(data.total)
  110. }
  111. })
  112. }
  113. //获取当前所属组织
  114. function getHospitalNames() {
  115. xPost(api.getHospitalNames, query).then((res) => {
  116. console.log('所属组织??', res);
  117. if (res.data.code === 200) {
  118. const data = res.data.data;
  119. console.log('所属组织??', data);
  120. let HospitalNamesList = []
  121. HospitalNamesList = data.map(item => {
  122. return item.hospitalName
  123. })
  124. setHospitalNamesList(HospitalNamesList)
  125. }
  126. })
  127. }
  128. const onChange = value => {
  129. value.forEach(it => {
  130. if (JSON.stringify(it).indexOf('-') > 0) {
  131. addHospitalTreeVOs.depts.push(it.split('-')[1])
  132. } else {
  133. addHospitalTreeVOs.hospitals.push(it)
  134. gethospitals(HospitalNamesList, it)
  135. }
  136. })
  137. setAddHospitalTreeVO(addHospitalTreeVOs)
  138. console.log(form.getFieldsValue())
  139. };
  140. //递归获取科室
  141. function gethospitals(arr, val) {
  142. arr.forEach(item => {
  143. if (item.value == val) {
  144. if (item.children) {
  145. getdepts(item.children)
  146. }
  147. if (item.children && item.depts) {
  148. item.children.forEach(item => {
  149. addHospitalTreeVOs.depts.push(item.value.split('-')[1])
  150. })
  151. }
  152. } else {
  153. if (item.children) {
  154. gethospitals(item.children, val)
  155. }
  156. }
  157. })
  158. }
  159. //递归获取医院
  160. function getdepts(arr) {
  161. arr.forEach(item => {
  162. if (JSON.stringify(item.value).indexOf('-') < 0) {
  163. addHospitalTreeVOs.hospitals.push(item.value)
  164. }
  165. if (item.children && item.depts) {
  166. item.children.forEach(it => {
  167. addHospitalTreeVOs.depts.push(it.value.split('-')[1])
  168. })
  169. return
  170. }
  171. if (item.children) {
  172. getdepts(item.children)
  173. }
  174. })
  175. }
  176. // 处理组织结构数据回显
  177. function getHospitals(arr) {
  178. arr.forEach((item, i, array) => {
  179. item.value = item.hospitalId
  180. item.title = item.hospitalName
  181. if (!item.children && item.depts) {
  182. item.depts.forEach(it => {
  183. it.value = item.parentId + '-' + it.deptId
  184. if (it.relation == 1) {
  185. list.push(it.value)
  186. }
  187. })
  188. }
  189. if (item.type != 0 && item.relation == 1) {
  190. list.push(item.value)
  191. console.log(list)
  192. }
  193. if (item.children) {
  194. getHospitals(item.children)
  195. }
  196. })
  197. return list
  198. }
  199. // 禁用/启用接口
  200. function disableUser(id, status) {
  201. const param = { id: id, status: status };
  202. xPost(api.disableUser, param).then((res) => {
  203. if (res.data.code === 200) {
  204. getHospitalSet();
  205. setMsvisible(false);
  206. message.success((status ? '启用' : '禁用') + "成功");
  207. } else {
  208. message.warning(res.data.msg || '操作失败');
  209. }
  210. }).catch(() => {
  211. message.error("接口出错");
  212. });
  213. }
  214. //重置密码
  215. function onResetPsd(id) {
  216. const param = { id: id };
  217. xPost(api.resetPasswordUser, param).then((res) => {
  218. if (res.data.code === 200) {
  219. getHospitalSet();
  220. message.success("重置成功");
  221. } else {
  222. message.warning(res.data.msg || '操作失败');
  223. }
  224. }).catch(() => {
  225. message.error("接口出错");
  226. });
  227. }
  228. //删除
  229. function deleteHospitalSet() {
  230. const param = { id: id };
  231. xPost(api.deleteHospitalSet, param).then((res) => {
  232. if (res.data.code === 200) {
  233. getHospitalSet();
  234. setMsvisible(false);
  235. message.success("删除成功");
  236. } else {
  237. message.warning(res.data.msg || '操作失败');
  238. }
  239. }).catch(() => {
  240. message.error("接口出错");
  241. });
  242. }
  243. function onSizeChange(current, pageSize) {
  244. params.current = current
  245. params.size = pageSize
  246. setSize(pageSize)
  247. setCurrent(current)
  248. setParams(params)
  249. setQuery(query)
  250. getHospitalSet()
  251. }
  252. function changePage(page, pageSize) {
  253. params.current = page
  254. params.size = pageSize
  255. setCurrent(page)
  256. setParams(params)
  257. setQuery(query)
  258. getHospitalSet()
  259. }
  260. const onFinish = (value) => {
  261. const param = {
  262. ...data,
  263. ...value
  264. }
  265. setCurrent(1)
  266. setParams(param)
  267. setQuery(param)
  268. getHospitalSet(param);
  269. };
  270. const onReset = () => {
  271. // setCurrent(1)
  272. // setParams(data)
  273. // setQuery(query)
  274. form.resetFields();
  275. getHospitalSet(data);
  276. };
  277. const messageBox = (type, id) => {
  278. setMsvisible(true)
  279. setParaId(id)
  280. setModalType(type)
  281. }
  282. //提示框确认事件
  283. function handleOk() {
  284. if (modalType == 1) {
  285. deleteHospitalSet(id)
  286. } else if (modalType == 2) {
  287. disableUser(id, 0)
  288. } else if (modalType == 3) {
  289. onResetPsd(id);
  290. }
  291. }
  292. //提示框取消
  293. function handleCancel() {
  294. setMsvisible(false);
  295. }
  296. function cancel() {
  297. setVisible(false)
  298. setFormData(null)
  299. }
  300. function userChange() {
  301. let val = form.getFieldsValue() // 页面刷新
  302. const param = {
  303. ...data,
  304. //...value
  305. ...val
  306. }
  307. getHospitalSet(param)
  308. setVisible(false)
  309. }
  310. // 表格渲染
  311. const columns = [
  312. { title: '所属组织', render: (row) => {
  313. if(row.hospitalName === null){
  314. return '-'
  315. }else {
  316. return hospitalName
  317. }
  318. }, key: 'index' },
  319. { title: '参数名', dataIndex: 'name', key: 'index' },
  320. { title: '参数值', dataIndex: 'val', key: 'index' },
  321. { title: '参数说明', dataIndex: 'code', key: 'index' },
  322. {title: '参数描述', dataIndex: 'remark', key: 'index'},
  323. {
  324. title: '操作', dataIndex: 'key', render: (text, record) => (
  325. <Space size="middle">
  326. <a onClick={e => showModal(
  327. '修改参数',
  328. true, 2,
  329. record.id,
  330. record.hospitalName,
  331. record.name,
  332. record.val,
  333. record.code,
  334. record.remark,
  335. record.status,
  336. )} >修改</a>
  337. <a className='delete' onClick={() => messageBox(1, record.id)}>删除</a>
  338. </Space>
  339. )
  340. }
  341. ]
  342. return (
  343. // 搜索框
  344. <div className="wrapper">
  345. <div className="filter-box">
  346. <Form
  347. form={form}
  348. name="normal_login"
  349. onFinish={onFinish}
  350. initialValues={{ status: '' }}
  351. >
  352. <Row gutter={24}>
  353. <Col span={5} key={0}>
  354. <Form.Item name="hospitalName" label="所属组织">
  355. <Select
  356. allowClear
  357. >
  358. {HospitalNamesList.map((item) => {
  359. return (
  360. <Option value={item} key={item}>{item}</Option>
  361. )
  362. })}
  363. </Select>
  364. </Form.Item>
  365. </Col>
  366. <Col span={5} key={1}>
  367. <Form.Item label="参数名" name="name" getValueFromEvent={getValueFromEvent}>
  368. <Input placeholder="参数名" autoComplete='off'/>
  369. </Form.Item>
  370. </Col>
  371. <Col span={5} key={2}>
  372. <Form.Item label="参数说明" name="code" getValueFromEvent={getValueFromEvent}>
  373. <Input placeholder="参数说明" autoComplete='off'/>
  374. </Form.Item>
  375. </Col>
  376. <Col span={6} key={3}>
  377. <Form.Item>
  378. <Button type="primary" htmlType="submit">
  379. 查询
  380. </Button>
  381. <Button onClick={onReset}>
  382. 重置
  383. </Button>
  384. </Form.Item>
  385. </Col>
  386. </Row>
  387. </Form>
  388. </div>
  389. <div className="table">
  390. <div className="table-header">
  391. <h2 className="table-title">参数管理</h2>
  392. <Button type="primary" icon={<PlusOutlined />} onClick={e => showModal('新增参数', true, 1)}>新增参数</Button>
  393. </div>
  394. <Table
  395. columns={columns}
  396. scroll={{ y: 'calc(100vh - 320px)' }}
  397. dataSource={dictList}
  398. rowKey={record => record.id + record.hospitalName}
  399. pagination={{
  400. current: current,
  401. pageSize: size,
  402. size: 'small',
  403. showSizeChanger: true,
  404. pageSizeOptions: ['15', '30', '60', '120'],
  405. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  406. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  407. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  408. total: total
  409. }} />
  410. </div>
  411. {visible && formData ?
  412. <Modal
  413. title={title}
  414. okText='确定'
  415. cancelText='取消'
  416. width={'45%'}
  417. visible={visible}
  418. onCancel={cancel}
  419. footer={null}
  420. forceRender={true}
  421. >
  422. <UserContext.Provider value={{ id, type, formData, dictList }}>
  423. <AddUser userChange={userChange} />
  424. </UserContext.Provider>
  425. </Modal>
  426. : ''}
  427. <Modal
  428. title="提示"
  429. okText='确定'
  430. cancelText='取消'
  431. width={400}
  432. visible={msvisible}
  433. onOk={handleOk}
  434. onCancel={handleCancel}
  435. >
  436. <p>{tipText[modalType]}</p>
  437. </Modal>
  438. </div >
  439. )
  440. }
  441. export default DictManager;