index.js 4.9 KB

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