ProcessInfo.js 16.4 KB
/* eslint-disable array-callback-return,no-undef */
import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Layout, Tabs, Spin, Avatar } from 'antd-v4';
import styles from '../../index.less';
import Toolbar from '../Common/ToolBar/ToolBarNew';
import * as commonFunc from '../Common/commonFunc';
import CommonBase from '../Common/CommonBase';
import CommonElementEvent from '../Common/CommonElementEvent';
import StaticEditTable from '../Common/CommonTable';/* 可编辑表格 */
import CommonView from '../Common/CommonView';
import * as commonBusiness from '../Common/commonBusiness';/* 单据业务功能 */
import * as commonUtils from '../../utils/utils';/* 通用方法 */

const { Header, Content } = Layout;
const { TabPane } = Tabs;

class ProcessInfoComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
    this.form = {}; /*   表单对象   */
  }
  onTabChange = (key) => {
    this.props.onSaveState({ activeKey: key });
  };
  handleAddRow = (name, sType) => {
    const tableData = JSON.parse(JSON.stringify(this.props[`${name}Data`] || []));
    const tableDataRow = { ...this.props.onDataRowAdd(name, true), sType };
    tableData.push(tableDataRow);
    this.props.onSaveState({
      [`${name}Data`]: tableData,
    });
  }
  render() {
    const { pageLoading } = this.props;
    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <ProcessComponent
              {...this.props}
              {...this.state}
              handleAddRow={this.handleAddRow}
              onTabChange={this.onTabChange}
            />
          </div>
        </Spin>
      </div>
    );
  }
}
const ProcessComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData, masterConfig } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form, masterConfig);
    return obj;
  },
})((props) => {
  const {
    form, onReturnForm, masterData, AutoTableHeight, app, assortConfig, outsideConfig, processstyleConfig,
  } = props;
  /*   回带表单   */
  onReturnForm(form);
  if (commonUtils.isNotEmptyObject(masterData)) {
    masterData.bCheck = true;
  }
  // let tabMachine = commonFunc.showMessage(app.commonConst, 'tabMachine');/* 对应机台 */
  let tabAssort = commonFunc.showMessage(app.commonConst, 'tabAssort');/* 配套工序 */
  let tabOutside = commonFunc.showMessage(app.commonConst, 'tabOutside');/* 發外公式 */
  let tabProcessstyle = commonFunc.showMessage(app.commonConst, 'tabProcesstyle');/* 工序规格 */
  // let tabProcessApsRule = commonFunc.showMessage(app.commonConst, 'tabProcessApsRule');/* APS规则定义 */
  // const tabDynamicParam = commonFunc.showMessage(app.commonConst, 'tabDynamicParam'); /* 动态参数 */
  let tabOrderParam = commonFunc.showMessage(app.commonConst, 'tabOrderParam'); /* 工单参数 */
  let tabOfferParam = commonFunc.showMessage(app.commonConst, 'tabOfferParam'); /* 报价参数 */
  let tabReportParam = commonFunc.showMessage(app.commonConst, 'tabReportParam'); /* 上报参数 */

  const bMachine = false; /* 对应机台 */
  // if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
  //   const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabMachine'); /* 对应机台 */
  //   if (iIndexProcess > -1) {
  //     bMachine = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
  //     tabMachine = props.masterConfig.gdsconfigformslave[iIndexProcess].sChinese;
  //   }
  // }
  let bAssort = commonUtils.isNotEmptyObject(assortConfig); /* 配套工序 */

  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabAssort'); /* 配套工序 */
    if (iIndexProcess > -1) {
      bAssort = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
      tabAssort = props.masterConfig.gdsconfigformslave[iIndexProcess].showName;
    }
  }
  let bOutside = commonUtils.isNotEmptyObject(outsideConfig); /* 發外公式 */
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabOutSide'); /* 發外公式 */
    if (iIndexProcess > -1) {
      bOutside = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
      tabOutside = props.masterConfig.gdsconfigformslave[iIndexProcess].showName;
    }
  }
  let bProcessstyle = commonUtils.isNotEmptyObject(processstyleConfig); /* 工序规格 */

  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabProcessStyle'); /* 工序规格 */
    if (iIndexProcess > -1) {
      bProcessstyle = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
      tabProcessstyle = props.masterConfig.gdsconfigformslave[iIndexProcess].showName;
    }
  }
  const bProcesssApsRule = false; /* APS规则定义 */

  // if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
  //   const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabAPS'); /* APS规则定义 */
  //   if (iIndexProcess > -1) {
  //     bProcesssApsRule = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
  //     tabProcessApsRule = props.masterConfig.gdsconfigformslave[iIndexProcess].sChinese;
  //   }
  // }
  let bOrderParam = true; /* 工单参数 */

  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabProcessParam'); /* 工单参数 */
    if (iIndexProcess > -1) {
      bOrderParam = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
      tabOrderParam = props.masterConfig.gdsconfigformslave[iIndexProcess].showName;
    }
  }
  let bOfferParam = true; /* 报价参数 */

  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabQuoParam'); /* 报价参数 */
    if (iIndexProcess > -1) {
      bOfferParam = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
      tabOfferParam = props.masterConfig.gdsconfigformslave[iIndexProcess].showName;
    }
  }

  let bReportParam = true; /* 上报参数 */

  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabReportParam');
    if (iIndexProcess > -1) {
      bReportParam = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
      tabReportParam = props.masterConfig.gdsconfigformslave[iIndexProcess].showName;
    }
  }

  let bNormParam = true; /* 标准书参数 */
  let tabNormParam = '标准书参数';
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabNormParam');
    if (iIndex > -1) {
      bNormParam = props.masterConfig.gdsconfigformslave[iIndex].bVisible;
      tabNormParam = props.masterConfig.gdsconfigformslave[iIndex].showName;
    }
  }

  let bTestParam = false; /* 测试参数 */
  let tabTestParam = '测试参数';
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tabTestParam');
    if (iIndex > -1) {
      bTestParam = props.masterConfig.gdsconfigformslave[iIndex].bVisible;
      tabTestParam = props.masterConfig.gdsconfigformslave[iIndex].showName;
    }
  }
  let defalutKey = '3';
  if (bMachine) {
    defalutKey = '2';
  } else if (bAssort) {
    defalutKey = '3';
  } else if (bAssort) {
    defalutKey = '3';
  } else if (bOutside) {
    defalutKey = '4';
  } else if (bProcessstyle) {
    defalutKey = '5';
  } else if (bProcesssApsRule) {
    defalutKey = '6';
  } else if (bReportParam) {
    defalutKey = '7';
  } else if (bOfferParam) {
    defalutKey = '8';
  }


  return (
    <Form>
      <Layout id="eleprocess">
        <Header className={styles.header}>
          <Toolbar {...props} />
        </Header>
        <Layout className={`${styles.clayout} ${styles.setHeight}`}>
          <Content className={styles.content}>
            <div className="bill-search-group">
              <CommonView {...props} />
            </div>
            <div id="slaveTabs" className={`${styles.bShow} ${styles.slaveTabHight}`} >
              <div>
                <Avatar src={props.imgSrc} />
              </div>
              <Tabs
                onChange={props.onTabChange}
                activeKey={props.activeKey === undefined ? defalutKey : props.activeKey}
                tabBarStyle={{ margin: '0 10px' }}
                className={`${styles.slaveTabs} basicInfo`}
              >
                {
                  bMachine ?
                    <TabPane tab={tabMachine} key={2} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable {...commonBusiness.getTableTypes('machine', props)} setOpterationColumn="Y" footer="hidden" />
                      </div>
                    </TabPane> : ''
                }
                {
                  bAssort ?
                    <TabPane tab={tabAssort} key={3} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable {...commonBusiness.getTableTypes('assort', props)} setOpterationColumn="Y" footer="hidden" />
                      </div>
                    </TabPane> : ''
                }
                {
                  bOutside ?
                    <TabPane tab={tabOutside} key={4} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable {...commonBusiness.getTableTypes('outside', props)} setOpterationColumn="Y" footer="hidden" />
                      </div>
                    </TabPane> : ''
                }
                {
                  bProcessstyle ?
                    <TabPane tab={tabProcessstyle} key={5} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable {...commonBusiness.getTableTypes('processstyle', props)} setOpterationColumn="Y" footer="hidden" />
                      </div>
                    </TabPane> : ''
                }
                {
                  bProcesssApsRule ?
                    <TabPane tab={tabProcessApsRule} key={6} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable {...commonBusiness.getTableTypes('processApsRule', props)} setOpterationColumn="Y" footer="hidden" />
                      </div>
                    </TabPane> : ''
                }
                {
                  bReportParam ?
                    <TabPane tab={tabReportParam} key={7} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable
                          {...commonBusiness.getTableTypes('dynamicParam', props)}
                          data={
                            commonBusiness.getTableTypes('dynamicParam', props).data ?
                              commonBusiness.getTableTypes('dynamicParam', props).data.filter(o => o.sType === '1') : []
                          }
                          onAddRow={e => props.handleAddRow(e, '1')}
                          setOpterationColumn="Y"
                          footer="hidden"
                        />
                      </div>
                    </TabPane> : ''
                }
                {
                  bOfferParam ?
                    <TabPane tab={tabOfferParam} key={8} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable
                          {...commonBusiness.getTableTypes('dynamicParam', props)}
                          data={
                            commonBusiness.getTableTypes('dynamicParam', props).data ?
                              commonBusiness.getTableTypes('dynamicParam', props).data.filter(o => o.sType === '2') : []
                          }
                          onAddRow={e => props.handleAddRow(e, '2')}
                          setOpterationColumn="Y"
                          footer="hidden"
                        />
                      </div>
                    </TabPane> : ''
                }
                {
                  bOrderParam ?
                    <TabPane tab={tabOrderParam} key={9} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable
                          {...commonBusiness.getTableTypes('dynamicParam', props)}
                          data={
                            commonBusiness.getTableTypes('dynamicParam', props).data ?
                              commonBusiness.getTableTypes('dynamicParam', props).data.filter(o => o.sType === '3') : []
                          }
                          onAddRow={e => props.handleAddRow(e, '3')}
                          setOpterationColumn="Y"
                          footer="hidden"
                        />
                      </div>
                    </TabPane> : ''
                }
                {
                  bNormParam ?
                    <TabPane tab={tabNormParam} key={10} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable
                          {...commonBusiness.getTableTypes('dynamicParam', props)}
                          data={
                            commonBusiness.getTableTypes('dynamicParam', props).data ?
                              commonBusiness.getTableTypes('dynamicParam', props).data.filter(o => o.sType === '4') : []
                          }
                          onAddRow={e => props.handleAddRow(e, '4')}
                          setOpterationColumn="Y"
                          footer="hidden"
                        />
                      </div>
                    </TabPane> : ''
                }
                {
                  bTestParam ?
                    <TabPane tab={tabTestParam} key={11} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 105px)` }}>
                      <div className="TabPaneStyle">
                        <StaticEditTable
                          {...commonBusiness.getTableTypes('dynamicParam', props)}
                          data={
                            commonBusiness.getTableTypes('dynamicParam', props).data ?
                              commonBusiness.getTableTypes('dynamicParam', props).data.filter(o => o.sType === '5') : []
                          }
                          onAddRow={e => props.handleAddRow(e, '5')}
                          setOpterationColumn="Y"
                          footer="hidden"
                        />
                      </div>
                    </TabPane> : ''
                }
              </Tabs>
            </div>
          </Content>
        </Layout>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonElementEvent(ProcessInfoComponent));