index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Form, Input, Button, Table, Pagination, Row, Col, Select, Modal, DatePicker } from 'antd';
  3. import '@common/common.less';
  4. import apiObj from '@api/index';
  5. import moment from "moment";
  6. import "moment/locale/zh-cn"
  7. import { message } from "antd/lib/index";
  8. import { disabledDate } from '@utils/index'
  9. const { post, api, xPost } = apiObj;
  10. const { RangePicker } = DatePicker;
  11. const { Option } = Select;
  12. function DutyRecord() {
  13. useEffect(() => {
  14. getDutyRecord();
  15. }, []);
  16. const [logList, setLogList] = useState([]);
  17. const [total, setTotal] = useState(0);
  18. const [visible, setVisible] = useState(false);
  19. const [size, setSize] = useState(15);
  20. const [current, setCurrent] = useState(1);
  21. const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  22. const [params, setParams] = useState({
  23. pages: 1,
  24. current: 1,
  25. size: 15
  26. });
  27. const [form] = Form.useForm();
  28. const typeMap = {
  29. '1': '职务变更',
  30. '2': '职称变更'
  31. };
  32. let data = {
  33. pages: 1,
  34. current: 1,
  35. size: size
  36. }
  37. //表格数据
  38. function getDutyRecord(param) {
  39. post(api.getOfficialCapacityPage, param || params).then((res) => {
  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 delRecord() {
  49. post(api.delOfficialCapacityPage, { id: selectedRowKeys }).then((res) => {
  50. if (res.data.code === 200) {
  51. //刷新列表
  52. getDutyRecord()
  53. } else {
  54. message.warning(res.data.msg || '操作失败,请重试~');
  55. }
  56. });
  57. showDelModal(false);
  58. }
  59. //删除弹窗确认
  60. function showDelModal(flag) {
  61. console.log(selectedRowKeys)
  62. if (flag && !selectedRowKeys.length) {
  63. message.warning("请先选择要删除的记录~", 1);
  64. return;
  65. }
  66. setVisible(flag)
  67. }
  68. function onSizeChange(current, pageSize) {
  69. params.current = current
  70. params.size = pageSize
  71. setSize(pageSize)
  72. setCurrent(current)
  73. setParams(params)
  74. getDutyRecord()
  75. }
  76. function changePage(page, pageSize) {
  77. params.current = page
  78. params.size = pageSize
  79. setParams(params)
  80. setCurrent(page)
  81. getDutyRecord()
  82. }
  83. function onSelectChange(selectedRowKeys) {
  84. setSelectedRowKeys(selectedRowKeys);
  85. };
  86. const onFinish = (value) => {
  87. if (value.changeTime) {
  88. value.changeTimeStart = moment(value.changeTime[0]).format('YYYY-MM-DD 00:00:00')
  89. value.changeTimeEnd = moment(value.changeTime[1]).format('YYYY-MM-DD 23:23:59')
  90. }
  91. const param = {
  92. ...data,
  93. ...value,
  94. }
  95. setCurrent(1)
  96. setParams(param)
  97. getDutyRecord(param);
  98. };
  99. const onReset = () => {
  100. setCurrent(1)
  101. setParams(data)
  102. form.resetFields();
  103. getDutyRecord(data);
  104. };
  105. const columns = [
  106. { title: '医生姓名', dataIndex: 'doctorName', key: 'doctorName' },
  107. { title: '科室', dataIndex: 'deptName', key: 'deptName' },
  108. { title: '工号', dataIndex: 'doctorCode', key: 'doctorCode' },
  109. { title: '变更时间', dataIndex: 'changeTime', key: 'changeTime' },
  110. { title: '职务/职称名称', dataIndex: 'name', key: 'name' },
  111. {
  112. title: '变更类型', dataIndex: 'type', key: 'type', render: (text, record) => {
  113. return typeMap[record.type];
  114. }
  115. },
  116. ];
  117. const rowSelection = {
  118. selectedRowKeys,
  119. onChange: onSelectChange,
  120. };
  121. return (
  122. <div className="wrapper">
  123. <div className="filter-box">
  124. <Form
  125. form={form}
  126. name="normal_login"
  127. onFinish={onFinish}
  128. initialValues={{ type: '' }}
  129. >
  130. <Row gutter={24}>
  131. <Col span={5} key={0}>
  132. <Form.Item label="医生姓名" name="doctorName">
  133. <Input placeholder="请输入" autoComplete='off' allowClear/>
  134. </Form.Item>
  135. </Col>
  136. <Col span={5} key={1}>
  137. <Form.Item label="科室" name="deptName">
  138. <Input placeholder="请输入" autoComplete='off' allowClear/>
  139. </Form.Item>
  140. </Col>
  141. <Col span={5} key={2}>
  142. <Form.Item label="工号" name="doctorCode">
  143. <Input placeholder="请输入" autoComplete='off' allowClear/>
  144. </Form.Item>
  145. </Col>
  146. <Col span={5} key={3}>
  147. <Form.Item label="职务/职称名称" name="name">
  148. <Input placeholder="请输入" autoComplete='off' allowClear/>
  149. </Form.Item>
  150. </Col>
  151. <Col span={5} key={4}>
  152. <Form.Item label="变更类型" name="type">
  153. <Select
  154. placeholder="请选择"
  155. allowClear
  156. >
  157. <Option value="" key={0}>全部</Option>
  158. <Option value="1" key={1}>{typeMap['1']}</Option>
  159. <Option value="2" key={2}>{typeMap['2']}</Option>
  160. </Select>
  161. </Form.Item>
  162. </Col>
  163. <Col span={7} key={5}>
  164. <Form.Item label="变更时间" name="changeTime">
  165. <RangePicker
  166. disabledDate={disabledDate}
  167. placeholder={['开始时间', '结束时间']}
  168. />
  169. </Form.Item>
  170. </Col>
  171. <Col span={6} key={6}>
  172. <Form.Item>
  173. <Button type="primary" htmlType="submit">
  174. 查询
  175. </Button>
  176. <Button onClick={onReset}>
  177. 重置
  178. </Button>
  179. </Form.Item>
  180. </Col>
  181. </Row>
  182. </Form>
  183. </div>
  184. <div className="table">
  185. <div className="table-header">
  186. <h2 className="table-title">职务职称变更记录</h2>
  187. <Button type="primary" onClick={() => showDelModal(true)} danger>删除</Button>
  188. </div>
  189. <Table
  190. columns={columns}
  191. rowSelection={rowSelection}
  192. scroll={{ y: 'calc(100vh - 360px)' }}
  193. dataSource={logList}
  194. rowKey={record => record.id}
  195. pagination={{
  196. pageSize: size,
  197. size: 'small',
  198. current: current,
  199. showSizeChanger: true,
  200. pageSizeOptions: ['15', '30', '60', '120'],
  201. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  202. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  203. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  204. total: total
  205. }} />
  206. </div>
  207. <Modal
  208. title="删除职务职称变更记录"
  209. okText='确定'
  210. cancelText='取消'
  211. width={400}
  212. visible={visible}
  213. onOk={delRecord}
  214. /*confirmLoading={confirmLoading}*/
  215. onCancel={() => showDelModal(false)}
  216. >
  217. <p>职务职称变更记录删除后将无法恢复,确认删除这{selectedRowKeys.length}条变更记录?</p>
  218. </Modal>
  219. </div >
  220. )
  221. }
  222. export default DutyRecord;