UserProjectRptModal.js 3.7 KB

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