/* eslint-disable */
import React, { Component } from 'react';
import { Layout, message } from 'antd';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import StaticEditTable from '@/components/Common/CommonTable';
import * as commonBusiness from '@/components/Common/commonBusiness';
import * as commonFunc from '@/components/Common/commonFunc';
import * as commonUtils from '@/utils/utils';
import '@/index.less';
import CommonBase from '@/components/Common/CommonBase';
import CommonListEvent from '@/components/Common/CommonListEvent';
import * as commonConfig from '@/utils/config';
import * as commonServices from '@/services/services';
import oeeStyle from './oee.less';
import OeeSearchComponent from './oeeSearchComponent';
import AffixOeeMenu from './AffixOeeMenu';
// import { timeMillisecond } from 'd3-time';
const { Content } = Layout;
class OeeCommonList extends Component {
constructor(props) {
super(props);
this.state = {
};
}
shouldComponentUpdate(nextProps) {
const { slaveColumn } = nextProps;
return commonUtils.isNotEmptyArr(slaveColumn);
}
componentDidUpdate() {
// 设置table中的ant-table-body的高度,使滚动条至底
if (document.getElementsByClassName('xly-normal-list') && commonUtils.isNotEmptyArr(document.getElementsByClassName('table')) &&
document.getElementsByClassName('table')[0].getElementsByClassName('xly-normal-list')) {
const antTable = document.getElementsByClassName('table')[0].getElementsByClassName('xly-normal-list')[0].offsetHeight;
const antTableHeader = document.getElementsByClassName('table')[0].getElementsByClassName('ant-table-header')[0].offsetHeight;
document.getElementsByClassName('table')[0].getElementsByClassName('ant-table-body')[0].style.height = `${antTable - antTableHeader}px`;
}
}
// 存储过程按钮调用存储过程
handleProcedureCall = async (btnConfig, proName, proInParam) => {
const { app, sModelsId } = this.props;
const value = {
sProName: proName,
paramsMap: {
sMachineId: app.sMachineNameSId,
sProInParam: proInParam,
},
};
const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (returnData.code === 1) {
message.success(returnData.msg);
this.props.onButtonClick('BtnRefresh');
} else {
this.props.onSaveState({ loading: false });
this.props.getServiceError(returnData);
}
}
// 根据配置解析拼接具体参数
handleProParams = (sKey, arr) => {
const { [`${sKey}Data`]: tableData, [`${sKey}SelectedRowKeys`]: selectedRowKeys } = this.props;
const keyData = commonUtils.isNotEmptyArr(tableData) ? tableData.filter(item => selectedRowKeys.includes(item.sId) || selectedRowKeys.includes(item.sSlaveId)) : [];
if (commonUtils.isNotEmptyArr(keyData)) {
const addState = {};
addState.key = sKey;
const val = [];
keyData.forEach((currData) => {
const currVal = {};
arr.forEach((filed) => {
currVal[`${filed}`] = currData[`${filed}`];
});
val.push(currVal);
});
addState.value = val;
return addState;
} else {
return undefined;
}
};
// 进行存储过程按钮存储过程参数解析拼接 根据存储过程按钮参数配置进行解析,配置是json格式 {"sproName":"cal_sss","inMap":"master.sSlaveId,slave.sId"}
handleBtnEent = (btnConfig) => {
const { masterData } = this.props;
const { sButtonParam } = btnConfig;
const btn = JSON.parse(sButtonParam);
const sProName = btn.sproName;
const inParams = [];
const { inMap } = btn;
const inlist = inMap.split(',');
const masterArr = [];
const slaveArr = [];
if (inlist.length > 0) {
inlist.forEach((item) => {
const itemArr = item.split('.');
if (itemArr.length > 0) {
const sname = itemArr[0];
const stype = itemArr[1];
if (commonUtils.isNotEmptyStr(sname) && sname === 'master') {
masterArr.push(stype);
}
if (commonUtils.isNotEmptyStr(sname) && sname === 'slave') {
slaveArr.push(stype);
}
}
});
if (commonUtils.isNotEmptyArr(masterArr) && commonUtils.isNotEmptyObject(masterData)) {
const addState = {};
addState.key = 'master';
const val = [];
const currVal = {};
masterArr.forEach((filed) => {
currVal[`${filed}`] = masterData[`${filed}`];
});
val.push(currVal);
addState.value = val;
inParams.push({ ...addState });
}
if (commonUtils.isNotEmptyArr(slaveArr)) {
const addState = this.handleProParams('slave', slaveArr);
if (commonUtils.isNotEmptyObject(addState)) {
inParams.push({ ...addState });
}
}
}
this.handleProcedureCall(btnConfig, sProName, JSON.stringify({ params: inParams }));
};
handleBtnClick = (btnConfig) => {
if (btnConfig.sControlName === 'BtnCopyTo.productionReport') {
this.props.onOeeCopyTo(btnConfig.sControlName, btnConfig.sActiveId);
} else if (btnConfig.sControlName === 'BtnClose') {
// eslint-disable-next-line prefer-destructuring
const userAgent = navigator.userAgent;
if (userAgent.indexOf('Firefox') !== -1 || userAgent.indexOf('Chrome') !== -1) {
window.location.href = 'about:blank';
} else {
window.opener = null;
window.open(' ', '_self', ' ');
window.close();
}
} else if (commonUtils.isNotEmptyObject(btnConfig.sControlName) && btnConfig.sControlName.indexOf('BtnConvert') > -1) {
this.handleBtnEent(btnConfig);
}
}
render() {
return (