index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import React, { useState, useEffect } from 'react';
  2. import { Empty,ConfigProvider,Spin,Form, Input, Button, Table, Select, Space, Modal, message, Row, Col } from 'antd';
  3. import { PlusOutlined } from '@ant-design/icons';
  4. import AddTerm from '../DiagManager/addDiag'
  5. import { useSelector } from 'react-redux';
  6. import '@common/common.less';
  7. import apiObj from '@api/index';
  8. const { post, api } = apiObj;
  9. const { Option } = Select;
  10. //获取列表
  11. function DrugManager() {
  12. const { drugNum } = useSelector((state) => {
  13. return state.userInfo;
  14. });
  15. useEffect(() => {
  16. setSize(15)
  17. setCurrent(1)
  18. form.resetFields();
  19. getDrugeryPage();
  20. }, [drugNum]);
  21. const [DrugList, setDrugList] = useState([]);//当前页列表数据
  22. const [Drugid, setDrugid] = useState([]);//当前操作行id
  23. const [title, setTitle] = useState("");//新增/修改的弹窗标题
  24. const [visible, setVisible] = useState(false);//新增修改 弹窗
  25. const [delvisible, setDelvisible] = useState(false);//删除 弹窗
  26. const [loading, setloading] = useState(true);//是否显示加载中
  27. const [flag, setFlag] = useState(false);//新增1或修改3
  28. const [formData, setFormData] = useState({});//当前行数据
  29. const [size, setSize] = useState(15);//每页显示条数
  30. const [total, setTotal] = useState(0);
  31. const [current, setCurrent] = useState(1);//当前页
  32. const [params, setParams] = useState({
  33. pages: 1,
  34. current: 1,
  35. size: 15
  36. });
  37. const [form] = Form.useForm();
  38. let data = {
  39. pages: 1,
  40. current: 1,
  41. size: 15
  42. }
  43. //新增/修改 弹窗flag=1新增,3修改
  44. const showModal = (name, flag1, Drugrow) => {
  45. setVisible(true);
  46. setTitle(name);
  47. setFlag(flag1)
  48. if (flag1 === 1) {
  49. setFormData({
  50. status: 1,
  51. hisName:'',
  52. uniqueName:'',
  53. form:''
  54. })
  55. }else if (flag1 === 3) {
  56. console.log(33,Drugrow)
  57. setFormData(Drugrow)
  58. }
  59. }
  60. //表格数据
  61. function getDrugeryPage(param) { //type(必填): 类型:1-化验、3-辅检、4-诊断、5-药品、6-手术和操作
  62. const hide = message.loading('加载中...',0);
  63. const hospitalId = localStorage.getItem('hospitalId')
  64. setloading(true)
  65. post(api.getTermPage, {...(param || params),type:5,hospitalId:hospitalId}).then((res) => {
  66. hide()
  67. if (res.data.code === 200) {
  68. const data = res.data.data;
  69. setDrugList(data.records);
  70. setTotal(data.total)
  71. setloading(false)
  72. }
  73. })
  74. }
  75. function showDelModal(id){
  76. setDelvisible(true);
  77. setDrugid(id);
  78. }
  79. //删除
  80. function delDrugeryById() {
  81. post(api.deleteRecord, { id: Drugid }).then((res) => {
  82. setDelvisible(false);
  83. if (res.data.code === 200) {
  84. //刷新列表
  85. const totalPage = Math.ceil((total-1) / size);
  86. //将当前页码与删除数据之后的总页数进行比较,避免当前页码不存在
  87. const pagenum =
  88. params.current > totalPage ? totalPage : params.current;
  89. //避免pagenum变为0
  90. params.current = pagenum < 1 ? 1 : pagenum;
  91. setParams(params)
  92. getDrugeryPage();
  93. setDrugid("");
  94. message.success("删除成功");
  95. } else {
  96. message.warning(res.data.msg || '操作失败');
  97. }
  98. }).catch(() => {
  99. setDelvisible(false);
  100. message.error("接口出错");
  101. });
  102. }
  103. //每页显示条数切换
  104. function onSizeChange(current, pageSize) {
  105. params.current = current
  106. params.size = pageSize
  107. setSize(pageSize)
  108. setCurrent(current)
  109. setParams(params)
  110. }
  111. //翻页
  112. function changePage(page, pageSize) {
  113. params.current = page
  114. params.size = pageSize
  115. setCurrent(page)
  116. setParams(params)
  117. getDrugeryPage()
  118. }
  119. //筛选查询
  120. const onFinish = (value) => {
  121. const param = {
  122. ...data,
  123. ...value
  124. }
  125. console.log(param)
  126. setCurrent(1)
  127. setParams(param)
  128. getDrugeryPage(param);
  129. };
  130. //重置
  131. const onReset = () => {
  132. setSize(15)
  133. setCurrent(1)
  134. setParams(data)
  135. form.resetFields();
  136. getDrugeryPage(data);
  137. };
  138. //删除 提示框取消或关闭
  139. function handleCancel() {
  140. setDelvisible(false);
  141. }
  142. //新增修改 取消或关闭
  143. function cancel() {
  144. setVisible(false)
  145. setFormData([])
  146. }
  147. function saveMatching(saveParams) {
  148. post(api.saveOrUpdateRecord, saveParams).then((res) => {
  149. if (res.data.code === 200) {
  150. message.success("匹配成功");
  151. setVisible(false);
  152. setFormData([])
  153. getDrugeryPage();
  154. } else {
  155. message.warning(res.data.message || "匹配失败,请重试");
  156. }
  157. }).catch((error) => {
  158. message.warning(error.message || "接口出错,请重试",);
  159. })
  160. }
  161. const renderEmpty = () => (
  162. <Empty
  163. imageStyle={{
  164. height: 0,
  165. }}
  166. description={<span></span>}
  167. >
  168. </Empty>
  169. )
  170. const columns = [
  171. { title: '序号', dataIndex: 'index', render: (text, record, index) => (current - 1) * params.size + index + 1 },
  172. { title: '操作时间', dataIndex: 'gmtModified', },
  173. { title: '医院药品名称', dataIndex: 'hisName', },
  174. { title: '标准药品名称', dataIndex: 'uniqueName', },
  175. { title: '药品剂型', dataIndex: 'form', },
  176. { title: '标准术语状态', dataIndex: 'status',render: (text, record) => {
  177. return record.status===1?'启用':record.status===0?'禁用':'';
  178. }},
  179. { title: '剂型术语状态', dataIndex: 'formStatus',render: (text, record) => {
  180. return record.formStatus===1?'启用':record.formStatus===0?'禁用':'';
  181. }},
  182. { title: '是否匹配', dataIndex: 'isMatch',render: (text, record) => {
  183. return record.isMatch===1?'已匹配':'未匹配';
  184. }},
  185. {
  186. title: '操作', dataIndex: 'key', render: (text, record) => (
  187. <Space size="middle">
  188. <a onClick={e => showModal('修改药品信息',3, record)}>修改</a>
  189. <a style={{color:"#FF4D4D"}} onClick={() => showDelModal(record.id)}>删除</a>
  190. </Space>
  191. )
  192. }
  193. ]
  194. return (
  195. <div className="wrapper">
  196. <div className="filter-box">
  197. <Form
  198. form={form}
  199. name="normal_login"
  200. onFinish={onFinish}
  201. >
  202. <Row gutter={24}>
  203. <Col span={5} key={0}>
  204. <Form.Item label="医院药品名称" name="hisName">
  205. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  206. </Form.Item>
  207. </Col>
  208. <Col span={5} key={1}>
  209. <Form.Item label="标准药品名称" name="uniqueName">
  210. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  211. </Form.Item>
  212. </Col>
  213. <Col span={5} key={2}>
  214. <Form.Item label="药品剂型" name="form">
  215. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  216. </Form.Item>
  217. </Col>
  218. <Col span={5} key={3}>
  219. <Form.Item id="groupTypeval" label="是否匹配" name="isMatch">
  220. <Select
  221. showSearch
  222. optionFilterProp="children"
  223. // onSearch={onSearch}
  224. // onFocus={onFocus}
  225. placeholder="全部"
  226. >
  227. <Option value={''} key={-1}>全部</Option>
  228. <Option value={0} key={0}>未匹配</Option>
  229. <Option value={1} key={1}>已匹配</Option>
  230. </Select>
  231. </Form.Item>
  232. </Col>
  233. <Col span={5} key={4}>
  234. <Form.Item label="标准术语状态" name="status">
  235. <Select
  236. showSearch
  237. optionFilterProp="children"
  238. placeholder="全部"
  239. >
  240. <Option value={''} key={-1}>全部</Option>
  241. <Option value={0} key={0}>禁用</Option>
  242. <Option value={1} key={1}>启用</Option>
  243. </Select>
  244. </Form.Item>
  245. </Col>
  246. <Col span={5} key={5}>
  247. <Form.Item label="剂型术语状态" name="formStatus">
  248. <Select
  249. showSearch
  250. optionFilterProp="children"
  251. placeholder="全部"
  252. >
  253. <Option value={''} key={-1}>全部</Option>
  254. <Option value={0} key={0}>禁用</Option>
  255. <Option value={1} key={1}>启用</Option>
  256. </Select>
  257. </Form.Item>
  258. </Col>
  259. <Col span={5} key={6}>
  260. <Form.Item>
  261. <Button type="primary" htmlType="submit">
  262. 查询
  263. </Button>
  264. <Button onClick={onReset}>
  265. 重置
  266. </Button>
  267. </Form.Item>
  268. </Col>
  269. </Row>
  270. </Form>
  271. </div>
  272. <div className="table">
  273. <div className="table-header">
  274. <h2 className="table-title">药品信息维护</h2>
  275. <Row gutter={12}>
  276. <Col key={0}>
  277. <Button type="primary" icon={<PlusOutlined />} onClick={e => showModal('新增药品信息',1)}>新增</Button>
  278. </Col>
  279. </Row>
  280. </div>
  281. <ConfigProvider renderEmpty={loading?renderEmpty:""}>
  282. <Table
  283. /*rowSelection={{ type: 'checkbox', ...rowSelection, }}*/
  284. columns={columns}
  285. scroll={{ y: 'calc(100vh - 400px)' }}
  286. dataSource={DrugList}
  287. rowKey={record => record.id}
  288. pagination={{
  289. current: current,
  290. pageSize: size,
  291. size: 'small',
  292. showSizeChanger: true,
  293. pageSizeOptions: ['15', '30', '60', '120'],
  294. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  295. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  296. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  297. total: total
  298. }} />
  299. </ConfigProvider>
  300. </div>
  301. <AddTerm formData={formData} termSType={5} termType={5} onOk={saveMatching} title={title} visible={visible} cancel={cancel} flag={flag}/>
  302. <Modal
  303. maskClosable={false}
  304. title="删除药品信息"
  305. okText='确定'
  306. cancelText='关闭'
  307. width={400}
  308. visible={delvisible}
  309. onOk={delDrugeryById}
  310. onCancel={handleCancel}
  311. >
  312. <p>药品信息删除后将无法恢复,确认删除这条手术信息。</p>
  313. </Modal>
  314. </div>
  315. )
  316. }
  317. export default DrugManager;