commonOeeReport.js 14.1 KB
/* eslint-disable */
import { routerRedux } from 'dva/router';
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 oeeStyle from './oee.less';
import OeeSearchComponent from './oeeSearchComponent';
import * as commonBusiness from '../../components/Common/commonBusiness';
import * as commonFunc from '../../components/Common/commonFunc';
import * as commonUtils from '../../utils/utils';
// import * as commonConfig from '../../utils/config';
import '../../index.less';
import CommonBase from '../../components/Common/CommonBase';
import CommonListEvent from '../../components/Common/CommonListEvent';
import AntdDraggableModal from '../../components/Common/AntdDraggableModal';
import CommonListSelect from '../../components/Common/CommonListSelect';
import AffixOeeMenu from './AffixOeeMenu';

const { Content } = Layout;
class CommonOeeReport extends Component {
  constructor(props) {
    super(props);
    this.state = {
      bool: true,
    };
  }
  componentWillMount() {
    if(this.props && this.props.app) {
      const { app } = this.props;
      const { token } = app;
      commonBusiness.clearSocketData({ token, value: { optName: '' }, sModelsId: 100 });
      commonUtils.clearStoreDropDownData();
    }
  }

  componentWillReceiveProps(nextProps) {
    const { oeeBtnStatus } = nextProps;
    if (oeeBtnStatus !== undefined) { /* 此作用是 按钮点击后置灰色,调用接口返回数据后 按钮状态回到初始可点击状态 */
      this.setState({ bool: oeeBtnStatus });
    }
  }

