CommobileViewSlave.js 3.39 KB
/**
 * Created by mar105 on 2019-02-27.
 */
/* eslint-disable object-curly-newline,prefer-destructuring */
import React, { Component } from 'react';
import { List } from 'antd-mobile';
import ShowType from './CommobileComponent';
import * as commonUtils from '../../utils/utils';
import styles from '../mobile.less'; /* 通用方法 */

export default class CommobileView extends Component {
  // shouldComponentUpdate(nextProps) {
  //   const { slaveData, enabled } = this.props;
  //   return JSON.stringify(slaveData) !== JSON.stringify(nextProps.slaveData) || enabled !== nextProps.enabled;
  // }

  render() {
    const { slaveConfig, slaveData, sModelsId, enabled, sUseInfo, app, iTag } = this.props;
    const slaveDataRow = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
    let masterShowConfig;
    if (iTag === 1) {
      masterShowConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag === 1) : [];
    } else {
      masterShowConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '' && item.iTag !== 1) : [];
    }

    const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
    return (
      <div className={iTag === 1 ? styles.onlyWordBg : ''}>
        {
          // eslint-disable-next-line array-callback-return
          masterShowConfig.map((child, index) => {
            const sMemo = child.sName.toLowerCase().endsWith('memo');
            // sUseInfo是指被其他单据调用,或者被审核
            let enabledNew = (enabled && !child.bReadonly && !child.specialControl && commonUtils.isEmpty(sUseInfo));
            if (child.iTag === 1) {
              enabledNew = false;
            } else if (child.iTag === 3) {
              enabledNew = true;
            }
            const showTypeProps = {
              app,
              record: slaveDataRow,
              sId: slaveDataRow.sId, /*   修改当前编号(数据格式:字符串)   */
              name: 'slave',
              form: this.props.form,
              formId: sModelsId,
              getSqlDropDownData: this.props.getSqlDropDownData,
              getSqlCondition: this.props.getSqlCondition,
              handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
              getFloatNum: this.props.getFloatNum,
              getDateFormat: this.props.getDateFormat,
              onChange: this.props.onDataChange,
              showConfig: child,
              formItemLayout: sMemo ? formItemLayout : {},
              textArea: sMemo,
              enabled: enabledNew,
              dataValue: slaveDataRow[child.sName],
              bTable: false,
              onFilterDropDownData: this.props.onFilterDropDownData,
              onSaveState: this.props.onSaveState,
            };
            if (child.iTag === 1) {
              if (index > 9) {
                return (
                  <div className={styles.onlyWordBg}>
                    <div style={{ padding: '0 0 5px 15px', fontSize: '17px' }}>{child.showName} : {showTypeProps.dataValue}</div>
                  </div>
                );
              }
            } else {
              return (
                <List>
                  <ShowType {...showTypeProps} />
                </List>
              );
            }
          })
        }
      </div>
    );
  }
}