index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Table, Modal, Row, Col,message } from 'antd';
  3. import '@common/common.less';
  4. import { useSelector } from 'react-redux';
  5. import apiObj from '@api/index';
  6. import "moment/locale/zh-cn"
  7. const { post, api } = apiObj;
  8. function DocTemplate() {
  9. const { docNum } = useSelector((state) => {
  10. return state.userInfo;
  11. });
  12. useEffect(() => {
  13. setSize(15)
  14. setCurrent(1)
  15. form.resetFields();
  16. getDocTemplate();
  17. }, [docNum]);
  18. const [logList, setLogList] = useState([]);
  19. const [total, setTotal] = useState(0);
  20. const [size, setSize] = useState(15);
  21. const [visible,setVisible] = useState(false);
  22. const [current, setCurrent] = useState(1);
  23. const [tmplInfo,setTmplInfo] = useState({});
  24. const [params, setParams] = useState({
  25. pages: 1,
  26. current: 1,
  27. size: 15
  28. });
  29. const [form] = Form.useForm();
  30. let data = {
  31. pages: 1,
  32. current: 1,
  33. size: 15
  34. }
  35. //表格数据
  36. function getDocTemplate(param) {
  37. const hide = message.loading('加载中...',0);
  38. post(api.getRecordTemplatePage, param || params).then((res) => {
  39. hide()
  40. if (res.data.code === 200) {
  41. const data = res.data.data;
  42. setLogList(data.records);
  43. setTotal(data.total)
  44. }
  45. })
  46. }
  47. //模板详情
  48. function getTmplInfo(flag,id) {
  49. if(!flag){
  50. setVisible(flag);
  51. return;
  52. }
  53. const hide = message.loading('加载中...',0);
  54. post(api.getRecordTemplateManage, {id}).then((res) => {
  55. hide();
  56. if (res.data.code === 200) {
  57. const data = res.data.data;
  58. if(data.type==="2"){ //模板类型,0:未知,1:html,2:xml
  59. setVisible(flag);
  60. setTmplInfo(data);
  61. console.log(data.content)
  62. }else{
  63. const myWindow=window.open('','','width=800,height=600');
  64. myWindow.document.write(data.content);
  65. myWindow.focus();
  66. }
  67. }
  68. })
  69. }
  70. function onSizeChange(current, pageSize) {
  71. params.current = current
  72. params.size = pageSize
  73. setSize(pageSize)
  74. setCurrent(current)
  75. setParams(params)
  76. }
  77. function changePage(page, pageSize) {
  78. params.current = page
  79. params.size = pageSize
  80. setParams(params)
  81. setCurrent(page)
  82. getDocTemplate()
  83. }
  84. //查看模板
  85. /*function showModal(flag,id){
  86. if(flag){
  87. getTmplInfo(id);
  88. }
  89. }*/
  90. const onFinish = (value) => {
  91. const param = {
  92. ...params,
  93. ...value,
  94. }
  95. setCurrent(1)
  96. setParams(param)
  97. getDocTemplate(param);
  98. };
  99. const onReset = () => {
  100. setSize(15)
  101. setCurrent(1)
  102. setParams(data)
  103. form.resetFields();
  104. getDocTemplate(data);
  105. };
  106. const columns = [
  107. { title: '医院模板ID', dataIndex: 'code', key: 'code' },
  108. { title: '医院模板名称', dataIndex: 'name', key: 'name' },
  109. { title: '医院父类模板ID', dataIndex: 'parentCode', key: 'parentCode' },
  110. { title: '医院父类模板名称', dataIndex: 'parentName', key: 'parentName' },
  111. {
  112. title: '操作', dataIndex: 'operation', key: 'operation', render: (text, record) =>{
  113. return <a className="showDetail" onClick={()=>getTmplInfo(true,record.id)}>查看</a>
  114. }
  115. },
  116. ]
  117. return (
  118. <div className="wrapper">
  119. <div className="filter-box">
  120. <Form
  121. form={form}
  122. name="normal_login"
  123. onFinish={onFinish}
  124. >
  125. <Row gutter={24}>
  126. <Col span={5} key={0}>
  127. <Form.Item label="医院模板ID" name="code">
  128. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  129. </Form.Item>
  130. </Col>
  131. <Col span={5} key={1}>
  132. <Form.Item label="医院模板名称" name="name">
  133. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  134. </Form.Item>
  135. </Col>
  136. <Col span={5} key={2}>
  137. <Form.Item label="医院父类模板ID" name="parentCode">
  138. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  139. </Form.Item>
  140. </Col>
  141. <Col span={5} key={4}>
  142. <Form.Item label="医院父类模板名称" name="parentName">
  143. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  144. </Form.Item>
  145. </Col>
  146. <Col span={4} key={5}>
  147. <Form.Item>
  148. <Button type="primary" htmlType="submit">
  149. 查询
  150. </Button>
  151. <Button onClick={onReset}>
  152. 重置
  153. </Button>
  154. </Form.Item>
  155. </Col>
  156. </Row>
  157. </Form>
  158. </div>
  159. <div className="table">
  160. <div className="table-header">
  161. <h2 className="table-title">文书模板维护</h2>
  162. </div>
  163. <Table
  164. columns={columns}
  165. scroll={{ y: 'calc(100vh - 400px)' }}
  166. dataSource={logList}
  167. rowKey={record => record.id}
  168. pagination={{
  169. pageSize: size,
  170. size: 'small',
  171. current: current,
  172. showSizeChanger: true,
  173. pageSizeOptions: ['15', '30', '60', '120'],
  174. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  175. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  176. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  177. total: total
  178. }} />
  179. </div>
  180. <Modal
  181. destroyOnClose={true}
  182. title="查看文书模板"
  183. footer={[<Button key={1} type="primary" onClick={()=>setVisible(false)}>
  184. 关闭
  185. </Button>]}
  186. width="90%"
  187. visible={visible}
  188. onCancel={()=>setVisible(false)}
  189. >
  190. <div>
  191. {tmplInfo.content}
  192. </div>
  193. </Modal>
  194. </div >
  195. )
  196. }
  197. export default DocTemplate;