  shouldComponentUpdate(nextProps) {
    const { slaveColumn } = nextProps;
    return commonUtils.isNotEmptyArr(slaveColumn);
  }
  componentDidUpdate() {
    // 设置table中的ant-table-body的高度,使滚动条至底
    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`;
  }
  // ----------------------------数据修改回带end  ---------------------------- //
  handleEject = () => {
    const { currentPane, panes } = this.props.app;
    if (commonUtils.isNotEmptyArr(panes) && commonUtils.isNotEmptyObject(currentPane)) {
      // const index = panes.indexOf(currentPane);
      const index = panes.findIndex(item => item.formId === currentPane.formId && item.key === currentPane.key && item.notCurrentPane === currentPane.notCurrentPane && item.route === currentPane.route && item.title === currentPane.title && item.sModelsType === currentPane.sModelsType && item.sProcName === currentPane.sProcName);
      /* 当前页签 */
      let currentTab = document.getElementById('navTabWrap').children[index];
      if (commonUtils.isEmpty(currentTab)) {
        const oChildren = document.getElementById('navTabWrap').getElementsByClassName('ant-tabs-content')[0].children;
        for (const child of oChildren) {
          if (child.nodeName === 'DIV' && index !== undefined && child.getAttribute('id') === `navTabWrap-panel-${panes[index].key}`) {
            currentTab = child;
          }
        }
      }
      // const currentTab = document.getElementById('tabs').getElementsByClassName('ant-tabs-content-no-animated')[0].children[index];
      if (!commonUtils.isEmpty(currentTab)) {
        const filterTreeArr = currentTab.getElementsByClassName('xly-filter-tree');/* 获取当前页签下的树组件 */
        if (commonUtils.isNotEmptyArr(filterTreeArr)) {
          const filterTree = filterTreeArr[0];
          if (filterTree.style.display === 'block') {
            filterTree.style.display = 'none';
          } else {
            filterTree.style.display = 'block';
          }
        }
      }
    }
  };
  /**   树节点选中   */
  handleTreeSelect = (name, checkedKeys, e) => {
    this.props.onSelect(name, checkedKeys, e); /* 调用CommonListEvent通用处理 */
  };
  handleBtnClick = async (btnConfig) => {
    const { app, slaveSelectedRowKeys, slaveSelectedData, slaveData } = this.props;
    if (btnConfig.sControlName === 'BtnCopyTo.productionReport') {
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
        message.warn('请选择数据!');
        return;
      } else if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
        if (slaveSelectedData[0].sState === '3') {
          message.warn('该任务已暂停,不能开工!');
          return;
        }
        /* 若设置了禁止跳单 选择数据不是第一条时进行提示 */
        const iIndex = app.systemData.findIndex(item => item.sName === 'CkxNoSkip');
        if (iIndex > -1) {
          const sValue = app.systemData[iIndex].sValue;
          if ( sValue === "1" ) { /* 如果设置了进制跳单 */
            const indexFirst = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId) || slaveSelectedRowKeys.includes(item.sSlaveId));
            if (indexFirst > 0) {
              message.warn('禁止跳单!');
              return;
            }
          }

        }
      }
      if (this.state.bool) {
        this.setState({
          bool: false,
        });
        // this.props.onOeeCopyTo(btnConfig.sControlName, btnConfig.sActiveId);
        await this.props.onOeeCopyTo(btnConfig.sControlName, btnConfig.sActiveId);
        this.setState({
          bool: true,
        });
      } else {
        message.warning(commonFunc.showMessage(app.commonConst, 'donotRepeat'));
        return;
      }
      // setTimeout(() => { // 防止多次点击
      //   this.setState({
      //     bool: true,
      //   });
      // }, 1000);
    } 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 (btnConfig.sControlName === 'BtnEnterLabel') { // 标签打印
      const { slaveSelectedRowKeys, getSlaveSelectedRowKeys } = this.props;
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
        message.warn('请选择数据!');
        return;
      }
      const { slaveData, onSaveCurrentState } = this.props;
      onSaveCurrentState(slaveData, undefined, undefined, slaveSelectedRowKeys);
      this.props.onOeeLabelCopyTo(btnConfig.sControlName, btnConfig.sActiveId);
      this.props.dispatch(routerRedux.push('/indexOee/labelPrint'));
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { // 向父组件中存slaveSelectedRowKeys
        getSlaveSelectedRowKeys(slaveSelectedRowKeys);
      }
    } else if (btnConfig.sControlName.includes('OeeCopyTo')) { /* OEE单据 */
      const { slaveSelectedRowKeys, getSlaveSelectedRowKeys } = this.props;
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
        message.warn('请选择数据!');
        return;
      }
      const { slaveData, onSaveCurrentState } = this.props;
      onSaveCurrentState(slaveData, undefined, undefined, btnConfig, undefined, true);
      this.props.onOeeBillCopyTo(btnConfig.sControlName, btnConfig.sActiveId, btnConfig);
      // this.props.dispatch(routerRedux.push('/indexOee/commonBillOee'));
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { // 向父组件中存slaveSelectedRowKeys
        getSlaveSelectedRowKeys(slaveSelectedRowKeys);
      }
    } else if (btnConfig.sControlName === 'BtnDetailProcess') { // 详细进度
      const { slaveSelectedRowKeys, slaveData } = this.props;
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys) && commonUtils.isNotEmptyArr(slaveData)) {
        const iIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
        if (iIndex > -1) {
          const slaveDataRow = slaveData[iIndex];
          this.props.onPartNameClick('BtnDetailProcess', btnConfig, slaveDataRow);
        }
      } else {
        message.error('请选择数据!');
      }
    } else if (commonUtils.isNotEmptyObject(btnConfig.sControlName) && btnConfig.sControlName.indexOf('BtnConvert') > -1) { /* 自定义按钮 */
      this.setState({
        bool: false,
      });
      this.props.onOeeBtnEent(btnConfig);
    }
  }
  render() {
    return (
      <CommonOeeReportComponent
        {...this.props}
        {...this.state}
        onEject={this.handleEject}
        onSelectTree={this.handleTreeSelect}
        // handleColsePage={this.handleColsePage}
        // onstartWork={this.handleonStartWork}
        onBtnClick={this.handleBtnClick}
      />
    );
  }
}

const CommonOeeReportComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const {
    form,
    onReturnForm,
    slavePagination,
    slaveConfig,
    isSmall,
    onBtnClick,
    sModelsId,
  } = props;
  // isSmall将分页变小,以及去掉跳转页面和总条数记录
  /*   回带表单   */
  if (commonUtils.isNotEmptyObject(slavePagination)) {
    if (isSmall) {
      slavePagination.showTotal = null;
    }
  }

  onReturnForm(form);
  // const pagination = {
  // pageSize: commonConfig.pageSize,
  // ...slavePagination,
  // size: isSmall ? 'small' : 'large',
  // pageSizeOptions: commonConfig.pageSizeOptions,
  // showSizeChanger: !isSmall,
  // showQuickJumper: !isSmall,
  // };
  const pagination = false;
  const tableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: { rowKey: 'sSlaveId', pagination, onChange: props.onTitleChange },
    onSaveState: props.onSaveState,
    clearArray: props.clearArray,
    readOnly: true,
    isSmall,
    sGroupByList: props.sGroupByList,
  };
  let searchWorkSchedule = {};
  let workScheduleConfig = {};
  let searchWorkTitle = '';
  if (commonUtils.isNotEmptyObject(props.workScheduleConfig)) {
    // eslint-disable-next-line prefer-destructuring
    workScheduleConfig = props.workScheduleConfig;
    searchWorkTitle = workScheduleConfig.sActiveName;
    const sWorkOrderId = commonUtils.isNotEmptyObject(props.workScheduleRecord) ? props.workScheduleRecord.sWorkOrderId : '';
    searchWorkSchedule = {
      app: {
        ...props.app,
        currentPane: {
          name: 'workSchedule',
          config: workScheduleConfig,
          conditonValues: props.getSqlCondition(workScheduleConfig),
          title: workScheduleConfig.sActiveName,
          route: '/indexPage/commonList',
          formRoute: '/indexPage/commonList',
          formId: workScheduleConfig.sActiveId,
          key: sModelsId + workScheduleConfig.sId,
          sModelsType: 'search/workSchedule',
          bFilterProName: 'p_sWorkOrderId_pro',
          bFilterProValue: sWorkOrderId,
          // select: props.onSelect,
          // selectCancel: props.onSelectCancel,
        },
      },
      dispatch: props.dispatch,
      content: props.content,
      id: new Date().getTime().toString(),
      realizeHeight: props.realizeHeight, /* 拖动偏移高度 */
      bNotShowBtn: true,
    };
  }
  const bCanClick = props.bool; /* 按钮是否可点击,true:可点击,false:禁用 */
  // 取得配置中的按钮
  const buttonConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave.filter(item => item.sName === '' && item.showName !== '' && item.sControlName !== '' && item.bVisible && item.sControlName.indexOf('Btn') > -1) : [];
  return (
    <div>
      <Form style={{ height: '100%' }}>
        <Layout style={{ height: '100%' }} className="xly-list">
          <Layout className="table">
            <Content className="xly-normal-list" >
              <StaticEditTable {...tableProps} footer="hidden" tableBelone="list" />
            </Content>
          </Layout>
          <div className={oeeStyle.bottomBtns}>
            <div className={oeeStyle.btnBrints}>
              {
                commonUtils.isNotEmptyArr(buttonConfig) ?
                  buttonConfig.map((item, index) => {
                    if (item.sControlName === 'BtnSet') {
                      return (
                        // eslint-disable-next-line jsx-a11y/anchor-is-valid,react/no-array-index-key
                        <a key={index} className="oeeAffixBtnContainer" disabled={!bCanClick} style={{ background: bCanClick ? `${item.sColorTerms}` : '#ABAAAB', position: 'relative' }} onClick={() => (bCanClick ? onBtnClick(item) : null)}>
                          {item.showName}<AffixOeeMenu{...props}/>
                        </a>
                      );
                    } else {
                      return (
                        // eslint-disable-next-line jsx-a11y/anchor-is-valid,react/no-array-index-key
                        <a key={index} disabled={!bCanClick} style={{ background: bCanClick ? `${item.sColorTerms}` : '#ABAAAB' }} onClick={() => (bCanClick ? onBtnClick(item) : null)}>
                          {item.showName}
                        </a>
                      );
                    }
                  }) : ''
              }
            </div>
            <div className={oeeStyle.searchComponent}>
              <OeeSearchComponent {...props} />
            </div>
          </div>
          {

              props.workScheduleVisible ?
                <AntdDraggableModal
                  className="workScheduleModal"
                  width={1300}
                  title={commonUtils.isEmptyObject(searchWorkSchedule) ? searchWorkTitle : searchWorkSchedule.app.currentPane.title}
                  visible={props.workScheduleVisible}
                  onCancel={props.onCloseModel.bind(this, 'workScheduleVisible')}
                  onSaveState={props.onSaveState}
                  footer={null}
                >
                  <CommonListSelect {...searchWorkSchedule} />
                </AntdDraggableModal> : null

          }

        </Layout>
      </Form>
    </div>

  );
});

export default CommonBase(CommonListEvent(CommonOeeReport));