"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _amosFramework = require("amos-framework"), _LibHeader = _interopRequireDefault(require("./LibHeader")), _LibList = _interopRequireDefault(require("./LibList")), _CreateLibForm = _interopRequireDefault(require("./CreateLibForm")), _RuleTree = _interopRequireDefault(require("./tree/RuleTree")), _ruleDesignService = require("./../../../services/ruleDesignService");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var i = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var a in e) if ("default" !== a && Object.prototype.hasOwnProperty.call(e, a)) {
    var l = n ? Object.getOwnPropertyDescriptor(e, a) : null;
    l && (l.get || l.set) ? Object.defineProperty(i, a, l) : i[a] = e[a];
  }
  return i.default = e, r && r.set(e, i), i;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, i = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(i, arguments, n);
    } else r = i.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

var RuleManageView = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var i;
    return (0, _classCallCheck2.default)(this, r), i = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(i), "onCreateObj", (function() {
      i.toggleEditOrCreate(!1), i.setState({
        visible: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onSetting", (function(e) {
      i.toggleEditOrCreate(!0), i.setState({
        visible: !0,
        editObj: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onRemove", (function(e) {
      "2" === e.status || e.isUser ? _amosFramework.Modal.confirm({
        title: "操作提示",
        content: "此规则正在应用，确定要删除吗？",
        onOk: function() {
          i.deleteRuleLib(e);
        }
      }) : i.deleteRuleLib(e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onToggleUse", (function(e, t) {
      (0, _ruleDesignService.startUseSubObjectAction)(e.id).then((function(e) {
        i.props.reload();
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onTogglePublish", (function(e, t) {
      e.status = !1 === t ? "1" : "2", (0, _ruleDesignService.updateSubObjectAction)(e).then((function(e) {
        i.props.reload();
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onStartUseAllSwitchChange", (function(e) {
      var t = i.props.ruleLib;
      t && t.length > 0 ? (0, _ruleDesignService.startUseObjectAction)(e).then((function(e) {
        i.props.reload();
      })) : _amosFramework.message.danger("没有可操作的数据");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onSave", (function(e, t) {
      var r = i.state.orgCode;
      (0, _extends2.default)(e, {
        orgCode: r
      }), i.isEditRulelib ? (0, _ruleDesignService.updateSubObjectAction)(e).then((function(e) {
        i.props.reload(), i.onCancel();
      }), (function(e) {
        _amosFramework.message.danger(e || "编辑失败");
      })) : (0, _ruleDesignService.addSubObjectAction)(e).then((function(e) {
        i.props.reload(), i.onCancel();
      }), (function(e) {
        _amosFramework.message.danger(e || "添加失败");
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "onCancel", (function() {
      i.setState({
        visible: !1,
        editObj: {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "setCurrentSubviewId", (function(e) {
      i.setState({
        orgCode: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "deleteRuleLib", (function(e) {
      (0, _ruleDesignService.removeSubObjectAction)(e.id).then((function(e) {
        i.props.reload();
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "toggleEditOrCreate", (function() {
      var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
      i.isEditRulelib = e;
    })), i.state = {
      visible: !1,
      editObj: {},
      orgCode: 1
    }, i.isEditRulelib = !1, i;
  }
  return (0, _createClass2.default)(r, [ {
    key: "render",
    value: function() {
      var e = this.state, t = e.visible, r = e.editObj, i = this.props, n = i.ruleLib, a = i.onPushToRule, l = i.onSearchRuleLib, u = n && n.filter((function(e) {
        return e.isUser;
      })).length === n.length && 0 !== n.length, o = "新增规则", s = {
        onSave: this.onSave,
        onCancel: this.onCancel
      };
      return this.isEditRulelib && (s.libObj = r, o = r.name), _react.default.createElement("div", {
        className: "rule-manage-root"
      }, _react.default.createElement(_LibHeader.default, {
        title: "规则库管理",
        startUseAllSwitchChange: this.onStartUseAllSwitchChange,
        checked: u,
        onSearch: l
      }), _react.default.createElement(_RuleTree.default, (0, _extends2.default)({
        setCurrentSubviewId: this.setCurrentSubviewId
      }, this.props)), _react.default.createElement(_LibList.default, {
        ruleLibList: n,
        toggleUse: this.onToggleUse,
        togglePublish: this.onTogglePublish,
        onDoubleClick: a,
        onCreateObj: this.onCreateObj,
        onRemove: this.onRemove,
        onSetting: this.onSetting
      }), _react.default.createElement(_amosFramework.Modal, {
        header: o,
        width: 400,
        visible: t,
        className: "rule-lib-modal",
        onCancel: this.onCancel,
        noDefaultFooter: !0,
        destroyContent: !0,
        content: _react.default.createElement(_CreateLibForm.default, (0, _extends2.default)({
          cancelAction: this.onCancel
        }, s))
      }));
    }
  } ]), r;
}(_react.Component);

(0, _defineProperty2.default)(RuleManageView, "propTypes", {
  onPushToRule: _propTypes.default.func.isRequired,
  ruleLib: _propTypes.default.array,
  reload: _propTypes.default.func,
  onSearchRuleLib: _propTypes.default.func
}), (0, _defineProperty2.default)(RuleManageView, "defaultPrps", {
  ruleLib: [],
  reload: function() {}
}), RuleManageView.displayName = "RuleManageView";

var _default = RuleManageView;

exports.default = _default;