import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Row, Col } from 'antd-v4';
import ShowType from '@/components/Common/CommonComponent';
import styles from '@/index.less';
import * as commonUtils from '@/utils/utils';

const FormItem = Form.Item;

class TabSalesBuyerComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

  /* 判断字段是否存在 存在显示，不存在返回空 */
  getExistShowConfig = (sName) => {
    let bShow = false;
    const { masterConfig, masterData } = this.props;
    if (commonUtils.isNotEmptyObject(masterConfig) && commonUtils.isNotEmptyObject(masterData)) {
      /*   配置信息   */
      const showConfig = this.getShowConfig(sName);
      /*   返回值   */
      if (commonUtils.isNotEmptyObject(showConfig) && showConfig.bVisible) {
        bShow = true;
      }
    }
    return bShow;
  };

  /* 判断字段是否存在并且勾了显示  */
  getExistVisibleShowConfig = (sName) => {
    let bShow = false;
    const { masterConfig, masterData } = this.props;
    if (commonUtils.isNotEmptyObject(masterConfig) && commonUtils.isNotEmptyObject(masterData)) {
      /*   配置信息   */
      const showConfig = this.getShowConfig(sName);
      /*   返回值   */
      if (commonUtils.isNotEmptyObject(showConfig) && showConfig.bVisible) {
        bShow = true;
      }
    }
    return bShow;
  };

  getShowTypeProps = (sName) => {
    const { masterConfig, masterData } = this.props;
    if (commonUtils.isNotEmptyObject(masterConfig) && commonUtils.isNotEmptyObject(masterData)) {
      /*   配置信息   */
      const showConfig = this.getShowConfig(sName);
      /*   返回值   */
      if (commonUtils.isNotEmptyObject(showConfig)) {
        return {
          form: this.props.form,
          getSqlDropDownData: this.props.getSqlDropDownData,
          getSqlCondition: this.props.getSqlCondition,
          handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
          getFloatNum: this.props.getFloatNum,
          onChange: this.props.onChange, /*   表单数据改变事件方法(数据格式:函数)   */
          showConfig, /*   关于本showType相关配置(数据格式:对象)   */
          enabled: this.props.enabled && !showConfig.bReadonly, /*   是否是查看状态(数据格式:布尔)   */
          dataValue: masterData[sName], /*   本showType数据(数据格式:对象)   */
          bTable: false, /*   是否为表格数据   */
          formItemLayout: { labelCol: { span: 14 }, wrapperCol: { span: 10 } },
        };
      }
    }
  };
  /**   获取showConfig   */
  getShowConfig = (sName) => {
    /*   通过sName过滤出对应的showConfig   */
    const showConfigArr = this.props.masterConfig.gdsconfigformslave.filter(item => item.sControlName === sName); //  && item.bVisible
    if (commonUtils.isNotEmptyArr(showConfigArr)) {
      showConfigArr[0].sName = showConfigArr[0].sControlName;
      return showConfigArr[0];
    }
    /*   返回值   */
    return {};
  };
  render() {
    const { masterConfig, masterData } = this.props;
    return (
      <FormItem className={styles.searchSlaveForm}>
        {commonUtils.isEmptyObject(masterConfig) || commonUtils.isEmptyObject(masterData) ? '' :
        <Row type="flex" justify="space-between">
          <Col span={11}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{this.props.masterConfig.gdsconfigformslave.filter(item => (item.sControlName.toLowerCase() === 'tabsalescontrol'))[0].showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  { this.getExistVisibleShowConfig('sCbxDeliverGoods') ? <ShowType {...this.getShowTypeProps('sCbxDeliverGoods')} /> : ''}
                  {this.getExistVisibleShowConfig('sCbxSrcNoCheck') ? <ShowType {...this.getShowTypeProps('sCbxSrcNoCheck')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDeliverGoodsNotify') ? <ShowType {...this.getShowTypeProps('sCbxDeliverGoodsNotify')} /> : ''}
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistVisibleShowConfig('bCkxLookCustomer') ? <ShowType {...this.getShowTypeProps('bCkxLookCustomer')} /> : ''}
                  {this.getExistShowConfig('bCkxLookPerson') ? <ShowType {...this.getShowTypeProps('bCkxLookPerson')} /> : ''}
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={11}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{this.props.masterConfig.gdsconfigformslave.filter(item => (item.sControlName.toLowerCase() === 'tabcommonsetting'))[0].showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistShowConfig('bCkxLookSupply') ? <ShowType {...this.getShowTypeProps('bCkxLookSupply')} /> : ''}
                  {this.getExistShowConfig('bCkxDefineCheck') ? <ShowType {...this.getShowTypeProps('bCkxDefineCheck')} /> : ''}
                  {this.getExistShowConfig('bCkxTmpCheck') ? <ShowType {...this.getShowTypeProps('bCkxTmpCheck')} /> : ''}
                  {this.getExistShowConfig('bCkxModifyBillNoMakePerson') ? <ShowType {...this.getShowTypeProps('bCkxModifyBillNoMakePerson')} /> : ''}
                  {this.getExistShowConfig('bCkxNoSkip') ? <ShowType {...this.getShowTypeProps('bCkxNoSkip')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistShowConfig('bCkxOeeNoConnectPlan') ? <ShowType {...this.getShowTypeProps('bCkxOeeNoConnectPlan')} /> : ''}
                  {/* <ShowType {...this.getShowTypeProps('bCbxOutputReport')} /> 送货或入库后不能上报 */}
                  {this.getExistShowConfig('bCkxMaterialsStockLimit') ? <ShowType {...this.getShowTypeProps('bCkxMaterialsStockLimit')} /> : ''}
                  {this.getExistShowConfig('bCkxProductStockLimit') ? <ShowType {...this.getShowTypeProps('bCkxProductStockLimit')} /> : ''}
                  {this.getExistShowConfig('bCkxOEEToTask') ? <ShowType {...this.getShowTypeProps('bCkxOEEToTask')} /> : ''}
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={11}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{this.props.masterConfig.gdsconfigformslave.filter(item => (item.sControlName.toLowerCase() === 'tabschedule'))[0].showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType {...this.getShowTypeProps('sCbxProductionReport')} />
                  {this.getExistVisibleShowConfig('sCbxDstributionWage') ? <ShowType {...this.getShowTypeProps('sCbxDstributionWage')} /> : ''}
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistShowConfig('bCkxProcessFilter') ? <ShowType {...this.getShowTypeProps('bCkxProcessFilter')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistShowConfig('bCkxXd') ? <ShowType {...this.getShowTypeProps('bCkxXd')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistShowConfig('bCkxNotProduction') ? <ShowType {...this.getShowTypeProps('bCkxNotProduction')} /> : ''}
                  {this.getExistVisibleShowConfig('bCkxOrderStart') ? <ShowType {...this.getShowTypeProps('bCkxOrderStart')} /> : ''}
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={11}>
            <div className={styles.tabChild}>
              <div className={styles.tabChildTitle}>
                <span>{this.props.masterConfig.gdsconfigformslave.filter(item => (item.sControlName.toLowerCase() === 'tabproductmanage'))[0].showName}</span>
              </div>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistShowConfig('sCbxMakeupName') ? <ShowType {...this.getShowTypeProps('sCbxMakeupName')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistShowConfig('sCbxCutName') ? <ShowType {...this.getShowTypeProps('sCbxCutName')} /> : ''}
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistShowConfig('sCbxPublishName') ? <ShowType {...this.getShowTypeProps('sCbxPublishName')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistShowConfig('bCkxIntoPlanNewWod') ? <ShowType {...this.getShowTypeProps('bCkxIntoPlanNewWod')} /> : ''}
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistShowConfig('bCkxCopyFromTechnology') ? <ShowType {...this.getShowTypeProps('bCkxCopyFromTechnology')} /> : ''}
                </Col>
              </Row>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistShowConfig('bCkxWodCheckIntoPlan') ? <ShowType {...this.getShowTypeProps('bCkxWodCheckIntoPlan')} /> : ''}
                </Col>
              </Row>
            </div>
          </Col>
        </Row>
        }
      </FormItem>
    );
  }
}

export default TabSalesBuyerComponent;

