index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Table, Select, Pagination, Space, Modal, message, Row, Col, Upload } from 'antd';
  3. import { PlusOutlined } from '@ant-design/icons';
  4. import AddSurg from './addSurg'
  5. import MatchSurg from './MatchSurg.js'
  6. import '@common/common.less';
  7. import apiObj from '@api/index';
  8. import SurgContext from './surg-context';
  9. const { post, api } = apiObj;
  10. const { Option } = Select;
  11. //获取列表
  12. function SurgManager() {
  13. useEffect(() => {
  14. getOperationPage();
  15. }, []);
  16. const [SurgList, setSurgList] = useState([]);//当前页列表数据
  17. const [Surgid, setSurgid] = useState([]);//当前列表id
  18. const [title, setTitle] = useState("");//数据总量
  19. const [visible, setVisible] = useState(false);//新增修改 弹窗
  20. const [msvisible, setMsvisible] = useState(false);//删除 弹窗
  21. const [visible1, setvisible1] = useState(false);//导入 弹窗
  22. const [visible2, setvisible2] = useState(false);//匹配 弹窗
  23. const [unsaved, setUnsaved] = useState(false);//修改未保存弹窗
  24. const [revise, setRevise] = useState(false);//是否修改 新增修改内容
  25. const [type, setType] = useState("");
  26. const [formData, setFormData] = useState(null);//当前行数据
  27. const [size, setSize] = useState(15);//每页显示条数
  28. const [total, setTotal] = useState(0);
  29. const [current, setCurrent] = useState(1);//当前页
  30. const [uploadStatus, setUploadStatus] = useState(0);//导入状态,0初始,1成功,2格式错误,3导入数据错误
  31. const [uploadTip, setUploadTip] = useState(""); //导入状态提示语
  32. const [saveParams, setSaveParams] = useState({}); //匹配诊断选中
  33. const [params, setParams] = useState({
  34. pages: 1,
  35. current: 1,
  36. size: 15
  37. });
  38. const [form] = Form.useForm();
  39. const tipMap = {
  40. 0: '提示:EXCEL导入,模板样式及数据请在【朗通云平台-CDSS数据维护-医学术语关联维护】中导出获取。',
  41. 2: "模板格式错误,模板样式及数据请在【朗通云平台-CDSS数据维护-医学术语关联维护】中导出获取",
  42. 3: '模板导入失败,失败原因已在Excel中标识并自动下载,请检查后重新导入',
  43. };
  44. let data = {
  45. pages: 1,
  46. current: 1,
  47. size: size
  48. }
  49. //新增 弹窗
  50. const showModal = (name, type, flag, Surgrow) => {
  51. setVisible(type);
  52. setTitle(name);
  53. setType(flag)
  54. if (flag == 1) {
  55. setFormData({
  56. status: '1'
  57. })
  58. }
  59. if (flag == 3) {
  60. setFormData(Surgrow)
  61. getOperationPage()
  62. }
  63. }
  64. //表格数据
  65. function getOperationPage(param) {
  66. post(api.getOperationPage, param || params).then((res) => {
  67. if (res.data.code === 200) {
  68. const data = res.data.data;
  69. setSurgList(data.records);
  70. setTotal(data.total)
  71. }
  72. })
  73. }
  74. //删除
  75. function delOperationById() {
  76. post(api.delOperationById, { ids: Surgid }).then((res) => {
  77. setMsvisible(false);
  78. if (res.data.code === 200) {
  79. getOperationPage();
  80. setSurgid([])
  81. message.success("删除成功");
  82. } else {
  83. message.warning(res.data.msg || '操作失败');
  84. }
  85. }).catch(() => {
  86. setMsvisible(false);
  87. message.error("接口出错");
  88. });
  89. }
  90. //每页显示条数切换
  91. function onSizeChange(current, pageSize) {
  92. params.current = current
  93. params.size = pageSize
  94. setSize(pageSize)
  95. setCurrent(current)
  96. setParams(params)
  97. getOperationPage()
  98. }
  99. //翻页
  100. function changePage(page, pageSize) {
  101. params.current = page
  102. params.size = pageSize
  103. setCurrent(page)
  104. setParams(params)
  105. getOperationPage()
  106. }
  107. const onFinish = (value) => {
  108. const param = {
  109. ...data,
  110. ...value
  111. }
  112. setCurrent(1)
  113. setParams(param)
  114. getOperationPage(param);
  115. };
  116. //重置
  117. const onReset = () => {
  118. setCurrent(1)
  119. setParams(data)
  120. form.resetFields();
  121. getOperationPage(data);
  122. };
  123. //打开导入弹窗
  124. const ImportBox = () => {
  125. setvisible1(true)
  126. }
  127. //导入弹窗取消或关闭
  128. function handleCancel1() {
  129. setvisible1(false);
  130. setUploadStatus(0);
  131. }
  132. //打开匹配弹窗
  133. function match(row) {
  134. setvisible2(true)
  135. setFormData(row)
  136. }
  137. //导入弹窗取消或关闭
  138. function handleCancel2() {
  139. setvisible2(false);
  140. }
  141. const messageBox = () => {
  142. if (!Surgid.length) {
  143. message.warning("请先选择要删除的记录~", 1);
  144. return;
  145. }
  146. setMsvisible(true)
  147. }
  148. //删除 提示框取消或关闭
  149. function handleCancel() {
  150. setMsvisible(false);
  151. }
  152. //新增修改 取消或关闭
  153. function cancel() {
  154. if (revise) {
  155. setUnsaved(true)
  156. } else {
  157. setVisible(false)
  158. setFormData(null)
  159. }
  160. }
  161. function isChange(a) {
  162. setRevise(a)
  163. }
  164. function addCancel() {
  165. setRevise(false)
  166. setVisible(false)
  167. setUnsaved(false)
  168. setFormData(null)
  169. }
  170. function unsavedCancel() {
  171. setUnsaved(false)
  172. }
  173. //新增修改 保存
  174. function SurgChange() {
  175. setRevise(false)
  176. setVisible(false)
  177. getOperationPage();
  178. }
  179. const rowSelection = {
  180. onChange: (selectedRowKeys, selectedRows) => {
  181. console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  182. setSurgid(selectedRowKeys)
  183. }
  184. };
  185. //导入模板
  186. const props = {
  187. name: 'file',
  188. accept: ".xls",
  189. showUploadList: false,
  190. action: api.importOperation,
  191. headers: {
  192. authorization: 'authorization-text',
  193. },
  194. onChange(info) {
  195. const { response, status } = info.file;
  196. if (status === 'done') {
  197. if (response.code === 200) {
  198. getOperationPage(); //刷新列表
  199. //setvisible1(false); //关闭导入弹窗
  200. //message.success(`${info.file.name} 导入成功`);
  201. setUploadStatus(1);
  202. setUploadTip(response.data);
  203. } else {
  204. //message.error(`${info.file.name} 导入失败.`);
  205. setUploadStatus(2);
  206. }
  207. } else if (status === 'error') {
  208. setUploadStatus(3);
  209. }
  210. },
  211. };
  212. function saveMatching() {
  213. post(api.matchingOperation, saveParams).then((res) => {
  214. setvisible2(false);
  215. if (res.data.code === 200) {
  216. message.success("匹配成功");
  217. getOperationPage();
  218. } else {
  219. message.warning(res.data.message || "匹配失败,请重试");
  220. }
  221. }).catch((error) => {
  222. message.warning(error.message || "接口出错,请重试",);
  223. })
  224. }
  225. function matchChange(data) {
  226. setSaveParams(data);
  227. }
  228. const columns = [
  229. { title: '序号', dataIndex: 'index', render: (text, record, index) => (current - 1) * params.size + index + 1 },
  230. { title: '医院手术/操作名称', dataIndex: 'name', },
  231. { title: '手术和操作代码', dataIndex: 'code', },
  232. { title: '标准手术/操作名称', dataIndex: 'standard', },
  233. { title: '是否匹配', dataIndex: 'isMapping', },
  234. {
  235. title: '操作', dataIndex: 'key', render: (text, record) => (
  236. <Space size="middle">
  237. <a onClick={e => showModal('修改字典', true, 3, record)}>修改</a>
  238. <a onClick={e => match(record)}>匹配</a>
  239. </Space>
  240. )
  241. }
  242. ]
  243. return (
  244. <div className="wrapper">
  245. <div className="filter-box">
  246. <Form
  247. form={form}
  248. name="normal_login"
  249. onFinish={onFinish}
  250. initialValues={{ isMapping: '' }}
  251. >
  252. <Row gutter={24}>
  253. <Col span={5} key={0}>
  254. <Form.Item label="医院手术/操作名称" name="name">
  255. <Input placeholder="医院手术/操作名称" autoComplete='off' />
  256. </Form.Item>
  257. </Col>
  258. <Col span={5} key={1}>
  259. <Form.Item label="手术和操作代码" name="code">
  260. <Input placeholder="手术和操作代码" autoComplete='off' />
  261. </Form.Item>
  262. </Col>
  263. <Col span={5} key={2}>
  264. <Form.Item label="标准手术/操作名称" name="standard">
  265. <Input placeholder="标准手术/操作名称" autoComplete='off' />
  266. </Form.Item>
  267. </Col>
  268. <Col span={4} key={3}>
  269. <Form.Item id="groupTypeval" label="是否匹配" name="isMapping">
  270. <Select
  271. showSearch
  272. optionFilterProp="children"
  273. // onSearch={onSearch}
  274. // onFocus={onFocus}
  275. placeholder="全部"
  276. >
  277. <Option value={''} key={-1}>全部</Option>
  278. <Option value={0} key={0}>未匹配</Option>
  279. <Option value={1} key={1}>已匹配</Option>
  280. </Select>
  281. </Form.Item>
  282. </Col>
  283. <Col span={5} key={4}>
  284. <Form.Item>
  285. <Button type="primary" htmlType="submit">
  286. 查询
  287. </Button>
  288. <Button onClick={onReset}>
  289. 重置
  290. </Button>
  291. </Form.Item>
  292. </Col>
  293. </Row>
  294. </Form>
  295. </div>
  296. <div className="table">
  297. <div className="table-header">
  298. <h2 className="table-title">手术信息维护</h2>
  299. <Row gutter={12}>
  300. <Col key={0}>
  301. <Button type="primary" icon={<PlusOutlined />} onClick={e => showModal('新增', true, 1)}>新增</Button>
  302. </Col>
  303. <Col key={1}>
  304. <Button onClick={e => messageBox()} className="delete" >删除</Button>
  305. </Col>
  306. <Col key={2}>
  307. <Button type="primary" onClick={e => ImportBox()}>导入</Button>
  308. </Col>
  309. </Row>
  310. </div>
  311. <Table
  312. rowSelection={{ type: 'checkbox', ...rowSelection, }}
  313. columns={columns}
  314. scroll={{ y: 'calc(100vh - 350px)' }}
  315. dataSource={SurgList}
  316. rowKey={record => record.id}
  317. pagination={{
  318. current: current,
  319. pageSize: size,
  320. size: 'small',
  321. showSizeChanger: true,
  322. pageSizeOptions: ['15', '30', '60', '120'],
  323. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  324. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  325. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  326. total: total
  327. }} />
  328. </div>
  329. {visible && formData ?
  330. <Modal maskClosable={false}
  331. title={title}
  332. okText='确定'
  333. cancelText='关闭'
  334. width={'45%'}
  335. visible={visible}
  336. onCancel={cancel}
  337. footer={null}
  338. forceRender={true}
  339. >
  340. <SurgContext.Provider value={{ type, formData }}>
  341. <AddSurg SurgChange={SurgChange} cancel={cancel} isChange={isChange} />
  342. </SurgContext.Provider>
  343. <Modal
  344. title="提示"
  345. okText='确定'
  346. cancelText='关闭'
  347. width={400}
  348. visible={unsaved}
  349. onOk={addCancel}
  350. onCancel={unsavedCancel}
  351. >
  352. <p>当前数据未保存 是否确认关闭?</p>
  353. </Modal>
  354. </Modal>
  355. : ''}
  356. <Modal
  357. maskClosable={false}
  358. title="提示"
  359. okText='确定'
  360. cancelText='关闭'
  361. width={400}
  362. visible={msvisible}
  363. onOk={delOperationById}
  364. onCancel={handleCancel}
  365. >
  366. <p>诊断信息删除后将无法恢复,确认删除这{Surgid.length}条信息。</p>
  367. </Modal>
  368. <Modal
  369. maskClosable={false}
  370. destroyOnClose={true}
  371. title="提示"
  372. width={400}
  373. visible={visible1}
  374. onCancel={handleCancel1}
  375. footer={<Button key="back" onClick={handleCancel1}>关闭</Button>}
  376. >
  377. <div style={{ marginBottom: 10 + 'px' }}>
  378. <span>手术信息导入:</span>
  379. <Upload {...props}><Button type="primary" >导入目录</Button></Upload>
  380. </div>
  381. {uploadStatus === 1 ? (<span style={{ color: '#00AF71' }}>{uploadTip}</span>) : (<span style={{ color: '#E3505B' }}>{tipMap[uploadStatus]}</span>)}
  382. </Modal>
  383. <Modal
  384. maskClosable={false}
  385. destroyOnClose={true}
  386. title="提示"
  387. okText='保存'
  388. cancelText='关闭'
  389. width={800}
  390. visible={visible2}
  391. onCancel={handleCancel2}
  392. onOk={saveMatching}
  393. >
  394. <MatchSurg row={formData} onChange={matchChange}></MatchSurg>
  395. </Modal>
  396. </div>
  397. )
  398. }
  399. export default SurgManager;