UserProjectRptModal.js 3.6 KB

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