"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _vtxFormLayout = _interopRequireDefault(require("@vtx/components/lib/vtx-form-layout"));
var _vtxColorPicker = _interopRequireDefault(require("@vtx/components/lib/vtx-color-picker"));
var _MinusCircleFilled = _interopRequireDefault(require("@ant-design/icons/lib/icons/MinusCircleFilled"));
var _PlusCircleOutlined = _interopRequireDefault(require("@ant-design/icons/lib/icons/PlusCircleOutlined"));
var _col = _interopRequireDefault(require("antd/lib/col"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _form = _interopRequireDefault(require("antd/lib/form"));
var _input = _interopRequireDefault(require("antd/lib/input"));
var _row = _interopRequireDefault(require("antd/lib/row"));
var _select = _interopRequireDefault(require("antd/lib/select"));
var _antd = require("antd");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
var opList = [{
  name: '等于',
  id: 'EQ'
}, {
  name: '大于',
  id: 'GT'
}, {
  name: '大于等于',
  id: 'GE'
}, {
  name: '小于',
  id: 'LT'
}, {
  name: '小于等于',
  id: 'LE'
}, {
  name: '介于',
  id: 'BETWEEN'
}];
var checkIntersection = function checkIntersection(_ref) {
  var op = _ref.op,
    expression = _ref.expression,
    expression1 = _ref.expression1,
    rules = _ref.rules,
    index = _ref.index;
  return rules.every(function (rule, i) {
    if (i !== index) {
      var flag = true;
      var ruleExpression = Number(rule.expression[0]);
      var ruleExpression1 = Number(rule.expression[1]);
      if (op === 'EQ') {
        flag = !(rule.op === 'EQ' && ruleExpression === expression);
      } else if (['GT', 'GE'].includes(op)) {
        if (['GT', 'GE'].includes(rule.op)) {
          flag = false;
        } else if (rule.op === 'LT') {
          flag = ruleExpression <= expression;
        } else if (rule.op === 'LE') {
          flag = ruleExpression < expression;
        } else if (rule.op === 'BETWEEN') {
          flag = op === 'GE' ? ruleExpression1 < expression : ruleExpression1 <= expression;
        }
      } else if (['LT', 'LE'].includes(op)) {
        if (['LT', 'LE'].includes(rule.op)) {
          flag = false;
        } else if (rule.op === 'GT') {
          flag = ruleExpression >= expression;
        } else if (rule.op === 'GE') {
          flag = ruleExpression > expression;
        } else if (rule.op === 'BETWEEN') {
          flag = op === 'LE' ? ruleExpression < expression : ruleExpression <= expression;
        }
      } else if (op === 'BETWEEN') {
        if (['LT', 'LE'].includes(rule.op)) {
          flag = rule.op === 'LE' ? ruleExpression < expression : ruleExpression <= expression;
        } else if (['GT', 'GE'].includes(op)) {
          flag = rule.op === 'GE' ? ruleExpression < expression1 : ruleExpression <= expression1;
        }
      }
      return flag;
    }
    return true;
  });
};
var Fillingdegree = function Fillingdegree() {
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", null, "\u5145\u6EA2\u5EA6\u7B49\u7EA7\uFF1A"), /*#__PURE__*/_react["default"].createElement(_form["default"].List, {
    name: "rules"
  }, function (fields, _ref2) {
    var add = _ref2.add,
      remove = _ref2.remove;
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, fields.map(function (field, index) {
      return /*#__PURE__*/_react["default"].createElement(_row["default"], {
        key: index
      }, /*#__PURE__*/_react["default"].createElement(_col["default"], {
        span: 22
      }, /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"], {
        cols: 2
      }, /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
        name: [field.name, 'name'],
        label: "\u5145\u6EA2\u5EA6\u7B49\u7EA7\u540D\u79F0",
        rules: [{
          required: true,
          message: '请填写'
        }, function (_ref3) {
          var getFieldValue = _ref3.getFieldValue;
          return {
            validator: function validator(_, value) {
              var rules = getFieldValue('rules');
              if (!value || rules.every(function (rule, i) {
                if (i !== index) {
                  return rule.name !== value;
                }
                return true;
              })) {
                return Promise.resolve();
              }
              return Promise.reject(new Error('充溢度等级名称不可重复'));
            }
          };
        }]
      }, /*#__PURE__*/_react["default"].createElement(_input["default"], {
        style: {
          width: '100%'
        }
      })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
        name: [field.name, 'level'],
        label: "\u5145\u6EA2\u5EA6\u7B49\u7EA7",
        rules: [{
          required: true,
          message: '请填写'
        }, function (_ref4) {
          var getFieldValue = _ref4.getFieldValue;
          return {
            validator: function validator(_, value) {
              var rules = getFieldValue('rules');
              if (!value || rules.every(function (rule, i) {
                if (i !== index) {
                  return rule.level !== value;
                }
                return true;
              })) {
                return Promise.resolve();
              }
              return Promise.reject(new Error('充溢度等级不可重复'));
            }
          };
        }]
      }, /*#__PURE__*/_react["default"].createElement(_antd.InputNumber, {
        style: {
          width: '100%'
        },
        min: 0,
        precision: 0
      })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
        label: "\u5145\u6EA2\u5EA6\u7B49\u7EA7\u9608\u503C",
        required: true,
        name: field.name
      }, /*#__PURE__*/_react["default"].createElement(_input["default"].Group, {
        compact: true
      }, /*#__PURE__*/_react["default"].createElement(_form["default"].Item, {
        name: [field.name, 'op'],
        noStyle: true,
        rules: [{
          required: true,
          message: '请填写'
        }, function (_ref5) {
          var getFieldValue = _ref5.getFieldValue;
          return {
            validator: function validator(_, value) {
              var _rules$index, _rules$index2;
              var rules = getFieldValue('rules');
              if (!value || checkIntersection({
                rules: rules,
                index: index,
                op: value,
                expression: Number((_rules$index = rules[index]) === null || _rules$index === void 0 || (_rules$index = _rules$index.expression) === null || _rules$index === void 0 ? void 0 : _rules$index[0]),
                expression1: Number((_rules$index2 = rules[index]) === null || _rules$index2 === void 0 || (_rules$index2 = _rules$index2.expression) === null || _rules$index2 === void 0 ? void 0 : _rules$index2[1])
              })) {
                return Promise.resolve();
              }
              return Promise.reject(new Error('充溢度等级阈值存在交集'));
            }
          };
        }]
      }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
        style: {
          width: '33%'
        }
      }, opList.map(function (item) {
        return /*#__PURE__*/_react["default"].createElement(_select["default"].Option, {
          value: item.id,
          key: item.id
        }, item.name);
      }))), /*#__PURE__*/_react["default"].createElement(_form["default"].Item, {
        noStyle: true,
        shouldUpdate: function shouldUpdate(prevValues, curValues) {
          var _prevValues$rules, _curValues$rules;
          return (prevValues === null || prevValues === void 0 || (_prevValues$rules = prevValues.rules) === null || _prevValues$rules === void 0 || (_prevValues$rules = _prevValues$rules[field.name]) === null || _prevValues$rules === void 0 ? void 0 : _prevValues$rules.op) !== (curValues === null || curValues === void 0 || (_curValues$rules = curValues.rules) === null || _curValues$rules === void 0 || (_curValues$rules = _curValues$rules[field.name]) === null || _curValues$rules === void 0 ? void 0 : _curValues$rules.op);
        }
      }, function (_ref6) {
        var getFieldValue = _ref6.getFieldValue;
        var op = getFieldValue(['rules', field.name, 'op']);
        var isBETWEEN = op === 'BETWEEN';
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_form["default"].Item, {
          name: [field.name, 'expression', 0],
          noStyle: true,
          rules: [{
            required: true,
            message: '请填写'
          }]
        }, /*#__PURE__*/_react["default"].createElement(_antd.InputNumber, {
          addonAfter: "%",
          placeholder: "\u8BF7\u8F93\u5165",
          style: {
            width: isBETWEEN ? '29%' : '67%'
          }
        })), isBETWEEN && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
          style: {
            margin: '4px 4px 0'
          }
        }, "\u81F3"), /*#__PURE__*/_react["default"].createElement(_form["default"].Item, {
          name: [field.name, 'expression', 1],
          noStyle: true,
          rules: [{
            required: true,
            message: '请填写'
          }]
        }, /*#__PURE__*/_react["default"].createElement(_antd.InputNumber, {
          addonAfter: "%",
          placeholder: "\u8BF7\u8F93\u5165",
          style: {
            width: '29%'
          }
        }))));
      }))), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, _extends({}, field, {
        label: '颜色',
        name: [field.name, 'color'],
        required: true,
        rules: [{
          required: true,
          message: '请填写'
        }]
      }), /*#__PURE__*/_react["default"].createElement(_vtxColorPicker["default"], null)))), /*#__PURE__*/_react["default"].createElement(_col["default"], {
        span: 1
      }, /*#__PURE__*/_react["default"].createElement(_MinusCircleFilled["default"], {
        style: {
          fontSize: 20,
          color: '#1890ff'
        },
        onClick: function onClick() {
          if (fields.length > 3) {
            remove(field.name);
          } else {
            _message["default"].error('最少有三个因子');
            return;
          }
        }
      })), /*#__PURE__*/_react["default"].createElement(_col["default"], {
        span: 1
      }, /*#__PURE__*/_react["default"].createElement(_PlusCircleOutlined["default"], {
        style: {
          fontSize: 20,
          color: '#1890ff'
        },
        onClick: function onClick() {
          add();
        }
      })));
    }));
  }), /*#__PURE__*/_react["default"].createElement("div", null, "\u5904\u7406\u63AA\u65BD\u914D\u7F6E"), /*#__PURE__*/_react["default"].createElement(_form["default"].List, {
    name: "rules"
  }, function (fields) {
    return /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"], {
      cols: 1
    }, fields.map(function (field, index) {
      return /*#__PURE__*/_react["default"].createElement(_form["default"].Item, {
        key: index,
        noStyle: true,
        shouldUpdate: function shouldUpdate(prevValues, curValues) {
          var _prevValues$rules2, _curValues$rules2;
          return (prevValues === null || prevValues === void 0 || (_prevValues$rules2 = prevValues.rules) === null || _prevValues$rules2 === void 0 || (_prevValues$rules2 = _prevValues$rules2[field.name]) === null || _prevValues$rules2 === void 0 ? void 0 : _prevValues$rules2.name) !== (curValues === null || curValues === void 0 || (_curValues$rules2 = curValues.rules) === null || _curValues$rules2 === void 0 || (_curValues$rules2 = _curValues$rules2[field.name]) === null || _curValues$rules2 === void 0 ? void 0 : _curValues$rules2.name);
        }
      }, function (_ref7) {
        var getFieldValue = _ref7.getFieldValue;
        var name = getFieldValue(['rules', field.name, 'name']);
        return /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
          name: [field.name, 'handleMeasure'],
          label: name + '处理措施',
          key: index,
          rules: [{
            required: true,
            message: '请填写'
          }]
        }, /*#__PURE__*/_react["default"].createElement(_input["default"].TextArea, {
          showCount: true,
          maxLength: 100
        }));
      });
    }));
  }), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"], {
    cols: 1
  }, /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    name: "alarmLevel",
    label: "\u62A5\u8B66\u7B49\u7EA7",
    rules: [{
      required: true,
      message: '请填写报警等级'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_input["default"], null))));
};
var _default = exports["default"] = Fillingdegree;
//# sourceMappingURL=Fillingdegree.js.map
