index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Form, Input, Button, Table, Pagination, Row, Col, Select, Modal, DatePicker } from 'antd';
  3. import { useSelector } from 'react-redux';
  4. import '@common/common.less';
  5. import apiObj from '@api/index';
  6. import moment from "moment";
  7. import "moment/locale/zh-cn"
  8. import { message } from "antd/lib/index";
  9. import { disabledDate,getDaysBetween } from '@utils/index'
  10. const { post, api, xPost } = apiObj;
  11. const { RangePicker } = DatePicker;
  12. const { Option } = Select;
  13. function DutyRecord() {
  14. const { dutyNum } = useSelector((state) => {
  15. return state.userInfo;
  16. });
  17. useEffect(() => {
  18. setSize(15)
  19. setCurrent(1)
  20. setSelectedRowKeys([])
  21. form.resetFields();
  22. getDutyRecord();
  23. }, [dutyNum]);
  24. let today = getNowFormatDate()
  25. let lastmonthday= getlastmonthday()
  26. const [logList, setLogList] = useState([]);
  27. const [total, setTotal] = useState(0);
  28. const [visible, setVisible] = useState(false);
  29. const [size, setSize] = useState(15);
  30. const [current, setCurrent] = useState(1);
  31. const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  32. const [params, setParams] = useState({
  33. changeTimeEnd:today.split('/').join('-') + ' 23:59:59',
  34. changeTimeStart:lastmonthday.split('/').join('-') + ' 00:00:00',
  35. pages: 1,
  36. current: 1,
  37. size: 15
  38. });
  39. const [form] = Form.useForm();
  40. const typeMap = {
  41. '1': '职务变更',
  42. '2': '职称变更'
  43. };
  44. let data = {
  45. changeTimeEnd:today.split('/').join('-') + ' 23:59:59',
  46. changeTimeStart:lastmonthday.split('/').join('-') + ' 00:00:00',
  47. pages: 1,
  48. current: 1,
  49. size: 15
  50. }
  51. function getlastmonthday(){
  52. let time = new Date((new Date() - 30 * 24 * 3600 * 1000)).toLocaleDateString()
  53. return time
  54. }
  55. function getNowFormatDate() {
  56. let time = new Date().toLocaleDateString()
  57. return time
  58. }
  59. //表格数据
  60. function getDutyRecord(param) {
  61. const hide = message.loading('加载中...',0);
  62. post(api.getOfficialCapacityPage, param || params).then((res) => {
  63. hide()
  64. if (res.data.code === 200) {
  65. const data = res.data.data;
  66. setLogList(data.records);
  67. setTotal(data.total)
  68. }
  69. })
  70. }
  71. //删除记录
  72. function delRecord() {
  73. post(api.delOfficialCapacityPage, { id: selectedRowKeys }).then((res) => {
  74. if (res.data.code === 200) {
  75. //刷新列表
  76. const totalPage = Math.ceil((total - selectedRowKeys.length) / size);
  77. //将当前页码与删除数据之后的总页数进行比较,避免当前页码不存在
  78. const pagenum =
  79. params.current > totalPage ? totalPage : params.current;
  80. //避免pagenum变为0
  81. params.current = pagenum < 1 ? 1 : pagenum;
  82. setParams(params)
  83. //刷新列表
  84. getDutyRecord()
  85. } else {
  86. message.warning(res.data.msg || '操作失败,请重试~');
  87. }
  88. });
  89. showDelModal(false);
  90. }
  91. //删除弹窗确认
  92. function showDelModal(flag) {
  93. console.log(selectedRowKeys)
  94. if (flag && !selectedRowKeys.length) {
  95. message.warning("请先选择要删除的记录~", 1);
  96. return;
  97. }
  98. setVisible(flag)
  99. }
  100. function onSizeChange(current, pageSize) {
  101. params.current = current
  102. params.size = pageSize
  103. setSize(pageSize)
  104. setCurrent(current)
  105. setParams(params)
  106. }
  107. function changePage(page, pageSize) {
  108. params.current = page
  109. params.size = pageSize
  110. setParams(params)
  111. setCurrent(page)
  112. getDutyRecord()
  113. }
  114. function onSelectChange(selectedRowKeys) {
  115. setSelectedRowKeys(selectedRowKeys);
  116. };
  117. const onFinish = (value) => {
  118. value.changeTimeStart = moment(value.changeTimeStart).format('YYYY-MM-DD 00:00:00');
  119. value.changeTimeEnd = moment(value.changeTimeEnd).format('YYYY-MM-DD 23:59:59');
  120. if (value.changeTimeStart > value.changeTimeEnd) {
  121. message.warning('开始时间不能大于结束时间');
  122. return
  123. }
  124. params.current = 1
  125. const param = {
  126. ...params,
  127. ...value,
  128. }
  129. setSelectedRowKeys([])
  130. setCurrent(1)
  131. setParams(param)
  132. getDutyRecord(param);
  133. };
  134. const onReset = () => {
  135. setSize(15)
  136. setSelectedRowKeys([])
  137. setCurrent(1)
  138. setParams(data)
  139. form.resetFields();
  140. getDutyRecord(data);
  141. };
  142. const columns = [
  143. { title: '医生姓名', dataIndex: 'doctorName', key: 'doctorName' },
  144. { title: '科室', dataIndex: 'deptName', key: 'deptName' },
  145. { title: '工号', dataIndex: 'doctorCode', key: 'doctorCode' },
  146. { title: '变更时间', dataIndex: 'changeTime', key: 'changeTime' },
  147. { title: '职务/职称名称', dataIndex: 'name', key: 'name' },
  148. {
  149. title: '变更类型', dataIndex: 'type', key: 'type', render: (text, record) => {
  150. return typeMap[record.type];
  151. }
  152. },
  153. ];
  154. const rowSelection = {
  155. selectedRowKeys,
  156. onChange: onSelectChange,
  157. };
  158. return (
  159. <div className="wrapper">
  160. <div className="filter-box">
  161. <Form
  162. form={form}
  163. name="normal_login"
  164. onFinish={onFinish}
  165. initialValues={{ type: '', changeTimeStart: moment(lastmonthday), changeTimeEnd: moment(today) }}
  166. >
  167. <Row gutter={24}>
  168. <Col span={5} key={0}>
  169. <Form.Item label="医生姓名" name="doctorName">
  170. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  171. </Form.Item>
  172. </Col>
  173. <Col span={5} key={1}>
  174. <Form.Item label="科室" name="deptName">
  175. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  176. </Form.Item>
  177. </Col>
  178. <Col span={5} key={2}>
  179. <Form.Item label="工号" name="doctorCode">
  180. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  181. </Form.Item>
  182. </Col>
  183. <Col span={5} key={3}>
  184. <Form.Item label="职务/职称名称" name="name">
  185. <Input placeholder="请输入" autoComplete='off' allowClear maxLength='30'/>
  186. </Form.Item>
  187. </Col>
  188. <Col span={5} key={4}>
  189. <Form.Item label="变更类型" name="type">
  190. <Select
  191. placeholder="请选择"
  192. >
  193. <Option value="" key={0}>全部</Option>
  194. <Option value="1" key={1}>{typeMap['1']}</Option>
  195. <Option value="2" key={2}>{typeMap['2']}</Option>
  196. </Select>
  197. </Form.Item>
  198. </Col>
  199. <Col span={8} key={5}>
  200. <Form.Item label="变更时间" style={{height:'32px'}}>
  201. <Form.Item name="changeTimeStart" className='times'>
  202. <DatePicker
  203. allowClear={false}
  204. disabledDate={disabledDate}
  205. placeholder="请选择开始日期"
  206. />
  207. </Form.Item>
  208. <span style={{ margin: '0 5px', position: 'relative', top: '2px' }}>-</span>
  209. <Form.Item name="changeTimeEnd" className='times'>
  210. <DatePicker
  211. allowClear={false}
  212. disabledDate={disabledDate}
  213. placeholder="请选择结束日期"
  214. />
  215. </Form.Item>
  216. </Form.Item>
  217. </Col>
  218. <Col span={6} key={6}>
  219. <Form.Item>
  220. <Button type="primary" htmlType="submit">
  221. 查询
  222. </Button>
  223. <Button onClick={onReset}>
  224. 重置
  225. </Button>
  226. </Form.Item>
  227. </Col>
  228. </Row>
  229. </Form>
  230. </div>
  231. <div className="table">
  232. <div className="table-header">
  233. <h2 className="table-title">职务职称变更记录</h2>
  234. <Button type="primary" onClick={() => showDelModal(true)} danger>删除</Button>
  235. </div>
  236. <Table
  237. columns={columns}
  238. rowSelection={rowSelection}
  239. scroll={{ y: 'calc(100vh - 400px)' }}
  240. dataSource={logList}
  241. rowKey={record => record.id}
  242. pagination={{
  243. pageSize: size,
  244. size: 'small',
  245. current: current,
  246. showSizeChanger: true,
  247. pageSizeOptions: ['15', '30', '60', '120'],
  248. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  249. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  250. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  251. total: total
  252. }} />
  253. </div>
  254. <Modal
  255. title="删除职务职称变更记录"
  256. okText='确定'
  257. cancelText='关闭'
  258. width={400}
  259. visible={visible}
  260. onOk={delRecord}
  261. /*confirmLoading={confirmLoading}*/
  262. onCancel={() => showDelModal(false)}
  263. maskClosable={false}
  264. >
  265. <p>职务职称变更记录删除后将无法恢复,确认删除这{selectedRowKeys.length}条变更记录?</p>
  266. </Modal>
  267. </div >
  268. )
  269. }
  270. export default DutyRecord;