Resource.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React, { useEffect, useState, useRef } from 'react';
  2. import { connect } from 'dva';
  3. import { Form, Table, DatePicker, Input, Button } from 'antd';
  4. import report from './models/report';
  5. import moment from 'moment';
  6. const { RangePicker } = DatePicker;
  7. function Resource(props) {
  8. const { dispatch, form, loading, res } = props;
  9. const columns = [
  10. {
  11. title: '用户名称',
  12. dataIndex: 'user_name',
  13. },
  14. // {
  15. // title: '资源编号',
  16. // dataIndex: 'name',
  17. // },
  18. {
  19. title: '部门',
  20. dataIndex: 'dep_name',
  21. },
  22. {
  23. title: '报工类型',
  24. dataIndex: 'type_type_id',
  25. render: type => (type == 1 ? '非项目' : '项目'),
  26. },
  27. {
  28. title: '工时类型',
  29. dataIndex: 'type_name',
  30. },
  31. {
  32. title: '项目名称',
  33. dataIndex: 'project_name',
  34. },
  35. {
  36. title: '项目编号',
  37. dataIndex: 'project_code',
  38. },
  39. {
  40. title: '项目归属部门',
  41. dataIndex: 'project_dep_name',
  42. },
  43. {
  44. title: '工时统计',
  45. children: [
  46. {
  47. title: '保存未提交',
  48. dataIndex: 'un_audit_cnt',
  49. },
  50. {
  51. title: '提交未审批',
  52. dataIndex: 'pending_audit_cnt',
  53. },
  54. {
  55. title: '审批通过',
  56. dataIndex: 'pass_audit_cnt',
  57. },
  58. {
  59. title: '已拒绝',
  60. dataIndex: 'refuse_audit_cnt',
  61. },
  62. ],
  63. },
  64. ];
  65. const filterRef = useRef({});
  66. const onChangePage = pagination => {
  67. dispatch({
  68. type: 'report/queryResReport',
  69. payload: {
  70. ...filterRef.current,
  71. currentPage: pagination.current,
  72. },
  73. });
  74. };
  75. const handleSearch = () => {
  76. form.validateFields((error, { time }) => {
  77. let params = {};
  78. params.s_time = time[0] ? moment(time[0]).format('YYYY-MM-DD 00:00:00') : null;
  79. params.e_time = time[1] ? moment(time[1]).format('YYYY-MM-DD 23:59:59') : null;
  80. filterRef.current = params;
  81. dispatch({
  82. type: 'report/queryResReport',
  83. payload: params,
  84. });
  85. });
  86. };
  87. const renderSearch = () => {
  88. const formItemLayout = {
  89. labelCol: { span: 5 },
  90. wrapperCol: { span: 18 },
  91. };
  92. return (
  93. <Form layout="inline" {...formItemLayout}>
  94. <Form.Item label="时间">
  95. {form.getFieldDecorator('time')(<RangePicker placeholder="选择时间" />)}
  96. </Form.Item>
  97. <Form.Item>
  98. <Button type="primary" loading={loading} onClick={handleSearch}>
  99. 查询
  100. </Button>
  101. </Form.Item>
  102. </Form>
  103. );
  104. };
  105. useEffect(() => {
  106. dispatch({
  107. type: 'report/queryResReport',
  108. });
  109. }, []);
  110. return (
  111. <div>
  112. {renderSearch()}
  113. <Table
  114. style={{ marginTop: 20 }}
  115. columns={columns}
  116. dataSource={res.list}
  117. pagination={res.pagination}
  118. onChange={onChangePage}
  119. />
  120. </div>
  121. );
  122. }
  123. export default connect(({ report, loading }) => ({
  124. res: report.res,
  125. loading: loading.models.report,
  126. }))(Form.create()(Resource));