index.js 8.5 KB

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