import {
WeaInput,
WeaEchart,
} from 'ecCom'
import {
Row,
Col,
message,
} from 'antd';
import {
i18n
} from '../../public/i18n';
import React from 'react'
import {
jumpToHrmDept
} from '../../util/pulic-func'
class ReportChart extends React.Component {
constructor(props) {
super(props);
}
componentDidUpdate() {
if (this.refs.echart) this.refs.echart.paint();
if (this.refs.echart1) this.refs.echart1.paint();
}
componentWillReceiveProps(nextProps) {
if (this.props.winWidth !== nextProps.winWidth) {
if (this.refs.echart) this.refs.echart.chart.resize();
if (this.refs.echart1) this.refs.echart1.chart.resize();
}
}
getDOM(interval, key, setGap, getData, isIntervalShow, pathname, tag, isChartsShow, chartTitle) {
return (
{this.getName(key) + ':'}
setGap(val)}
/>
{this.getSuffix(key)}
)
}
getName(key) {
switch (key) {
case '1':
return i18n.label.ageRange();
case '3':
return i18n.label.workingAgeRange();
case '7':
return i18n.label.rankingInterval();
}
}
getSuffix(key) {
switch (key) {
case '7':
return i18n.label.level();
default:
return i18n.label.year();
}
}
getImgSrc(tag, chartTitle) {
let cvs = document.getElementsByTagName('canvas');
if (tag !== 'right') {
this.downloadCvs2Img(cvs[0], chartTitle);
} else {
this.downloadCvs2Img(cvs[1], chartTitle);
}
}
downloadCvs2Img(cvs, chartTitle) {
let $a = document.createElement('a');
$a.download = chartTitle + '.jpg';
$a.target = '_blank';
let url;
if (cvs) {
url = cvs.toDataURL("image/jpg");
} else {
message.info(i18n.message.dataNone());
}
if (url) $a.href = url;
if (typeof MouseEvent === 'function') {
var evt = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: false
});
$a.dispatchEvent(evt);
} else {
if (window.navigator.msSaveOrOpenBlob) {
var bstr = atob(url.split(',')[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
var blob = new Blob([u8arr]);
window.navigator.msSaveOrOpenBlob(blob, chartTitle + '.jpg');
} else {
var html = '' +
'' +
'
' +
'';
var tab = window.open();
tab.document.write(html);
}
}
}
chartAction(chart, ids, yAxisData, linkList) {
chart.off('click');
chart.on('click', (params) => this.handleClick(params, ids, yAxisData, linkList));
}
handleClick(params, ids, yAxisData, linkList) {
const {
pathname
} = this.props;
if (pathname !== 'departmentStatistics') return false;
let anid = params.event.target.anid;
if (!anid) {
return
}
let index = anid.split('_')[1];
jumpToHrmDept(ids[index])
}
render() {
const {
option,
isIntervalShow,
interval,
tabKey,
pathname,
setGap,
getData,
chartTitle,
isChartsShow,
ids,
yAxisData,
linkList,
tagName
} = this.props;
return (
{(pathname == 'basicConditionAnalysis') ? (
{this.getDOM(interval, tabKey, setGap, getData, isIntervalShow, pathname, pathname, isChartsShow[0], tagName)}
{isChartsShow[0] ? (
)
:
{i18n.message.dataNone()}
}
) : ''}
{ (pathname == 'departmentStatistics' || pathname == 'postStatistics') ?
{chartTitle[0]}
{this.getDOM(interval, tabKey, setGap, getData, isIntervalShow, pathname, pathname, isChartsShow[0], chartTitle[0])}
{isChartsShow[0] ? (
this.chartAction(chart, ids, yAxisData, linkList)}/>
)
:
{i18n.message.dataNone()}
}
: ''}
{ (pathname == 'jobStatusStatistics') ?
{chartTitle[0]}
{this.getDOM(interval, tabKey, setGap, getData, isIntervalShow, pathname, 'left', isChartsShow[1], chartTitle[0])}
{isChartsShow[1] ?
:
{i18n.message.dataNone()}
}
{chartTitle[1]}
{this.getDOM(interval, tabKey, setGap, getData, isIntervalShow, pathname, 'right', isChartsShow[2], chartTitle[1])}
{isChartsShow[2] ?
:
{i18n.message.dataNone()}
}
: ''}
)
}
}
export default ReportChart