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';
import TabSysParamIcon from './TabSysParamsIcon';

const FormItem = Form.Item;

class TabSysParamComponent 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)) {
        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: 12 }, wrapperCol: { span: 12 } },
        };
      }
    }
  };
  /**   获取showConfig   */
  getShowConfig = (sName) => {
    /*   通过sName过滤出对应的showConfig   */
    const showConfigArr = this.props.masterConfig.gdsconfigformslave.filter(item => item.sControlName === sName && item.bVisible);
    const showConfigHideArr = this.props.masterConfig.gdsconfigformslave.filter(item => item.sControlName === sName && !item.bVisible); /* 隐藏字段 */
    if (commonUtils.isNotEmptyArr(showConfigHideArr)) {
      console.log(`请勾选${sName}字段显示!`);
    }
    if (commonUtils.isNotEmptyArr(showConfigArr)) {
      showConfigArr[0].sName = showConfigArr[0].sControlName;
      return showConfigArr[0];
    }
    /*   返回值   */
    return {};
  };


  /* 判断字段是否存在并且勾了显示  */
  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;
  };

  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.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxMaterialsUnit') ? <ShowType {...this.getShowTypeProps('sCbxMaterialsUnit')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCardboardUnit') ? <ShowType {...this.getShowTypeProps('sCbxCardboardUnit')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxMachineUnit') ? <ShowType {...this.getShowTypeProps('sCbxMachineUnit')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('dNetConversionRate') ? <ShowType {...this.getShowTypeProps('dNetConversionRate')} /> : '' }
                </Col>
              </Row>
            </div>
            <div className={styles.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistVisibleShowConfig('dNetMoney') ? <ShowType {...this.getShowTypeProps('dNetMoney')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('dNetPrice') ? <ShowType {...this.getShowTypeProps('dNetPrice')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('iNetSquareM') ? <ShowType {...this.getShowTypeProps('iNetSquareM')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('bCkxPercentile') ? <ShowType {...this.getShowTypeProps('bCkxPercentile')} /> : '' }
                </Col>
              </Row>
            </div>
            <div className={styles.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxLanguage') ? <ShowType {...this.getShowTypeProps('sCbxLanguage')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistShowConfig('iCbxExitSystem') ? <ShowType {...this.getShowTypeProps('iCbxExitSystem')} /> : ''}
                </Col>
              </Row>
            </div>
            <div className={styles.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxNetID') ? <ShowType {...this.getShowTypeProps('sCbxNetID')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxNetVerifyCode') ? <ShowType {...this.getShowTypeProps('sCbxNetVerifyCode')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxHttp') ? <ShowType {...this.getShowTypeProps('sCbxHttp')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxMac') ? <ShowType {...this.getShowTypeProps('sCbxMac')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWechatAppscret') ? <ShowType {...this.getShowTypeProps('sCbxWechatAppscret')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWechatAgentid') ? <ShowType {...this.getShowTypeProps('sCbxWechatAgentid')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWechatAppid') ? <ShowType {...this.getShowTypeProps('sCbxWechatAppid')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWechatIpAddress') ? <ShowType {...this.getShowTypeProps('sCbxWechatIpAddress')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWechatToken') ? <ShowType {...this.getShowTypeProps('sCbxWechatToken')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWechatEncodingAESKey') ? <ShowType {...this.getShowTypeProps('sCbxWechatEncodingAESKey')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxEmailHost') ? <ShowType {...this.getShowTypeProps('sCbxEmailHost')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxEmailFrom') ? <ShowType {...this.getShowTypeProps('sCbxEmailFrom')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxEmailUser') ? <ShowType {...this.getShowTypeProps('sCbxEmailUser')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxEmailPass') ? <ShowType {...this.getShowTypeProps('sCbxEmailPass')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxEmailPort') ? <ShowType {...this.getShowTypeProps('sCbxEmailPort')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDingTalkToken') ? <ShowType {...this.getShowTypeProps('sCbxDingTalkToken')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDingTalkEncodingAESKey') ? <ShowType {...this.getShowTypeProps('sCbxDingTalkEncodingAESKey')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDingTalkAppid') ? <ShowType {...this.getShowTypeProps('sCbxDingTalkAppid')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDingTalkAgentid') ? <ShowType {...this.getShowTypeProps('sCbxDingTalkAgentid')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDingTalkAppscret') ? <ShowType {...this.getShowTypeProps('sCbxDingTalkAppscret')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxApiUrl') ? <ShowType {...this.getShowTypeProps('sCbxApiUrl')} /> : '' }
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxDateTime') ? <ShowType {...this.getShowTypeProps('sCbxDateTime')} /> : '' }
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={11}>
            <div className={styles.tabChild}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  {this.getExistVisibleShowConfig('iNetMonth') ? <ShowType {...this.getShowTypeProps('iNetMonth')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxServerFilePath') ? <ShowType {...this.getShowTypeProps('sCbxServerFilePath')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyName') ? <ShowType {...this.getShowTypeProps('sCbxCompanyName')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyTitle') ? <ShowType {...this.getShowTypeProps('sCbxCompanyTitle')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyAddress') ? <ShowType {...this.getShowTypeProps('sCbxCompanyAddress')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyInoviceAddress') ? <ShowType {...this.getShowTypeProps('sCbxCompanyInoviceAddress')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyPhone1') ? <ShowType {...this.getShowTypeProps('sCbxCompanyPhone1')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyPhone2') ? <ShowType {...this.getShowTypeProps('sCbxCompanyPhone2')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyFax') ? <ShowType {...this.getShowTypeProps('sCbxCompanyFax')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxCompanyEmail') ? <ShowType {...this.getShowTypeProps('sCbxCompanyEmail')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWorkPath') ? <ShowType {...this.getShowTypeProps('sCbxWorkPath')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxWorkCheckPath') ? <ShowType {...this.getShowTypeProps('sCbxWorkCheckPath')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxTime') ? <ShowType {...this.getShowTypeProps('sCbxTime')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('sCbxImpositionTime') ? <ShowType {...this.getShowTypeProps('sCbxImpositionTime')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('bCkxNumAlign') ? <ShowType {...this.getShowTypeProps('bCkxNumAlign')} /> : ''}
                </Col>
                <Col span={11}>
                  {this.getExistVisibleShowConfig('bCkxViewAllMachine') ? <ShowType {...this.getShowTypeProps('bCkxViewAllMachine')} /> : ''}
                </Col>
                <TabSysParamIcon {...this.props} />
              </Row>
            </div>
          </Col>
        </Row>
        }
      </FormItem>
    );
  }
}

export default TabSysParamComponent;
