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

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

  render() {
    const { masterConfig, sModelsId, enabled, sUseInfo, app } = this.props;
    let { masterData } = this.props;
    masterData = masterData === undefined ? {} : masterData;
    const masterShowConfig = commonUtils.isNotEmptyObject(masterConfig) ? masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName !== '') : [];
    const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
    return (
      <List>
        {
          masterShowConfig.map((child) => {
            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: masterData,
              name: 'master',
              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.onChange,
              showConfig: child,
              formItemLayout: sMemo ? formItemLayout : {},
              textArea: sMemo,
              enabled: enabledNew,
              dataValue: masterData[child.sName],
              bTable: false,
              onFilterDropDownData: this.props.onFilterDropDownData,
              onSaveState: this.props.onSaveState,
            };
            return (
              <ShowType {...showTypeProps} />
            );
          })
        }
      </List>
    );
  }
}
