UserProjectRptModal.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, { useState, useEffect } from 'react';
  2. import { Modal, Table, Form, Input, Button } from 'antd';
  3. import { connect } from 'dva';
  4. import moment from 'moment';
  5. function UserProjectRptModal(props) {
  6. const { dispatch, visible, onOk, onCancel, data, filter, loading, form } = props;
  7. // const getMonthColumns = () => {
  8. // let arr = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
  9. // return {
  10. // title: '月份',
  11. // children: arr.map((item, index) => ({
  12. // title: `${item}`,
  13. // dataIndex: `month[${String(index)}].total_audit_cnt`,
  14. // render: cnt => cnt || 0,
  15. // })),
  16. // };
  17. // };
  18. const getMonthColumns = () => {
  19. let arr = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
  20. var time = [moment(filter.s_time), moment(filter.e_time)];
  21. var date = {};
  22. let eYear = time[1].year();
  23. let eMonth = time[1].month();
  24. let current = moment(time[0]);
  25. let cYear, cMonth;
  26. for (let i = 0; i < 12; i++) {
  27. cYear = current.year();
  28. cMonth = current.month();
  29. if (!date[cYear]) date[cYear] = [];
  30. date[cYear].push(arr[cMonth]);
  31. current.add('month', 1);
  32. }
  33. current.subtract('month', 12);
  34. let monthColumns = Object.keys(date).map(year => ({
  35. title: year + '年',
  36. children: date[year].map(item => {
  37. let key = current.format('YYYY-MM');
  38. current.add('month', 1);
  39. return {
  40. title: `${item}`,
  41. render: record => {
  42. const { month_rpt } = record;
  43. return month_rpt.find(item => item.ts == key)?.pass_audit_cnt || 0;
  44. },
  45. };
  46. }),
  47. }));
  48. return monthColumns;
  49. };
  50. const columns = [
  51. {
  52. title: '用户名称',
  53. dataIndex: 'c_name',
  54. },
  55. {
  56. title: '部门',
  57. dataIndex: 'dep_name',
  58. },
  59. // getMonthColumns(),
  60. ...getMonthColumns(),
  61. {
  62. title: '总计',
  63. dataIndex: 'month_rpt',
  64. render: arr => (arr ? arr.reduce((total, item) => total + item.pass_audit_cnt, 0) : ''),
  65. },
  66. ];
  67. const onChangePage = pagination => {
  68. dispatch({
  69. type: 'report/queryUserProjectReport',
  70. payload: {
  71. ...filter,
  72. currentPage: pagination.current,
  73. },
  74. });
  75. };
  76. const handleSearch = () => {
  77. // if (!filter?.project_id && !filter?.p_type_id) return;
  78. if (!filter?.classification) return;
  79. const dep_name = form.getFieldValue('dep_name');
  80. dispatch({
  81. type: 'report/queryUserProjectReport',
  82. payload: {
  83. ...filter,
  84. dep_name: dep_name,
  85. },
  86. });
  87. };
  88. useEffect(() => {
  89. if (!filter?.project_id) return;
  90. dispatch({
  91. type: 'report/queryUserProjectReport',
  92. payload: filter,
  93. });
  94. }, [filter]);
  95. return (
  96. <Modal title="工时" width="80%" visible={visible} onCancel={onCancel} footer={false}>
  97. <Form layout="inline" style={{ marginBottom: 20 }}>
  98. <Form.Item lable="部门">
  99. {form.getFieldDecorator('dep_name')(<Input placeholder="请输入部门" />)}
  100. </Form.Item>
  101. <Form.Item>
  102. <Button type="primary" onClick={handleSearch}>
  103. 查询
  104. </Button>
  105. </Form.Item>
  106. </Form>
  107. <Table
  108. columns={columns}
  109. loading={loading}
  110. dataSource={data.list}
  111. pagination={data.pagination}
  112. onChange={onChangePage}
  113. ></Table>
  114. </Modal>
  115. );
  116. }
  117. export default connect(({ report, loading }) => ({
  118. data: report.projectUser,
  119. loading: loading.models.report,
  120. }))(Form.create()(UserProjectRptModal));