Project.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import React, { useEffect, useState, useRef } from 'react';
  2. import { connect } from 'dva';
  3. import { Form, Table, DatePicker, Input, Button, Select, message, Popover } from 'antd';
  4. import report from './models/report';
  5. import styles from './report.less';
  6. import moment from 'moment';
  7. import UserProjectRptModal from './UserProjectRptModal';
  8. import { downloadFile, getToken } from '@/utils/utils.js';
  9. const { Option } = Select;
  10. const { RangePicker } = DatePicker;
  11. const initDate = [moment().startOf('years'), moment()];
  12. // var currentYear = new Date().getFullYear();
  13. // var yearList = [];
  14. // // 获得过去10年至未来20年的年份列表
  15. // for (var i = currentYear - 10; i < currentYear + 20; i++) {
  16. // yearList.push(i);
  17. // }
  18. function Resource(props) {
  19. const { dispatch, loading, project } = props;
  20. const [form] = Form.useForm();
  21. const [expandedRowKeys, setExpandedRowKeys] = useState([]);
  22. const [visible, setVisible] = useState(false);
  23. const [modalFilter, setModalFilter] = useState({});
  24. const filterRef = useRef({});
  25. // const onChangePage = pagination => {
  26. // dispatch({
  27. // type: 'report/queryProjectReport',
  28. // payload: {
  29. // ...filterRef.current,
  30. // currentPage: pagination.current,
  31. // },
  32. // });
  33. // };
  34. const getMonthColumns = () => {
  35. let arr = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
  36. var time;
  37. if (filterRef.current.s_time) {
  38. time = [moment(filterRef.current.s_time), moment(filterRef.current.e_time)];
  39. } else {
  40. time = initDate;
  41. }
  42. var date = {};
  43. let eYear = time[1].year();
  44. let eMonth = time[1].month();
  45. let current = moment(time[0]);
  46. let cYear, cMonth;
  47. // do {
  48. // cYear = current.year();
  49. // cMonth = current.month();
  50. // if (!date[cYear]) date[cYear] = [];
  51. // date[cYear].push(arr[cMonth]);
  52. // current.add('month', 1);
  53. // } while (cYear != eYear || cMonth != eMonth);
  54. for (let i = 0; i < 12; i++) {
  55. cYear = current.year();
  56. cMonth = current.month();
  57. if (!date[cYear]) date[cYear] = [];
  58. date[cYear].push(arr[cMonth]);
  59. current.add('month', 1);
  60. }
  61. current.subtract('month', 12);
  62. let monthColumns = Object.keys(date).map(year => ({
  63. title: year + '年',
  64. children: date[year].map(item => {
  65. let key = current.format('YYYY-MM');
  66. current.add('month', 1);
  67. return {
  68. title: `${item}`,
  69. render: record => {
  70. const { month } = record;
  71. return month.find(item => item.st == key)?.pass_audit_cnt || 0;
  72. // return month[key]?.total_audit_cnt || 0;
  73. // return (
  74. // <Popover
  75. // content={
  76. // <>
  77. // {`审核通过: ${month[key]?.pass_audit_cnt || 0}`}
  78. // <br />
  79. // {`审核中: ${month[key]?.pending_audit_cnt || 0}`}
  80. // <br />
  81. // {`审核拒绝: ${month[key]?.refuse_audit_cnt || 0}`}
  82. // <br />
  83. // {`未提审: ${month[key]?.refuse_audit_cnt || 0}`}
  84. // </>
  85. // }
  86. // >
  87. // {month[key]?.total_audit_cnt || 0}
  88. // </Popover>
  89. // );
  90. // return `${JSON.stringify(month)}`;
  91. },
  92. };
  93. }),
  94. }));
  95. return monthColumns;
  96. };
  97. // const onExpand = (expanded, record) => {
  98. // if (expanded && !record.isLoad) {
  99. // dispatch({
  100. // type: 'report/queryProjectReportDetail',
  101. // payload: {
  102. // ...filterRef.current,
  103. // record: record,
  104. // },
  105. // });
  106. // }
  107. // };
  108. const handleSearch = () => {
  109. const { time, project_name } = form.getFieldsValue();
  110. if (
  111. !moment(time[0])
  112. .add(12, 'month')
  113. .isSameOrAfter(time[1])
  114. ) {
  115. message.error('时间间隔超过12个月,请重新选择。');
  116. return;
  117. }
  118. filterRef.current.s_time = time[0] ? moment(time[0]).format('YYYY-MM-DD') : null;
  119. filterRef.current.e_time = time[1] ? moment(time[1]).format('YYYY-MM-DD') : null;
  120. dispatch({
  121. type: 'report/queryProjectReport',
  122. payload: {
  123. ...filterRef.current,
  124. project_name: project_name,
  125. },
  126. });
  127. };
  128. const handleDownload = () => {
  129. const s_time = !filterRef.current.s_time ? '' : filterRef.current.s_time;
  130. const e_time = !filterRef.current.e_time ? '' : filterRef.current.e_time;
  131. const project_name = form.getFieldValue('project_name');
  132. const token = getToken();
  133. downloadFile(
  134. `/api/v2/workload/rpt/projects/export2excel?JWT-TOKEN=${token}&s_time=${s_time}&e_time=${e_time}&project_name=${
  135. !project_name ? '' : project_name
  136. }`,
  137. `项目报表${moment().format('YYYYMMDDHHMMSS')}.xlsx`
  138. );
  139. };
  140. const renderSearch = () => {
  141. return (
  142. <Form layout="inline" form={form}>
  143. <Form.Item label="时间" name="time" initialValue={initDate}>
  144. <RangePicker placeholder="选择时间" allowClear={false} />
  145. </Form.Item>
  146. <Form.Item label="项目" name="project_name">
  147. <Input />
  148. </Form.Item>
  149. <Form.Item>
  150. <Button type="primary" loading={loading} onClick={handleSearch}>
  151. 查询
  152. </Button>
  153. </Form.Item>
  154. </Form>
  155. );
  156. };
  157. const columns = [
  158. {
  159. title: '项目名称',
  160. render: record =>
  161. !record.child && record.total_audit_cnt ? (
  162. <a onClick={() => showUserModal(record)}>{record.name}</a>
  163. ) : (
  164. record.name
  165. ),
  166. },
  167. ...getMonthColumns(),
  168. { title: '总计', dataIndex: 'total_audit_cnt' },
  169. ];
  170. // const columns = [
  171. // {
  172. // title: '项目名称',
  173. // render: record =>
  174. // !record.isParent ? (
  175. // <a onClick={() => showUserModal(record)}>{record.type_name}</a>
  176. // ) : (
  177. // record.type_name
  178. // ),
  179. // },
  180. // {
  181. // title: '分项工作代码',
  182. // align: 'center',
  183. // dataIndex: 'type_code',
  184. // },
  185. // // {
  186. // // title: '项目名称',
  187. // // render: record => (record.project_id == 0 ? '' : record.project_name),
  188. // // },
  189. // // {
  190. // // title: '项目编号',
  191. // // dataIndex: 'project_code',
  192. // // },
  193. // // {
  194. // // title: '工作内容',
  195. // // dataIndex: 'type_name',
  196. // // },
  197. // ...getMonthColumns(),
  198. // {
  199. // title: '总计',
  200. // dataIndex: 'month_rpt',
  201. // render: arr => (
  202. // <Popover
  203. // content={
  204. // <>
  205. // {`审核通过: ${
  206. // arr ? arr.reduce((total, item) => total + item.pass_audit_cnt, 0) : ''
  207. // }`}
  208. // <br />
  209. // {`审核中: ${
  210. // arr ? arr.reduce((total, item) => total + item.pending_audit_cnt, 0) : ''
  211. // }`}
  212. // <br />
  213. // {`审核拒绝: ${
  214. // arr ? arr.reduce((total, item) => total + item.refuse_audit_cnt, 0) : ''
  215. // }`}
  216. // <br />
  217. // {`未提审: ${arr ? arr.reduce((total, item) => total + item.un_audit_cnt, 0) : ''}`}
  218. // </>
  219. // }
  220. // >
  221. // {arr ? arr.reduce((total, item) => total + item.total_audit_cnt, 0) : ''}
  222. // </Popover>
  223. // ),
  224. // },
  225. // ];
  226. const showUserModal = item => {
  227. const { s_time, e_time } = filterRef.current;
  228. setModalFilter({
  229. s_time: s_time,
  230. e_time: e_time,
  231. type_id: item.id,
  232. project_id: item.project_id,
  233. flag: item.flag,
  234. });
  235. setVisible(true);
  236. };
  237. useEffect(() => {
  238. handleSearch();
  239. }, []);
  240. // useEffect(() => {
  241. // setExpandedRowKeys(project.list.map(item => item.id));
  242. // }, [project.list]);
  243. return (
  244. <div className={styles.page}>
  245. <div className={styles.topPart}>
  246. {renderSearch()}
  247. <Button type="primary" onClick={handleDownload}>
  248. 导出
  249. </Button>
  250. </div>
  251. <Table
  252. style={{ marginTop: 20 }}
  253. columns={columns}
  254. rowKey="key"
  255. childrenColumnName="child"
  256. // onExpand={onExpand}
  257. dataSource={project}
  258. pagination={false}
  259. />
  260. <UserProjectRptModal
  261. filter={modalFilter}
  262. visible={visible}
  263. onCancel={() => setVisible(false)}
  264. />
  265. </div>
  266. );
  267. }
  268. export default connect(({ report, loading }) => ({
  269. project: report.project,
  270. // projectList: report.projectList,
  271. loading: loading.models.report,
  272. }))(Resource);