'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _desc, _value, _class, _class2, _temp; /**
                                            * Created by baoyinghai on 11/10/16.
                                            */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _coreDecorators = require('core-decorators');

var _reactRouterRedux = require('react-router-redux');

var _index = require('./displayComp/index');

var _index2 = _interopRequireDefault(_index);

var _fetch = require('../../system/fetch');

var _DispatchService = require('../../service/DispatchService');

var _routes = require('../../entrance/routes');

var _MapUtils = require('../../utils/MapUtils');

var _info = require('../info');

var _switchContainer = require('./switchContainer');

var _switchContainer2 = _interopRequireDefault(_switchContainer);

var _constant = require('./constant');

var _dictCodes = require('../../constant/dictCodes');

var _StringUtils = require('../../utils/StringUtils');

var _EmptyUtils = require('../../utils/EmptyUtils');

var _mxa = require('../../../components/mxa');

var _components = require('../../../components');

var _util = require('../list/util');

var _reviseModal = require('../reviseModal');

var _reviseModal2 = _interopRequireDefault(_reviseModal);

var _JSExecutor = require('../../utils/JSExecutor');

var _ModalInputUtils = require('../../utils/ModalInputUtils');

var _EventUtils = require('../../utils/EventUtils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

var FormItem = _mxa.Form.Item;

var Detail = (_class = (_temp = _class2 = function (_React$Component) {
  _inherits(Detail, _React$Component);

  /* eslint-disable */
  function Detail(props) {
    _classCallCheck(this, Detail);

    var _this = _possibleConstructorReturn(this, (Detail.__proto__ || Object.getPrototypeOf(Detail)).call(this, props));

    var dataSource = _this.props.dataSource;

    var data = _this.dataFieldsAdapter(dataSource);
    var modalInputSetting = _this.checkModalInputData(dataSource);
    var detailResult = _this.dealDataSource(dataSource.detailResult);
    _this.dealReadonly();
    _this.dealDefaultValue(dataSource, detailResult);
    _this.state = {
      dataSource: dataSource,
      passwordDirty: false,
      fields: data,
      detailResult: detailResult,
      isLeadInto: false,
      modalInputMappings: modalInputSetting.modalInputMappings,
      modalInputIsReadonlys: modalInputSetting.modalInputIsReadonlys
    };
    return _this;
  }

  _createClass(Detail, [{
    key: 'dealReadonly',
    value: function dealReadonly() {
      var _props = this.props,
          dataSource = _props.dataSource,
          query = _props.query,
          readonly = _props.readonly;
      // if (readonly === true || readonly === 'true' || dataSource.readOnly || query.readonly === true || query.readonly === 'true') {

      if (this.dealBoolean([readonly, dataSource.readOnly, query.readonly, query.displayType === 'VIEW'])) {
        this.props.dataSource.fields.map(function (item) {
          item.isReadonly = true;
          if (item.displayComponent.componentType === 'MODALINPUT') {
            item.modalInput.disabled = true;
          }
          return item;
        });
        // TODO 后面要用privilegeType = COMMON 来处理
        this.props.dataSource.buttons = dataSource.buttons.filter(function (item) {
          return item.privilegeType !== 'EDIT';
        });
        return true;
      } else if (this.props.model === 'VIEW') {
        this.props.dataSource.buttons = dataSource.buttons.filter(function (item) {
          return item.privilegeType !== 'EDIT';
        });
      }
      return false;
    }
  }, {
    key: 'dealBoolean',
    value: function dealBoolean(data) {
      if (data instanceof Array) {
        return data.some(function (item) {
          if (item === true || item === 'true') {
            return true;
          }
          return false;
        });
      } else {
        return data === true || data === 'true';
      }
    }
  }, {
    key: 'dealDefaultValue',
    value: function dealDefaultValue(dataSource, detailResult) {
      var _this2 = this;

      if (detailResult) {
        this.props.form.setFieldsValue(detailResult);
      }
      !detailResult && dataSource.fields.forEach(function (item) {
        item.defaultValue && _this2.props.form.setFieldsValue(_defineProperty({}, item.name, item.defaultValue));
      });
    }
  }, {
    key: 'dealDataSource',
    value: function dealDataSource(detailResult) {
      if (Array.isArray(detailResult)) {
        return detailResult[0];
      }
      return detailResult;
    }
  }, {
    key: 'checkModalInputData',
    value: function checkModalInputData(data) {
      var _this3 = this;

      var modalInputMappings = [];
      var modalInputIsReadonlys = [];
      data.fields.map(function (item, index) {
        if (item.modalInput && (0, _ModalInputUtils.getMappings)(item.modalInput, _this3.props)) {
          (0, _ModalInputUtils.getMappings)(item.modalInput, _this3.props).map(function (item1, index1) {
            modalInputMappings.push(item1.fieldName);
            if (item1.readonly) {
              modalInputIsReadonlys.push(item1.fieldName);
            }
          });
        }
      });
      return { modalInputMappings: modalInputMappings, modalInputIsReadonlys: modalInputIsReadonlys };
    }

    // 设置显示 和 必填

  }, {
    key: 'changeDataSourceVisable',
    value: function changeDataSourceVisable() {
      var _this4 = this;

      var fieldSetting = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dataSource = this.props.dataSource;

      var fieldList = dataSource.fields && dataSource.fields.map(function (field) {
        if (fieldSetting[field.name]) {
          var isVisible = fieldSetting[field.name].isVisible;
          if (isVisible === true || isVisible === false) {
            field.isVisible = isVisible;
          }
          if (fieldSetting[field.name].rules) {
            var isRequired = fieldSetting[field.name].rules.isRequired;
            if (isRequired === true || isRequired === false) {
              field.isRequired = isRequired;
            }
          }
          if (fieldSetting[field.name].value !== undefined || fieldSetting[field.name].value !== null) {
            // TODO
            var values = _defineProperty({}, field.name, fieldSetting[field.name].value);
            var detailResult = _this4.dealDataSource(dataSource.detailResult);
            _this4.state.detailResult = _extends({}, detailResult, values);
            if (fieldSetting[field.name + _constant.CONFIRM_SUFFIX]) {
              values[field.name + _constant.CONFIRM_SUFFIX] = fieldSetting[field.name + _constant.CONFIRM_SUFFIX].value;
            }
            _this4.props.form.setFieldsValue(values);
          }
          if (fieldSetting[field.name].dictionaryFilter) {
            field.dictionaryFilter = fieldSetting[field.name].dictionaryFilter;
          } else {
            delete field.dictionaryFilter;
          }

          if (fieldSetting[field.name].actionLink && field.modalInput) {
            field.modalInput.actionLink = fieldSetting[field.name].actionLink;
          }
        }
        return field;
      });
      var data = _extends({}, dataSource, { fields: fieldList });
      this.setState({ fields: this.dataFieldsAdapter(data), dataSource: data });
    }

    // 修改表单默认值

  }, {
    key: 'changeInitValue',
    value: function changeInitValue(value, values) {
      if (!values) {
        var modelInputItem = this.state.fields && this.state.fields[0].filter(function (item, index) {
          return item.displayComponent.componentType === 'MODALINPUT';
        });
        var mappingFields = modelInputItem && modelInputItem[0].modalInput && (0, _ModalInputUtils.getMappings)(modelInputItem[0].modalInput, this.props) || [];
        values = {};
        mappingFields && mappingFields.forEach(function (m) {
          values[m.fieldName] = value && value[m.remoteFieldName];
        });
      }
      var detailResult = this.dealDataSource(this.props.dataSource.detailResult);
      this.state.detailResult = _extends({}, detailResult, values);
      this.state.isLeadInto = !!value;
      this.props.form.setFieldsValue(values);
    }
  }, {
    key: 'injectFormValidate',
    value: function injectFormValidate(dataSource) {
      var _this5 = this;

      if (this.props.inject && this.props.inject.formValidate) {
        return dataSource.fields.map(function (field) {
          if (_this5.props.inject.formValidate[field.name]) {
            field.formValidate = _this5.props.inject.formValidate[field.name];
          }
          return field;
        });
      }
      return dataSource.fields;
    }

    // 注入 过滤 分组

  }, {
    key: 'dataFieldsAdapter',
    value: function dataFieldsAdapter(dataSource) {
      var fieldMap = {};
      this.injectFormValidate(dataSource).forEach(function (f) {
        if (typeof f.groupId === 'string') {
          (function () {
            var groupIdList = f.groupId.split(',');
            var groupNameList = f.groupName.split(',');
            var groupShortNameList = f.groupShortName ? f.groupShortName.split(',') : ['', ''];
            groupIdList.forEach(function (gId, index) {
              if (!fieldMap[gId]) {
                fieldMap[gId] = [];
              }
              fieldMap[gId].push(_extends({}, f, { groupId: gId, groupName: groupNameList[index], groupShortName: groupShortNameList[index] }));
            });
          })();
        } else {
          if (!fieldMap[f.groupId]) {
            fieldMap[f.groupId] = [];
          }
          fieldMap[f.groupId].push(f);
        }
      });
      var ret = [];
      Object.keys(fieldMap).forEach(function (key) {
        ret.push(fieldMap[key]);
      });
      return ret;
    }
  }, {
    key: 'createReqParam',
    value: function createReqParam() {
      var params = {};
      if (this.props && this.props.params) {
        params = this.props.params;
      }
      return _extends({}, params, (0, _MapUtils.getValueByKey)(this.props, {}, 'query'));
    }
  }, {
    key: 'realSubmit',
    value: function realSubmit(func, values) {
      var rest = this.createReqParam();
      var original = this.state.detailResult || {};
      return func && func(_extends({}, original, rest, values));
    }
  }, {
    key: 'handleSubmit',
    value: function handleSubmit(func, isTemporarySave) {
      var _this6 = this;

      var self = this;
      if (isTemporarySave) {
        (function () {
          var requireFields = _this6.state.fields.filter(function (item) {
            return item.isRequire;
          });
          var fieldNames = [];
          requireFields.forEach(function (item) {
            if (_this6.props, form.getFieldValue(item.name)) {
              fieldNames.push(item.name);
            }
          });
          _this6.props.form.validateFieldsAndScroll(fieldNames, { force: true }, function (err, values) {
            return self.validateFieldsCallback(err, values, func);
          });
        })();
      } else {
        this.props.form.validateFieldsAndScroll({ force: true }, function (err, values) {
          return self.validateFieldsCallback(err, values, func);
        });
      }
    }
  }, {
    key: 'validateFieldsCallback',
    value: function validateFieldsCallback(err, values, func) {
      var _this7 = this;

      if (!err) {
        // TODO: deal with checkbox: 'A,B,C'. it's error when not invoke submit
        var fields = this.props.dataSource && this.props.dataSource.fields || [];
        fields.filter(function (field) {
          return field.displayComponent.componentType === 'CHECKBOXGROUP';
        }).map(function (f) {
          if (values[f.name]) {
            values[f.name] = values[f.name].split(',');
          } else {
            values[f.name] = [];
          }
        });
        if (this.props.beforeSubmit) {
          this.props.beforeSubmit(values, this.state.detailResult, function () {
            var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : values;

            _this7.realSubmit(func, v);
          });
        } else {
          this.realSubmit(func, values);
        }
      }
    }
  }, {
    key: 'handlePasswordBlur',
    value: function handlePasswordBlur(e) {
      var value = e.target.value;
      this.setState({ passwordDirty: this.state.passwordDirty || !!value });
    }
  }, {
    key: 'handleChageState',
    value: function handleChageState(e) {
      this.props.changeState(e);
    }
  }, {
    key: '_onSearch',
    value: function _onSearch(params, item) {
      console.log('***--DETAIL REFRESH--***');
      this.props.onRefresh && this.props.onRefresh(params, item);
    }
  }, {
    key: '_renderColumnAction',
    value: function _renderColumnAction(displayPosition) {
      var _this8 = this;

      // TODO: refactor
      var _props2 = this.props,
          prefixCls = _props2.prefixCls,
          query = _props2.query,
          inject = _props2.inject;

      var buttonClass = prefixCls + '-button';
      var buttons = (this.props.dataSource.buttons || []).filter(function (btn) {
        if (displayPosition === _dictCodes.BUTTON_POSITION.TOP || displayPosition === _dictCodes.BUTTON_POSITION.BOTTOM) {
          return (btn && btn.displayPosition) === displayPosition;
        }
        return true;
      });
      buttons = buttons.map(function (item) {
        if (item.isEditButton) {
          return _react2.default.createElement(
            'a',
            { className: buttonClass, onClick: _this8.props.changeState },
            _this8.props.model === _constant.EDIT ? '返回' : '编辑'
          );
        } else {
          var ButtonComp = _components.ExtendButton;
          if (_this8.props.renderButtonsSelf) {
            var myBtn = _this8.props.renderButtonsSelf(item, _this8.props);
            if (myBtn) {
              ButtonComp = myBtn;
            }
          }
          return _react2.default.createElement(ButtonComp, _extends({
            type: 'link',
            inline: false,
            buttonProps: {
              type: 'primary'
            }
          }, item, {
            disabled: false,
            key: item.buttonDescription,
            className: buttonClass,
            query: query,
            inject: inject,
            submitFuc: item.relatedData === _dictCodes.BUTTON_RELATEDDATA.FORM && function (func) {
              return _this8.handleSubmit(func);
            },
            onRefresh: function onRefresh(params) {
              return _this8._onSearch(params, item);
            },
            isModal: _this8.props.isModal,
            modalCallback: _this8.props.modalCallback
          }));
        }
      });
      if (this.props.modalCallback && displayPosition === _dictCodes.BUTTON_POSITION.BOTTOM) {
        buttons = [_react2.default.createElement(
          'a',
          { className: buttonClass + ' cancel-btn', onClick: this.props.modalCallback },
          '\u8FD4\u56DE'
        )].concat(_toConsumableArray(buttons));
      }
      return buttons;
    }
  }, {
    key: 'renderForm',
    value: function renderForm(data, fields, i) {
      var titleF = fields[0];
      if (!titleF || !titleF.groupName) return;
      return _react2.default.createElement(
        _switchContainer2.default,
        { key: titleF.groupName + i, bar: titleF.groupName, index: i },
        this.renderGroupItem(data, fields, i)
      );
    }
  }, {
    key: 'getIsSameWithName',
    value: function getIsSameWithName() {
      return 'ISSAMEWITH';
    }

    // 解析校验 如果是object

  }, {
    key: 'dealWithCheckObject',
    value: function dealWithCheckObject(formValidate, f, ret) {
      var validateType = formValidate.validateType;
      if (validateType === this.getIsSameWithName()) {
        f.formValidate.formItemName = f.name + _constant.CONFIRM_SUFFIX;
        ret.push(f);
        //insert a confirm Text
        var fClone = (0, _EmptyUtils.clone)(f);
        fClone.name = f.name + _constant.CONFIRM_SUFFIX;
        fClone.description = f.description + '确认';
        fClone.formValidate.formItemName = f.name;
        fClone.formValidate.description = f.description;
        ret.push(fClone);
      } else {
        ret.push(f);
      }
    }

    // 解析校验 如果是数组

  }, {
    key: 'dealWithCheckArray',
    value: function dealWithCheckArray(formValidates, f, ret) {
      var _this9 = this;

      var flag = true;
      formValidates.some(function (formValidate, index) {
        var validateType = formValidate.validateType;
        if (validateType === _this9.getIsSameWithName()) {
          f.formValidates[index].formItemName = f.name + _constant.CONFIRM_SUFFIX;
          ret.push(f);
          var fClone = (0, _EmptyUtils.clone)(f);
          fClone.name = f.name + _constant.CONFIRM_SUFFIX;
          fClone.description = f.description + '确认';
          fClone.formValidates = [{
            formItemName: f.name,
            description: f.description,
            validateType: _this9.getIsSameWithName()
          }];
          ret.push(fClone);
          flag = false;
          return true;
        }
        return false;
      });
      flag && ret.push(f);
    }

    // 特殊情况 二次确认需要自己渲染标单项

  }, {
    key: '_processFields',
    value: function _processFields(fields) {
      var _this10 = this;

      fields.map(function (item) {
        item.isVisible = _this10.dealIsVisibleField(item);
        // TODO：要添加addonBefore并处理
        if (item.displayComponent.addOnBefore) {
          item.displayComponent.addOnBefore = _this10.dealAddOnBeforeField(item);
        }
        return item;
      });
      if (this.props.model === _constant.VIEW) {
        return fields;
      }
      if (this.props.model === _constant.EDIT) {
        var _ret3 = function () {
          var ret = [];
          fields.forEach(function (f) {
            var formValidate = f && f.formValidate || f && f.formValidates;
            if ((0, _StringUtils.isArray)(formValidate)) {
              _this10.dealWithCheckArray(formValidate, f, ret);
            } else if (!(0, _EmptyUtils.isEmpty)(formValidate)) {
              _this10.dealWithCheckObject(formValidate, f, ret);
            } else {
              ret.push(f);
            }
          });
          return {
            v: ret
          };
        }();

        if ((typeof _ret3 === 'undefined' ? 'undefined' : _typeof(_ret3)) === "object") return _ret3.v;
      }
    }
  }, {
    key: 'dealAddOnBeforeField',
    value: function dealAddOnBeforeField(record) {
      var addOnBefore = record.displayComponent.addOnBefore;
      if (addOnBefore.indexOf('function') !== -1) {
        return (0, _JSExecutor.createFunc)(addOnBefore)(this.props.form.getFieldsValue());
      }
      return addOnBefore;
    }
  }, {
    key: 'dealIsVisibleField',
    value: function dealIsVisibleField(record) {
      if (record.isVisible === 'true') {
        return true;
      } else if (record.isVisible === 'false') {
        return false;
      } else if (record.isVisible !== true && record.isVisible !== false) {
        return (0, _JSExecutor.createFunc)(record.isVisible)(this.props.form.getFieldsValue());
      } else {
        return record.isVisible;
      }
    }
  }, {
    key: 'renderGroupItem',
    value: function renderGroupItem(data, fields) {
      var _this11 = this;

      var groupIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var getFieldDecorator = this.props.form.getFieldDecorator;

      var isLeadInto = this.state.isLeadInto;
      var changeIsLeadInto = this.changeIsLeadInto;
      var modalInputMappings = this.state.modalInputMappings;
      var modalInputIsReadonlys = this.state.modalInputIsReadonlys;
      return _react2.default.createElement(
        'div',
        { className: 'form-box' },
        _react2.default.createElement(
          _mxa.Row,
          { className: 'cell', type: 'flex', justify: 'start' },
          this._processFields(fields).map(function (item, index) {
            var formItemLayout = {
              labelCol: { span: _this11.props.model === _constant.EDIT ? 22 : 6 },
              wrapperCol: { span: _this11.props.model === _constant.EDIT ? 22 : 16 }
            };
            var span = _this11.props.isModal ? 24 : 12;
            var componentType = (0, _MapUtils.getValueByKey)(item, 'default', 'displayComponent', 'componentType');
            if (span !== 24 && (componentType === 'TEXTAREA' || componentType === 'TRANSFER' || componentType === 'INNERLIST')) {
              span = 23;
              formItemLayout.wrapperCol = 23;
            }
            // const span = 24;
            var isModalInputMappingItem = modalInputMappings && modalInputMappings.findIndex(function (n) {
              return n === item.name;
            }) !== -1;
            var modalInputIsReadonly = modalInputIsReadonlys && modalInputIsReadonlys.findIndex(function (n) {
              return n === item.name;
            }) !== -1;
            return _react2.default.createElement(
              _mxa.Col,
              { key: item.name + groupIndex, span: item.isVisible ? span : 0 },
              (0, _index2.default)(formItemLayout, item, getFieldDecorator, _this11.state.detailResult, _extends({}, _this11.props, { isLeadInto: isLeadInto, isModalInputMappingItem: isModalInputMappingItem, modalInputIsReadonly: modalInputIsReadonly }), _this11.changeDataSourceVisable, _this11.changeInitValue, _this11.props.replaceMain)
            );
          })
        )
      );
    }
  }, {
    key: 'renderBody',
    value: function renderBody() {
      var _this12 = this;

      // const dataSource = JSON.parse(JSON.stringify(this.state.dataSource));
      var dataSource = (0, _EmptyUtils.clone)(this.state.dataSource);
      var fields = this.dataFieldsAdapter(dataSource);
      if (fields && fields.length === 1) {
        return _react2.default.createElement(
          'div',
          { style: { backgroundColor: '#FFFFFF' } },
          this.renderGroupItem(dataSource, fields[0])
        );
      } else {
        return fields.map(function (f, index) {
          return _this12.renderForm(dataSource, f, index);
        });
      }
    }
  }, {
    key: 'createButtons',
    value: function createButtons(position, tailFormItemLayout) {
      var btns = this._renderColumnAction(position);
      if (this.props.isModal && this.props.createModalButtons) {
        this.props.createModalButtons(btns);
      } else if (position === _dictCodes.BUTTON_POSITION.TOP && this.props.createTopButtons) {
        this.props.createTopButtons(btns);
      } else if (btns && btns.length > 0) {
        return _react2.default.createElement(
          FormItem,
          tailFormItemLayout,
          _react2.default.createElement(
            'div',
            { className: 'button-bar' },
            _react2.default.createElement(
              'ul',
              { className: 'button-bar-list' },
              btns && btns.map(function (item, index) {
                return _react2.default.createElement(
                  'li',
                  { key: index },
                  item
                );
              })
            )
          )
        );
      }
      return null;
    }
  }, {
    key: '_renderSummary',
    value: function _renderSummary() {
      // this.state.detailResult
      var values = this.state.detailResult || {};
      var dataSource = this.props.dataSource;

      return dataSource && dataSource.fields && dataSource.fields.filter(function (field) {
        return field.isSummary;
      }).map(function (field) {
        return {
          label: field.description,
          value: (0, _util.renderColumn)(values[field.name], field)
        };
      });
    }
  }, {
    key: 'componentDidMount',
    value: function componentDidMount() {
      (0, _EventUtils.addEventToBlurForm)(window);
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      (0, _EventUtils.removeEventToBlurForm)(window);
    }
  }, {
    key: 'render',
    value: function render() {
      var dataSource = this.props.dataSource;

      var tailFormItemLayout = {
        wrapperCol: {
          span: 22
        }
      };
      if (this.props.renderSummaryHandler) {
        this.props.renderSummaryHandler(this._renderSummary());
      }
      return _react2.default.createElement(
        'div',
        { className: 'detail-container' },
        _react2.default.createElement(
          _mxa.Form,
          { horizontal: true },
          this.createButtons(_dictCodes.BUTTON_POSITION.TOP, tailFormItemLayout),
          this.renderBody(),
          this.createButtons(_dictCodes.BUTTON_POSITION.BOTTOM, tailFormItemLayout)
        ),
        (0, _StringUtils.isArray)(dataSource.detailResult) ? _react2.default.createElement(_reviseModal2.default, { fieldsData: dataSource.fields, dataSource: dataSource.detailResult }) : null
      );
    }
  }]);

  return Detail;
}(_react2.default.Component), _class2.propTypes = {
  inject: _react2.default.PropTypes.object,
  model: _react2.default.PropTypes.oneOf([_constant.VIEW, _constant.EDIT]).isRequired,
  createRules: _react2.default.PropTypes.func, // 自定义表单校验 // record
  beforeSubmit: _react2.default.PropTypes.func, // 表单提交之前 // values, callback(v)
  afterSubmit: _react2.default.PropTypes.func, // 表单提交之后  //  err
  dataSource: _react2.default.PropTypes.object.isRequired,
  renderAnalyser: _react2.default.PropTypes.func, // 自定义渲染标单项 // componentName
  renderButtonsSelf: _react2.default.PropTypes.func // 自定义渲染按钮
}, _class2.defaultProps = {
  prefixCls: 'mx-list'
}, _temp), (_applyDecoratedDescriptor(_class.prototype, 'dealReadonly', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealReadonly'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealBoolean', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealBoolean'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealDefaultValue', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealDefaultValue'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealDataSource', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealDataSource'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeDataSourceVisable', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'changeDataSourceVisable'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeInitValue', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'changeInitValue'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'injectFormValidate', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'injectFormValidate'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dataFieldsAdapter', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dataFieldsAdapter'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'createReqParam', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'createReqParam'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'realSubmit', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'realSubmit'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleSubmit', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'handleSubmit'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'validateFieldsCallback', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'validateFieldsCallback'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handlePasswordBlur', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'handlePasswordBlur'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'handleChageState', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'handleChageState'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_onSearch', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_onSearch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_renderColumnAction', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_renderColumnAction'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_processFields', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_processFields'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealIsVisibleField', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealIsVisibleField'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'renderBody', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'renderBody'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_renderSummary', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_renderSummary'), _class.prototype)), _class);


var detailCreator = function detailCreator() {
  return _mxa.Form.create()(Detail);
};

exports.default = detailCreator;