2023-04-23 11:28:18 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* Author: 黎永顺
|
|
|
|
|
|
* name: 报表内容区
|
|
|
|
|
|
* Description:
|
|
|
|
|
|
* Date: 2023/4/21
|
|
|
|
|
|
*/
|
|
|
|
|
|
import React, { Component } from "react";
|
|
|
|
|
|
import { Spin } from "antd";
|
2023-05-12 16:38:07 +08:00
|
|
|
|
import { WeaEchart } from "ecCom";
|
2023-04-23 11:28:18 +08:00
|
|
|
|
import RightOptions from "./rightOptions";
|
2023-05-12 10:18:39 +08:00
|
|
|
|
import ChartsRangeSettingsModal from "./chartsRangeSettingsModal";
|
2023-05-15 09:09:19 +08:00
|
|
|
|
import { mapBarOptions, mapLineOptions, mapPieOptions } from "./condition";
|
2023-05-12 10:18:39 +08:00
|
|
|
|
import { queryRangeSetting, reportStatisticsReportGetData } from "../../../apis/statistics";
|
2023-06-08 11:24:05 +08:00
|
|
|
|
import PovitpivotChartModal from "./povitpivotChartModal";
|
2023-04-23 11:28:18 +08:00
|
|
|
|
import "../index.less";
|
|
|
|
|
|
|
|
|
|
|
|
class ReportContent extends Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
|
super(props);
|
|
|
|
|
|
this.state = {
|
|
|
|
|
|
columns: [],
|
|
|
|
|
|
dataSource: [],
|
|
|
|
|
|
countResult: {},
|
2023-05-12 10:18:39 +08:00
|
|
|
|
loading: false,
|
|
|
|
|
|
viewType: "dataView",
|
|
|
|
|
|
chartsType: "0",
|
2023-05-12 16:38:07 +08:00
|
|
|
|
chartsInfo: {},
|
2023-06-08 11:24:05 +08:00
|
|
|
|
povitView: {
|
|
|
|
|
|
visible: false, id: "",
|
|
|
|
|
|
dimensionId: "", dimensionValue: ""
|
|
|
|
|
|
},
|
2023-05-12 10:18:39 +08:00
|
|
|
|
rangSet: {
|
|
|
|
|
|
visible: false, reportId: "",
|
2023-05-12 16:38:07 +08:00
|
|
|
|
rangeVal: {}
|
2023-05-12 10:18:39 +08:00
|
|
|
|
}
|
2023-04-23 11:28:18 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
window.addEventListener("message", this.handleReceive, false);
|
2023-05-12 16:38:07 +08:00
|
|
|
|
if (this.refs.chart) this.refs.chart.paint();
|
2023-04-23 11:28:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps, nextContext) {
|
|
|
|
|
|
if (nextProps.report !== this.props.report && nextProps.report.dimensionId) {
|
|
|
|
|
|
this.reportStatisticsReportGetData(nextProps.report.id, nextProps.report.dimensionId);
|
2023-05-12 16:38:07 +08:00
|
|
|
|
this.setState({ viewType: "dataView", chartsInfo: {} });
|
2023-04-23 11:28:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
|
window.removeEventListener("message", this.handleReceive, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleReceive = ({ data }) => {
|
2023-06-08 11:24:05 +08:00
|
|
|
|
const { type, payload: { id, params } = {} } = data;
|
2023-04-23 11:28:18 +08:00
|
|
|
|
if (type === "init") {
|
|
|
|
|
|
const { columns, countResult, dataSource } = this.state;
|
|
|
|
|
|
this.postMessageToChild({
|
|
|
|
|
|
columns, countResult, dataSource,
|
|
|
|
|
|
showSum: !_.isEmpty(countResult)
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (type === "turn") {
|
2023-06-08 11:24:05 +08:00
|
|
|
|
//数据透视弹框
|
|
|
|
|
|
if (id === "PIVOTCHART") {
|
|
|
|
|
|
const { record } = params;
|
|
|
|
|
|
const { dimension: dimensionValue } = record;
|
|
|
|
|
|
const { id: pivotId, dimensionId } = this.props.report;
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
povitView: {
|
|
|
|
|
|
visible: true, id: pivotId, dimensionId, dimensionValue
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2023-04-23 11:28:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
postMessageToChild = (payload) => {
|
|
|
|
|
|
const childFrameObj = document.getElementById("atdTable");
|
|
|
|
|
|
const { dataSource, columns, showSum, countResult } = payload;
|
2023-05-15 18:21:23 +08:00
|
|
|
|
childFrameObj && childFrameObj.contentWindow.postMessage(JSON.stringify({
|
2023-04-23 11:28:18 +08:00
|
|
|
|
dataSource, columns, showSum, countResult
|
|
|
|
|
|
}), "*");
|
|
|
|
|
|
};
|
|
|
|
|
|
reportStatisticsReportGetData = (id, dimensionId) => {
|
|
|
|
|
|
const payload = { id, dimensionId };
|
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
reportStatisticsReportGetData(payload).then(({ status, data }) => {
|
|
|
|
|
|
this.setState({ loading: false });
|
2023-06-09 10:47:51 +08:00
|
|
|
|
if (status && id.toString() === data.reportId.toString()) {
|
2023-04-23 11:28:18 +08:00
|
|
|
|
const { countResult, columns, pageInfo: { list } } = data;
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
countResult,
|
2023-04-24 16:25:07 +08:00
|
|
|
|
columns: _.map(columns, it => ({
|
|
|
|
|
|
...it,
|
|
|
|
|
|
dataIndex: it.column, width: 150,
|
|
|
|
|
|
title: it.text, align: "center",
|
|
|
|
|
|
children: !_.isNil(it.children) ? _.map(it.children, child => ({
|
|
|
|
|
|
...child,
|
|
|
|
|
|
dataIndex: child.column, width: 150,
|
|
|
|
|
|
title: child.text, align: "center"
|
|
|
|
|
|
})) : []
|
|
|
|
|
|
})),
|
2023-04-23 11:28:18 +08:00
|
|
|
|
dataSource: list || []
|
|
|
|
|
|
}, () => {
|
|
|
|
|
|
this.postMessageToChild({
|
|
|
|
|
|
columns: this.state.columns, countResult: this.state.countResult,
|
|
|
|
|
|
dataSource: this.state.dataSource,
|
|
|
|
|
|
showSum: !_.isEmpty(this.state.countResult)
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(() => this.setState({ loading: false }));
|
|
|
|
|
|
};
|
2023-05-12 16:51:30 +08:00
|
|
|
|
queryRangeSetting = (payload, isTab) => {
|
2023-05-12 16:38:07 +08:00
|
|
|
|
const { dataSource, columns } = this.state;
|
2023-05-12 10:18:39 +08:00
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
queryRangeSetting(payload).then(({ status, data }) => {
|
|
|
|
|
|
this.setState({ loading: false });
|
|
|
|
|
|
if (status) {
|
2023-05-12 16:38:07 +08:00
|
|
|
|
const { rangSet, viewType } = this.state;
|
|
|
|
|
|
const { itemValues, itemColValue, id } = data;
|
2023-05-12 10:18:39 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
|
rangSet: {
|
|
|
|
|
|
...rangSet,
|
|
|
|
|
|
rangeVal: data
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-05-12 16:38:07 +08:00
|
|
|
|
if (id) {
|
2023-05-12 16:51:30 +08:00
|
|
|
|
if (!isTab) return;
|
2023-05-12 16:38:07 +08:00
|
|
|
|
switch (viewType) {
|
|
|
|
|
|
case "bar":
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
chartsInfo: {
|
|
|
|
|
|
name: _.find(_.reduce(_.filter(columns, col => !_.isNil(col.children)), (pre, cur) => ([...pre, ...cur.children]), []), it => it.column === itemColValue).text,
|
|
|
|
|
|
xAxis: _.reduce(itemValues, (pre, cur) => ([...pre, _.find(columns, item => item.column === cur).text]), []),
|
|
|
|
|
|
data: _.map(dataSource, item => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
name: item.dimension,
|
|
|
|
|
|
data: _.map(itemValues, child => {
|
|
|
|
|
|
const key = child + itemColValue.slice(_.indexOf(itemColValue, "_"));
|
2023-05-15 09:09:19 +08:00
|
|
|
|
return item[key] || "0";
|
2023-05-12 16:38:07 +08:00
|
|
|
|
})
|
|
|
|
|
|
};
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-05-15 09:09:19 +08:00
|
|
|
|
});
|
2023-05-12 16:38:07 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "line":
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
chartsInfo: {
|
|
|
|
|
|
xAxis: _.map(dataSource, it => it.dimension),
|
|
|
|
|
|
data: _.map(itemValues, item => {
|
|
|
|
|
|
return {
|
2023-05-15 09:09:19 +08:00
|
|
|
|
name: `${_.find(_.reduce(_.filter(columns, col => !_.isNil(col.children)), (pre, cur) => ([...pre, ...cur.children]), []), it => it.column === itemColValue).text}(${_.find(columns, it => it.column === item).text})`,
|
2023-05-12 16:38:07 +08:00
|
|
|
|
data: _.map(dataSource, child => {
|
|
|
|
|
|
const key = item + itemColValue.slice(_.indexOf(itemColValue, "_"));
|
2023-05-15 09:09:19 +08:00
|
|
|
|
return child[key] || "0";
|
|
|
|
|
|
})
|
|
|
|
|
|
};
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "pie":
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
chartsInfo: {
|
|
|
|
|
|
data: _.map(itemValues, item => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
name: _.find(_.reduce(_.filter(columns, col => !_.isNil(col.children)), (pre, cur) => ([...pre, ...cur.children]), []), it => it.column === itemColValue).text,
|
|
|
|
|
|
data: _.map(dataSource, child => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
name: child["dimension"],
|
|
|
|
|
|
value: child[itemColValue]
|
|
|
|
|
|
};
|
2023-05-12 16:38:07 +08:00
|
|
|
|
})
|
|
|
|
|
|
};
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-05-15 09:09:19 +08:00
|
|
|
|
});
|
2023-05-12 16:38:07 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-05-12 16:51:30 +08:00
|
|
|
|
if (this.refs.chart) this.refs.chart.paint();
|
2023-05-12 16:38:07 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.setState({ chartsInfo: {} });
|
|
|
|
|
|
}
|
2023-05-12 10:18:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(() => this.setState({ loading: false }));
|
|
|
|
|
|
};
|
|
|
|
|
|
handleChangeChartOpts = (chartsType, viewType) => {
|
2023-05-15 18:21:23 +08:00
|
|
|
|
this.setState({ chartsInfo: {} });
|
2023-05-12 16:51:30 +08:00
|
|
|
|
if (this.refs.chart && viewType !== "setting" && viewType !== "dataView" && !this.state.rangSet.visible) this.refs.chart.clear();
|
2023-05-12 10:18:39 +08:00
|
|
|
|
const { report: { id: reportId, dimensionId } } = this.props;
|
|
|
|
|
|
const { rangSet } = this.state;
|
|
|
|
|
|
viewType !== "setting" && this.setState({ chartsType, viewType }, () => {
|
|
|
|
|
|
const { viewType, chartsType } = this.state;
|
|
|
|
|
|
viewType !== "dataView" ?
|
2023-05-12 16:51:30 +08:00
|
|
|
|
this.queryRangeSetting({ reportId, chartsType }, true) :
|
2023-05-12 10:18:39 +08:00
|
|
|
|
this.reportStatisticsReportGetData(reportId, dimensionId);
|
|
|
|
|
|
});
|
2023-05-12 16:38:07 +08:00
|
|
|
|
viewType === "setting" && this.setState({ rangSet: { ...rangSet, visible: true, reportId } }, () => {
|
2023-05-12 10:18:39 +08:00
|
|
|
|
this.queryRangeSetting({ reportId, chartsType });
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
handleCancel = () => {
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
rangSet: {
|
|
|
|
|
|
visible: false, reportId: "",
|
2023-05-12 16:38:07 +08:00
|
|
|
|
rangeVal: {}
|
2023-05-12 10:18:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2023-05-12 16:38:07 +08:00
|
|
|
|
handleGetData = () => {
|
|
|
|
|
|
const { report } = this.props;
|
|
|
|
|
|
const { id, dimensionId } = report;
|
|
|
|
|
|
this.setState({ viewType: "dataView" }, () => this.reportStatisticsReportGetData(id, dimensionId));
|
|
|
|
|
|
};
|
|
|
|
|
|
renderCharts = () => {
|
|
|
|
|
|
const { chartsInfo, viewType } = this.state;
|
2023-05-15 09:09:19 +08:00
|
|
|
|
return _.isEmpty(chartsInfo) ?
|
|
|
|
|
|
<ChartEmptyComp/> : (viewType === "bar" || viewType === "line" || viewType === "pie") ?
|
|
|
|
|
|
<WeaEchart
|
|
|
|
|
|
ref="chart" useDefault={false} className="chart"
|
|
|
|
|
|
option={viewType === "bar" ? mapBarOptions(chartsInfo) : viewType === "line" ? mapLineOptions(chartsInfo) : mapPieOptions(chartsInfo)}
|
|
|
|
|
|
/> :
|
|
|
|
|
|
<div>123</div>;
|
2023-05-12 16:38:07 +08:00
|
|
|
|
};
|
2023-04-23 11:28:18 +08:00
|
|
|
|
|
|
|
|
|
|
render() {
|
2023-06-08 11:24:05 +08:00
|
|
|
|
const { loading, viewType, rangSet, columns, povitView } = this.state;
|
2023-04-23 11:28:18 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="layoutContent">
|
|
|
|
|
|
<div className="layoutBox">
|
|
|
|
|
|
<Spin spinning={loading}>
|
2023-05-12 10:18:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
viewType === "dataView" ?
|
|
|
|
|
|
<iframe
|
|
|
|
|
|
style={{ border: 0, width: "100%", height: "100%" }}
|
|
|
|
|
|
// src="http://localhost:7607/#/reportTable"
|
|
|
|
|
|
src="/spa/hrmSalary/hrmSalaryCalculateDetail/index.html#/reportTable"
|
|
|
|
|
|
id="atdTable"
|
2023-05-12 16:38:07 +08:00
|
|
|
|
/> : this.renderCharts()
|
2023-05-12 10:18:39 +08:00
|
|
|
|
}
|
2023-04-23 11:28:18 +08:00
|
|
|
|
</Spin>
|
|
|
|
|
|
</div>
|
2023-04-24 18:30:47 +08:00
|
|
|
|
{/*侧边栏*/}
|
2023-05-12 10:18:39 +08:00
|
|
|
|
<RightOptions onChange={this.handleChangeChartOpts}/>
|
|
|
|
|
|
{/* 图表范围数据设置框 */}
|
|
|
|
|
|
<ChartsRangeSettingsModal
|
|
|
|
|
|
{...rangSet}
|
|
|
|
|
|
columns={columns}
|
|
|
|
|
|
onCancel={this.handleCancel}
|
|
|
|
|
|
onChange={this.queryRangeSetting}
|
2023-05-12 16:38:07 +08:00
|
|
|
|
onGetData={this.handleGetData}
|
2023-05-12 10:18:39 +08:00
|
|
|
|
/>
|
2023-06-08 11:24:05 +08:00
|
|
|
|
{/* 数据透视弹框*/}
|
|
|
|
|
|
<PovitpivotChartModal
|
|
|
|
|
|
{...povitView}
|
|
|
|
|
|
onCancel={() => this.setState({
|
|
|
|
|
|
povitView: {
|
|
|
|
|
|
visible: false, id: "", dimensionId: "", dimensionValue: ""
|
|
|
|
|
|
}
|
|
|
|
|
|
})}
|
|
|
|
|
|
/>
|
2023-04-23 11:28:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ReportContent;
|
2023-05-12 10:18:39 +08:00
|
|
|
|
|
|
|
|
|
|
const ChartEmptyComp = () => {
|
|
|
|
|
|
return <div className="chartsEmptyWrapper">
|
|
|
|
|
|
<span>
|
|
|
|
|
|
<img src={require("../../../common/Icon-empty-file.svg")} alt=""/>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span>暂无数据</span>
|
|
|
|
|
|
<span>您还没有设置报表统计项,请先设置一下哦~</span>
|
|
|
|
|
|
</div>;
|
|
|
|
|
|
};
|