index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Table, Select, Space, Modal, message, Row, Col, Upload } from 'antd';
  3. import { PlusOutlined } from '@ant-design/icons';
  4. import AddDrug from './addDrug'
  5. import MatchDrug from './MatchDrug.js'
  6. import '@common/common.less';
  7. import apiObj from '@api/index';
  8. import DrugContext from './Drug-context';
  9. const { post, api } = apiObj;
  10. const { Option } = Select;
  11. //获取列表
  12. function DrugManager() {
  13. useEffect(() => {
  14. getDrugPage();
  15. }, []);
  16. const [DrugList, setDrugList] = useState([]);//当前页列表数据
  17. const [Drugid, setDrugid] = 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, Drugrow) => {
  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(Drugrow)
  61. getDrugPage()
  62. }
  63. }
  64. //表格数据
  65. function getDrugPage(param) {
  66. post(api.getDrugPage, param || params).then((res) => {
  67. if (res.data.code === 200) {
  68. const data = res.data.data;
  69. setDrugList(data.records);
  70. setTotal(data.total)
  71. }
  72. })
  73. }
  74. //删除
  75. function delDrugById() {
  76. post(api.delDrugById, { ids: Drugid }).then((res) => {
  77. setMsvisible(false);
  78. if (res.data.code === 200) {
  79. getDrugPage();
  80. setDrugid([])
  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. getDrugPage()
  98. }
  99. //翻页
  100. function changePage(page, pageSize) {
  101. params.current = page
  102. params.size = pageSize
  103. setCurrent(page)
  104. setParams(params)
  105. getDrugPage()
  106. }
  107. const onFinish = (value) => {
  108. const param = {
  109. ...data,
  110. ...value
  111. }
  112. setCurrent(1)
  113. setParams(param)
  114. getDrugPage(param);
  115. };
  116. //重置
  117. const onReset = () => {
  118. setCurrent(1)
  119. setParams(data)
  120. form.resetFields();
  121. getDrugPage(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 (!Drugid.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 DrugChange() {
  175. setRevise(false)
  176. setVisible(false)
  177. getDrugPage();
  178. }
  179. function saveMatching() {
  180. post(api.matchingDrug, saveParams).then((res) => {
  181. setvisible2(false);
  182. if (res.data.code === 200) {
  183. message.success("匹配成功");
  184. getDrugPage();
  185. } else {
  186. message.warning(res.data.message || "匹配失败,请重试");
  187. }
  188. }).catch((error) => {
  189. message.warning(error.message || "接口出错,请重试",);
  190. })
  191. }
  192. const rowSelection = {
  193. onChange: (selectedRowKeys, selectedRows) => {
  194. console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  195. setDrugid(selectedRowKeys)
  196. }
  197. };
  198. //导入模板
  199. const props = {
  200. name: 'file',
  201. accept: ".xls",
  202. showUploadList: false,
  203. action: api.importDrug,
  204. headers: {
  205. authorization: 'authorization-text',
  206. },
  207. onChange(info) {
  208. const { response, status } = info.file;
  209. if (status === 'done') {
  210. if (response.code === 200) {
  211. getDrugPage(); //刷新列表
  212. //setvisible1(false); //关闭导入弹窗
  213. //message.success(`${info.file.name} 导入成功`);
  214. setUploadStatus(1);
  215. setUploadTip(response.data);
  216. } else {
  217. //message.error(`${info.file.name} 导入失败.`);
  218. setUploadStatus(2);
  219. }
  220. } else if (status === 'error') {
  221. setUploadStatus(3);
  222. }
  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: 'approvalNum', },
  232. { title: '药品剂型', dataIndex: 'dosageForm', },
  233. { title: '标准药品名称', dataIndex: 'standard', },
  234. { title: '是否匹配', dataIndex: 'isMapping', },
  235. {
  236. title: '操作', dataIndex: 'key', render: (text, record) => (
  237. <Space size="middle">
  238. <a onClick={e => showModal('修改字典', true, 3, record)}>修改</a>
  239. <a onClick={e => match(record)}>匹配</a>
  240. </Space>
  241. )
  242. }
  243. ]
  244. return (
  245. <div className="wrapper">
  246. <div className="filter-box">
  247. <Form
  248. form={form}
  249. name="normal_login"
  250. onFinish={onFinish}
  251. initialValues={{ isMapping: '' }}
  252. >
  253. <Row gutter={24}>
  254. <Col span={5} key={0}>
  255. <Form.Item label="医院药品名称" name="name">
  256. <Input placeholder="请输入" autoComplete='off' allowClear />
  257. </Form.Item>
  258. </Col>
  259. <Col span={5} key={1}>
  260. <Form.Item label="国药准字" name="approvalNum">
  261. <Input placeholder="请输入" autoComplete='off' allowClear />
  262. </Form.Item>
  263. </Col>
  264. <Col span={5} key={2}>
  265. <Form.Item label="药品剂型" name="dosageForm">
  266. <Input placeholder="请选择" autoComplete='off' allowClear />
  267. </Form.Item>
  268. </Col>
  269. <Col span={5} key={3}>
  270. <Form.Item label="标准药品名称" name="standard">
  271. <Input placeholder="请输入" autoComplete='off' allowClear />
  272. </Form.Item>
  273. </Col>
  274. <Col span={4} key={4}>
  275. <Form.Item id="groupTypeval" label="是否匹配" name="isMapping">
  276. <Select
  277. showSearch
  278. optionFilterProp="children"
  279. // onSearch={onSearch}
  280. // onFocus={onFocus}
  281. placeholder="全部"
  282. >
  283. <Option value={''} key={-1}>全部</Option>
  284. <Option value={0} key={0}>未匹配</Option>
  285. <Option value={1} key={1}>已匹配</Option>
  286. </Select>
  287. </Form.Item>
  288. </Col>
  289. <Col span={5} key={5}>
  290. <Form.Item>
  291. <Button type="primary" htmlType="submit">
  292. 查询
  293. </Button>
  294. <Button onClick={onReset}>
  295. 重置
  296. </Button>
  297. </Form.Item>
  298. </Col>
  299. </Row>
  300. </Form>
  301. </div>
  302. <div className="table">
  303. <div className="table-header">
  304. <h2 className="table-title">药品信息维护</h2>
  305. <Row gutter={12}>
  306. <Col key={0}>
  307. <Button type="primary" icon={<PlusOutlined />} onClick={e => showModal('新增', true, 1)}>新增</Button>
  308. </Col>
  309. <Col key={1}>
  310. <Button onClick={e => messageBox()} type="primary" danger>删除</Button>
  311. </Col>
  312. <Col key={2}>
  313. <Button type="primary" onClick={e => ImportBox()}>导入</Button>
  314. </Col>
  315. </Row>
  316. </div>
  317. <Table
  318. rowSelection={{ type: 'checkbox', ...rowSelection, }}
  319. columns={columns}
  320. scroll={{ y: 'calc(100vh - 400px)' }}
  321. dataSource={DrugList}
  322. rowKey={record => record.id}
  323. pagination={{
  324. current: current,
  325. pageSize: size,
  326. size: 'small',
  327. showSizeChanger: true,
  328. pageSizeOptions: ['15', '30', '60', '120'],
  329. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  330. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  331. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  332. total: total
  333. }} />
  334. </div>
  335. {visible && formData ?
  336. <Modal
  337. title={title}
  338. okText='确定'
  339. cancelText='关闭'
  340. width={'45%'}
  341. visible={visible}
  342. onCancel={cancel}
  343. footer={null}
  344. forceRender={true}
  345. maskClosable={false}
  346. >
  347. <DrugContext.Provider value={{ type, formData }}>
  348. <AddDrug DrugChange={DrugChange} cancel={cancel} isChange={isChange} />
  349. </DrugContext.Provider>
  350. <Modal
  351. maskClosable={false}
  352. title="提示"
  353. okText='确定'
  354. cancelText='关闭'
  355. width={400}
  356. visible={unsaved}
  357. onOk={addCancel}
  358. onCancel={unsavedCancel}
  359. >
  360. <p>当前数据未保存 是否确认关闭?</p>
  361. </Modal>
  362. </Modal>
  363. : ''}
  364. <Modal
  365. maskClosable={false}
  366. title="提示"
  367. okText='确定'
  368. cancelText='关闭'
  369. width={400}
  370. visible={msvisible}
  371. onOk={delDrugById}
  372. onCancel={handleCancel}
  373. >
  374. <p>药品信息删除后将无法恢复,确认删除这{Drugid.length}条信息。</p>
  375. </Modal>
  376. <Modal
  377. maskClosable={false}
  378. destroyOnClose={true}
  379. title="提示"
  380. width={400}
  381. visible={visible1}
  382. onCancel={handleCancel1}
  383. footer={<Button key="back" onClick={handleCancel1}>关闭</Button>}
  384. >
  385. <div style={{ marginBottom: 10 + 'px' }}>
  386. <span>药品信息导入:</span>
  387. <Upload {...props}><Button type="primary" >导入目录</Button></Upload>
  388. </div>
  389. {uploadStatus === 1 ? (<span style={{ color: '#00AF71' }}>{uploadTip}</span>) : (<span style={{ color: '#E3505B' }}>{tipMap[uploadStatus]}</span>)}
  390. </Modal>
  391. <Modal
  392. maskClosable={false}
  393. destroyOnClose={true}
  394. title="提示"
  395. okText='保存'
  396. cancelText='关闭'
  397. width={800}
  398. visible={visible2}
  399. onCancel={handleCancel2}
  400. onOk={saveMatching}
  401. >
  402. <MatchDrug row={formData} onChange={matchChange}></MatchDrug>
  403. </Modal>
  404. </div>
  405. )
  406. }
  407. export default DrugManager;