index.js 9.1 KB

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