MatchSurg.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React, {
  2. useState, useEffect
  3. } from 'react';
  4. import { Input, Table,Row,Col } from 'antd';
  5. import apiObj from '@api/index';
  6. const { post, api } = apiObj;
  7. const { Search } = Input;
  8. function MatchSurg(props) {
  9. const isMapping = props.row.isMapping==="已匹配";
  10. const [DiagList, setDiagList] = useState([]);//当前页列表数据
  11. const [size, setSize] = useState(15);//每页显示条数
  12. const [total, setTotal] = useState(0);
  13. const [current, setCurrent] = useState(1);//当前页
  14. const [text,setText] = useState(isMapping?"":props.row.name);//输入框中内容
  15. const [diagId,setDiagId] = useState(props.row.id);//诊断id
  16. const [selectedRowKeys,setselectedRowKeys] = useState([]);//选中的行id
  17. const [params, setParams] = useState({
  18. pages: 1,
  19. current: 1,
  20. size: 15,
  21. name:""
  22. });
  23. const columns = [
  24. { title: '手术和操作代码', dataIndex: 'code',},
  25. { title: '标准手术/操作名称', dataIndex: 'standard',},
  26. { title: '同义词', dataIndex: 'synonym',},
  27. ];
  28. useEffect(() => {
  29. let param={};
  30. if(isMapping){
  31. param = {id:props.row.id};
  32. }else{
  33. //默认搜索手术名称
  34. param = {...params,name:text.trim(),current:1};
  35. }
  36. getPage(param);
  37. }, []);
  38. const rowSelection = {
  39. preserveSelectedRowKeys:true,
  40. selectedRowKeys:selectedRowKeys||[],
  41. onChange: (selectedRowKeys, selectedRows) => {
  42. const param = {code:selectedRows[0].code,
  43. standard:selectedRows[0].standard,
  44. synonym:selectedRows[0].synonym,
  45. id:diagId
  46. };
  47. setselectedRowKeys(selectedRowKeys);
  48. //setParams(param);
  49. props.onChange(param);
  50. },
  51. };
  52. //每页显示条数切换
  53. function onSizeChange(current, pageSize) {
  54. params.current = current
  55. params.size = pageSize
  56. setSize(pageSize)
  57. setCurrent(current)
  58. setParams(params)
  59. getPage()
  60. }
  61. //翻页
  62. function changePage(page, pageSize) {
  63. params.current = page
  64. params.size = pageSize
  65. setCurrent(page)
  66. setParams(params)
  67. getPage()
  68. }
  69. function onSearch(){
  70. const param = {...params,name:text.trim(),current:1};
  71. setParams({...params,name:text.trim(),current:1});
  72. getPage(param);
  73. }
  74. function onChange(e){
  75. const val = e.target.value;
  76. setText(val);
  77. }
  78. function getPage(param) {
  79. //已匹配的获取已被匹配的那条数据即可
  80. const url = isMapping?api.getOperationById:api.getConceptLibraryPage;
  81. const pm = param||params;
  82. const paramData = isMapping?pm:{...pm,type:2}; //type:1:诊断,2:手术,3:药品
  83. post(url, paramData).then((res) => {
  84. if (res.data.code === 200) {
  85. const data = res.data.data;
  86. const list = isMapping?[data]:data.records;
  87. setselectedRowKeys(isMapping?[data.id]:[]);
  88. setDiagList(list);
  89. setTotal(data.total||0)
  90. }
  91. })
  92. }
  93. return (
  94. <>
  95. <Row gutter={24}>
  96. <Col span={12} key={0}>
  97. <Search placeholder="请输入手术/操作名称" onSearch={onSearch} value={text} onChange={onChange} enterButton style={{marginBottom:'14px'}}/>
  98. </Col>
  99. </Row>
  100. <Table
  101. rowSelection={{type: 'radio',...rowSelection,}}
  102. columns={columns}
  103. scroll={{ y: 'calc(100vh - 320px)' }}
  104. dataSource={DiagList}
  105. rowKey={record => record.standard}
  106. pagination={{
  107. current: current,
  108. pageSize: size,
  109. size: 'small',
  110. showSizeChanger: true,
  111. pageSizeOptions: ['15', '30', '60', '120'],
  112. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  113. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  114. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  115. total: total
  116. }} />
  117. </>
  118. );
  119. }
  120. export default MatchSurg;