index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 [size, setSize] = useState(15);
  32. const [HospitalNamesList, setHospitalNamesList] = useState([]);
  33. const [total, setTotal] = useState(0);
  34. const [current, setCurrent] = useState(1);
  35. const { organizationData } = utils;
  36. const { SHOW_PARENT } = TreeSelect;
  37. const [revise, setRevise] = useState(false);//是否修改 新增修改内容
  38. const [unsaved, setUnsaved] = useState(false);// 修改未保存弹窗
  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. setParaId(null)
  207. message.success((status ? '启用' : '禁用') + "成功");
  208. } else {
  209. message.warning(res.data.msg || '操作失败');
  210. }
  211. }).catch(() => {
  212. message.error("接口出错");
  213. });
  214. }
  215. //重置密码
  216. function onResetPsd(id) {
  217. const param = { id: id };
  218. xPost(api.resetPasswordUser, param).then((res) => {
  219. if (res.data.code === 200) {
  220. getHospitalSet();
  221. message.success("重置成功");
  222. } else {
  223. message.warning(res.data.msg || '操作失败');
  224. }
  225. }).catch(() => {
  226. message.error("接口出错");
  227. });
  228. }
  229. //删除
  230. function deleteHospitalSet() {
  231. const param = { id: id };
  232. xPost(api.deleteHospitalSet, param).then((res) => {
  233. if (res.data.code === 200) {
  234. getHospitalSet();
  235. setMsvisible(false);
  236. setParaId(null)
  237. message.success("删除成功");
  238. } else {
  239. message.warning(res.data.msg || '操作失败');
  240. }
  241. }).catch(() => {
  242. message.error("接口出错");
  243. });
  244. }
  245. function onSizeChange(current, pageSize) {
  246. params.current = current
  247. params.size = pageSize
  248. setSize(pageSize)
  249. setCurrent(current)
  250. setParams(params)
  251. setQuery(query)
  252. getHospitalSet()
  253. }
  254. function changePage(page, pageSize) {
  255. params.current = page
  256. params.size = pageSize
  257. setCurrent(page)
  258. setParams(params)
  259. setQuery(query)
  260. getHospitalSet()
  261. }
  262. const onFinish = (value) => {
  263. const param = {
  264. ...data,
  265. ...value
  266. }
  267. setCurrent(1)
  268. setParams(param)
  269. setQuery(param)
  270. getHospitalSet(param);
  271. };
  272. const onReset = () => {
  273. // setCurrent(1)
  274. // setParams(data)
  275. // setQuery(query)
  276. form.resetFields();
  277. getHospitalSet(data);
  278. };
  279. const messageBox = (type, id) => {
  280. setMsvisible(true)
  281. setParaId(id)
  282. setModalType(type)
  283. }
  284. //提示框确认事件
  285. // function handleOk() {
  286. // if (modalType == 1) {
  287. // deleteHospitalSet(id)
  288. // } else if (modalType == 2) {
  289. // disableUser(id, 0)
  290. // } else if (modalType == 3) {
  291. // onResetPsd(id);
  292. // }
  293. // }
  294. // 确认删除是否继续
  295. function deleteCancel() {
  296. setMsvisible(false);
  297. }
  298. // 新增修改 取消/关闭
  299. function cancel() {
  300. if(revise){
  301. setUnsaved(true)
  302. }else{
  303. setVisible(false)
  304. setFormData(null)
  305. }
  306. }
  307. function isChange(tog){
  308. setRevise(tog)
  309. }
  310. function addCancel() {
  311. setRevise(false)
  312. setVisible(false)
  313. setUnsaved(false)
  314. setFormData(null)
  315. }
  316. function unsavedCancel() {
  317. setUnsaved(false)
  318. }
  319. // 保存 新增修改
  320. function userChange() {
  321. setRevise(false)
  322. setVisible(false)
  323. getHospitalSet()
  324. }
  325. function userChange() {
  326. let val = form.getFieldsValue() // 页面刷新
  327. const param = {
  328. ...data,
  329. //...value
  330. ...val
  331. }
  332. getHospitalSet(param)
  333. setVisible(false)
  334. }
  335. // 表格渲染
  336. const columns = [
  337. { title: '所属组织', render: (row) => {
  338. if(row.hospitalName === null){
  339. return '-'
  340. }else {
  341. return hospitalName
  342. }
  343. }, key: 'index' },
  344. { title: '参数名', dataIndex: 'name', key: 'index' },
  345. { title: '参数值', dataIndex: 'val', key: 'index' },
  346. { title: '参数说明', dataIndex: 'code', key: 'index' },
  347. {title: '参数描述', dataIndex: 'remark', key: 'index'},
  348. {
  349. title: '操作', dataIndex: 'key', render: (text, record) => (
  350. <Space size="middle">
  351. <a onClick={e => showModal(
  352. '修改参数',
  353. true, 2,
  354. record.id,
  355. record.hospitalName,
  356. record.name,
  357. record.val,
  358. record.code,
  359. record.remark,
  360. record.status,
  361. )} >修改</a>
  362. <a className='delete' onClick={() => messageBox(1, record.id)}>删除</a>
  363. </Space>
  364. )
  365. }
  366. ]
  367. return (
  368. // 搜索框
  369. <div className="wrapper">
  370. <div className="filter-box">
  371. <Form
  372. form={form}
  373. name="normal_login"
  374. onFinish={onFinish}
  375. initialValues={{ status: '' }}
  376. >
  377. <Row gutter={24}>
  378. <Col span={5} key={0}>
  379. <Form.Item name="hospitalName" label="所属组织">
  380. <Select
  381. allowClear
  382. >
  383. {HospitalNamesList.map((item) => {
  384. return (
  385. <Option value={item} key={item}>{item}</Option>
  386. )
  387. })}
  388. </Select>
  389. </Form.Item>
  390. </Col>
  391. <Col span={5} key={1}>
  392. <Form.Item label="参数名" name="name" getValueFromEvent={getValueFromEvent}>
  393. <Input placeholder="参数名" autoComplete='off'/>
  394. </Form.Item>
  395. </Col>
  396. <Col span={5} key={2}>
  397. <Form.Item label="参数说明" name="code" getValueFromEvent={getValueFromEvent}>
  398. <Input placeholder="参数说明" autoComplete='off'/>
  399. </Form.Item>
  400. </Col>
  401. <Col span={6} key={3}>
  402. <Form.Item>
  403. <Button type="primary" htmlType="submit">
  404. 查询
  405. </Button>
  406. <Button onClick={onReset}>
  407. 重置
  408. </Button>
  409. </Form.Item>
  410. </Col>
  411. </Row>
  412. </Form>
  413. </div>
  414. <div className="table">
  415. <div className="table-header">
  416. <h2 className="table-title">参数管理</h2>
  417. <Button type="primary" icon={<PlusOutlined />} onClick={e => showModal('新增参数', true, 1)}>新增参数</Button>
  418. </div>
  419. <Table
  420. columns={columns}
  421. scroll={{ y: 'calc(100vh - 320px)' }}
  422. dataSource={dictList}
  423. rowKey={record => record.id + record.hospitalName}
  424. pagination={{
  425. current: current,
  426. pageSize: size,
  427. size: 'small',
  428. showSizeChanger: true,
  429. pageSizeOptions: ['15', '30', '60', '120'],
  430. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  431. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  432. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  433. total: total
  434. }} />
  435. </div>
  436. {visible && formData ?
  437. <Modal
  438. title={title}
  439. okText='确定'
  440. cancelText='取消'
  441. width={'45%'}
  442. visible={visible}
  443. onCancel={cancel}
  444. footer={null}
  445. forceRender={true}
  446. >
  447. <UserContext.Provider value={{type, formData }}>
  448. <AddUser userChange={userChange} cancel={cancel} isChange={isChange} />
  449. </UserContext.Provider>
  450. <Modal
  451. title="提示"
  452. okText='确定'
  453. cancelText='取消'
  454. width={400}
  455. visible={unsaved}
  456. onOk={addCancel}
  457. onCancel={unsavedCancel}
  458. >
  459. <p>当前数据未保存 是否确认关闭?</p>
  460. </Modal>
  461. </Modal>
  462. : ''}
  463. <Modal
  464. title="提示"
  465. okText='确定'
  466. cancelText='取消'
  467. width={400}
  468. visible={msvisible}
  469. onOk={deleteHospitalSet}
  470. onCancel={deleteCancel}
  471. >
  472. <p>确定要删除该参数?</p>
  473. </Modal>
  474. </div >
  475. )
  476. }
  477. export default DictManager;