"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _grid = _interopRequireDefault(require("@alifd/next/lib/grid"));
var _form = _interopRequireDefault(require("@alifd/next/lib/form"));
var _react = _interopRequireDefault(require("react"));
require("./index.scss");
var _variables = require("../../variables");
var _events = _interopRequireDefault(require("../../utils/events"));
var _typeData = require("../../type/type-data");
var FormItem = _form["default"].Item;
var Row = _grid["default"].Row,
  Col = _grid["default"].Col;
//这是过滤器
var CommonFilter = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(CommonFilter, _React$Component);
  function CommonFilter(_props) {
    var _this;
    _this = _React$Component.call(this, _props) || this;
    _this.submit = function (v, e) {
      if (e) return;
      var _this$props = _this.props,
        fieldList = _this$props.fieldList,
        children = _this$props.children;
      var commonVOs = [];
      var _loop = function _loop(i) {
        if (v[i] !== undefined) {
          var field = fieldList.filter(function (item) {
            return item.fieldName === i;
          })[0];
          var child = children.filter(function (item) {
            return item.key === field.id;
          })[0];
          var props = child.props;
          var comparison = props.comparison;
          if (!comparison) {
            comparison = props.bizType == 'text' ? 'like' : '=';
          }
          commonVOs.push({
            key: i,
            oper: comparison,
            value1: v[i]
          });
        }
      };
      for (var i in v) {
        _loop(i);
      }
      _events["default"].emit('onFilter', commonVOs);
    };
    _this.reset = function () {
      _events["default"].emit('onFilter', []);
    };
    _this.renderChildren_ = function () {
      var _this$props2 = _this.props,
        children = _this$props2.children,
        span = _this$props2.span,
        __designMode = _this$props2.__designMode;
      return _react["default"].Children.map(children, function (child) {
        var props = child.props;
        var componentType = props.componentType,
          comparison = props.comparison,
          bizType = props.bizType,
          isHide = props.isHide;
        var newComponentType = componentType;
        var newComparison = comparison;
        if (!componentType) {
          var list = _typeData.componentTypeList.filter(function (item) {
            return item.tplType.includes(bizType);
          });
          newComponentType = list.length ? list[0].value : 'Input';
        }
        if (!comparison) {
          newComparison = bizType == 'text' ? 'like' : '=';
        }
        if (isHide && __designMode !== 'design') {
          return null;
        }
        return /*#__PURE__*/_react["default"].createElement(Col, {
          span: span
        }, /*#__PURE__*/_react["default"].cloneElement(child, {
          componentType: newComponentType,
          comparison: newComparison
        }));
      });
    };
    return _this;
  }
  var _proto = CommonFilter.prototype;
  _proto.render = function render() {
    var _this2 = this;
    var style = this.props.style;
    return /*#__PURE__*/_react["default"].createElement(_form["default"], {
      className: _variables.bizCssPrefix + '-common-filter',
      style: style
    }, /*#__PURE__*/_react["default"].createElement(Row, {
      align: "stretch",
      wrap: true
    }, this.renderChildren_()), /*#__PURE__*/_react["default"].createElement(Row, {
      align: "center"
    }, /*#__PURE__*/_react["default"].createElement(Col, {
      style: {
        textAlign: 'right'
      }
    }, /*#__PURE__*/_react["default"].createElement(FormItem, {
      wrapperCol: {
        offset: 12
      }
    }, /*#__PURE__*/_react["default"].createElement(_form["default"].Reset, {
      onClick: function onClick() {
        _this2.reset();
      },
      style: {
        marginRight: 10
      }
    }, "\u6E05\u7A7A"), /*#__PURE__*/_react["default"].createElement(_form["default"].Submit, {
      validate: true,
      type: "primary",
      onClick: function onClick(v, e) {
        return _this2.submit(v, e);
      },
      style: {
        marginRight: 10
      }
    }, "\u641C\u7D22")))));
  };
  return CommonFilter;
}(_react["default"].Component);
CommonFilter.displayName = 'CommonFilter';
var _default = CommonFilter;
exports["default"] = _default;