"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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")), _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")), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _amosTool = require("amos-tool"), _rayValidate = require("ray-validate"), _InterfaceEnum = require("./../common/InterfaceEnum"), _InterfaceLang = require("./../common/InterfaceLang"), _processor = require("../../../utils/processor"), _urlConsts = require("../../../consts/urlConsts"), _validate = require("./../../common/utils/validate");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, a = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? a : 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 a = _getRequireWildcardCache(t);
  if (a && a.has(e)) return a.get(e);
  var r = {}, l = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var n in e) if ("default" !== n && Object.prototype.hasOwnProperty.call(e, n)) {
    var u = l ? Object.getOwnPropertyDescriptor(e, n) : null;
    u && (u.get || u.set) ? Object.defineProperty(r, n, u) : r[n] = e[n];
  }
  return r.default = e, a && a.set(e, r), r;
}

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

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 RadioGroup = _amosAntd.Radio.Group, Option = _amosFramework.Select.Option, FormItem = _amosAntd.Form.Item, dataTypeOption = (0, 
_InterfaceLang.enums2array)(_InterfaceEnum.dataTypeEnum).map((function(e) {
  return _react.default.createElement(Option, {
    key: e.key,
    value: "".concat(e.key)
  }, e.label);
})), classifyOption = (0, _InterfaceLang.enums2array)(_InterfaceEnum.classifyEnum).map((function(e) {
  return _react.default.createElement(_amosAntd.Radio, {
    key: e.key,
    value: "".concat(e.key)
  }, e.label);
})), formItemLayout = {
  labelCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 5
    }
  },
  wrapperCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 16
    }
  }
}, fieldNames = [ "name", "type", "displayName", "dataType", "unit", "descr", "isRequired" ], AddEditInterfaceProperty = function(e) {
  (0, _inherits2.default)(a, e);
  var t = _createSuper(a);
  function a(e) {
    var r;
    return (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(r), "onEnumRangeChange", (function(e) {
      r.setState({
        currentenumRange: e.target.value
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getDynamicCode", (function() {
      var e = r.props.form, t = e.getFieldProps, a = e.getFieldValue, l = r.props.propertyInfo, n = l.valueStr, u = l.enumRange, d = l.minValue, o = l.maxValue, s = l.precision, i = void 0 === r.state.currentenumRange ? null === u ? "" : u : r.state.currentenumRange, c = a("dataType"), m = a("type"), f = t("defaultAppointedInt", {
        initialValue: n ? parseInt(n) : "",
        rules: [ {
          required: !0,
          message: "常量值不能为空！"
        }, {
          validator: r.checkInt
        } ]
      }), p = t("defaultAppointedFloat", {
        initialValue: n ? parseFloat(n) : "",
        rules: [ {
          required: !0,
          message: "常量值不能为空！"
        }, {
          validator: r.checkFloat
        } ]
      }), _ = t("defaultAppointedString", {
        initialValue: n || "",
        rules: [ {
          required: !0,
          min: 0,
          max: 255,
          message: "最大长度255！"
        } ]
      }), h = t("defaultAppointedBoolean", {
        initialValue: n,
        rules: [ {
          required: !0,
          message: "常量值不能为空！"
        } ]
      }), y = t("defaultAppointedPwd", {
        initialValue: n || "",
        rules: [ {
          required: !0,
          min: 0,
          max: 255,
          message: "最大长度255！"
        } ]
      }), I = t("enumRange", {
        initialValue: i,
        rules: [ {
          required: !0,
          message: "枚举范围不能为空！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(null, !0, "枚举范围不能为空！")
        } ]
      }), b = t("defaultIntValue", {
        initialValue: n,
        rules: [ {
          required: !1,
          message: "默认值不能为空！"
        }, {
          validator: r.checkInt
        } ]
      }), E = t("minIntValue", {
        initialValue: d,
        rules: [ {
          validator: r.checkInt
        } ]
      }), F = t("maxIntValue", {
        initialValue: o,
        rules: [ {
          validator: r.checkInt
        } ]
      }), g = t("defaultFloatValue", {
        initialValue: n ? parseFloat(n) : "",
        rules: [ {
          required: !1,
          message: "默认值不能为空！"
        }, {
          validator: r.checkFloatExcludeNull
        } ]
      }), x = t("minFloatValue", {
        initialValue: d,
        rules: [ {
          validator: r.checkFloat
        } ]
      }), v = t("maxFloatValue", {
        initialValue: o,
        rules: [ {
          validator: r.checkFloat
        } ]
      }), k = t("defaultEnumValue", {
        initialValue: n || "",
        rules: [ {
          required: !1,
          message: "默认值不能为空！"
        } ]
      }), q = t("defaultStringValue", {
        initialValue: n || "",
        rules: [ {
          required: !1,
          min: 0,
          max: 255,
          message: "最大长度255！"
        } ]
      }), A = t("defaultPwdValue", {
        initialValue: n || "",
        rules: [ {
          required: !1,
          min: 0,
          max: 255,
          message: "最大长度255！"
        } ]
      }), V = t("defaultBoolean", {
        initialValue: n,
        rules: [ {
          required: !1,
          message: "默认值不能为空！"
        } ]
      }), R = t("precision", {
        initialValue: void 0 === s ? 2 : s,
        rules: []
      }), P = [];
      if ("1" === c) "1" === m ? (P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "最小值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, E, {
        placeholder: "最小值"
      })))), P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "最大值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, F, {
        placeholder: "最大值"
      })))), P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, b, {
        placeholder: "默认值"
      }))))) : "2" === m && P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "数值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, f, {
        placeholder: "(数值)最多支持32位整型数据"
      })))); else if ("3" === c) "1" === m ? P.push(_react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(RadioGroup, V, _react.default.createElement(_amosAntd.Radio, {
        key: "1",
        value: "1"
      }, "true"), _react.default.createElement(_amosAntd.Radio, {
        key: "0",
        value: "0"
      }, "false")))) : "2" === m && P.push(_react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "值: "
      }), _react.default.createElement(RadioGroup, h, _react.default.createElement(_amosAntd.Radio, {
        key: "1",
        value: "1"
      }, "true"), _react.default.createElement(_amosAntd.Radio, {
        key: "0",
        value: "0"
      }, "false")))); else if ("4" === c) if ("1" === m) {
        P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
          hasFeedback: !0,
          label: "枚举范围: "
        }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, I, {
          placeholder: "由中文英文及字符组成，字符之间以一个半角逗号作为间隔",
          onChange: r.onEnumRangeChange
        }))));
        for (var C = i.split(","), L = [], T = 0; T < C.length; T++) {
          var w = C[T];
          "" !== w && L.push(_react.default.createElement(Option, {
            key: T,
            value: "".concat(w)
          }, w));
        }
        P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
          hasFeedback: !0,
          label: "默认值: "
        }), _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({
          style: {
            width: "100%",
            height: "32px"
          }
        }, k, {
          placeholder: "请先输入枚举范围"
        }), L)));
      } else "2" === m && P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "枚举范围: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, I, {
        placeholder: "由中文英文及字符组成，字符之间以一个半角逗号作为间隔"
      })))); else "5" === c ? "1" === m ? P.push(_react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, q, {
        placeholder: "默认值"
      })))) : "2" === m && P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, _, {
        placeholder: "默认值"
      })))) : "6" === c ? "1" === m ? P.push(_react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, A, {
        type: "password",
        placeholder: "默认值"
      })))) : "2" === m && P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, y, {
        type: "password",
        placeholder: "默认值"
      })))) : "2" === c && ("1" === m ? (P.push(_react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "精度: "
      }), _react.default.createElement("label", null, "小数点后"), _react.default.createElement(_amosAntd.InputNumber, (0, 
      _extends2.default)({
        min: 0,
        max: 32,
        defaultValue: 0
      }, R)), _react.default.createElement("label", null, "位"))), P.push(_react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "最小值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, x, {
        placeholder: "最小值"
      })))), P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "最大值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, v, {
        placeholder: "最大值"
      })))), P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "默认值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, g, {
        placeholder: "默认值"
      }))))) : "2" === m && P.push(_react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "数值: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, p, {
        placeholder: "(数值)最多支持小数点前后32位浮点型数据"
      })))));
      return P;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getDynamicCodeName", (function() {
      var e = r.props.form.getFieldValue, t = e("dataType"), a = e("type"), l = [];
      return "1" === t ? "1" === a ? (l.push("minIntValue"), l.push("maxIntValue"), l.push("defaultIntValue")) : "2" === a && l.push("defaultAppointedInt") : "3" === t ? "1" === a ? l.push("defaultBoolean") : "2" === a && l.push("defaultAppointedBoolean") : "4" === t ? "1" === a ? (l.push("enumRange"), 
      l.push("defaultEnumValue")) : "2" === a && l.push("enumRange") : "5" === t ? "1" === a ? l.push("defaultStringValue") : "2" === a && l.push("defaultAppointedString") : "6" === t ? "1" === a ? l.push("defaultPwdValue") : "2" === a && l.push("defaultAppointedPwd") : "2" === t && ("1" === a ? (l.push("precision"), 
      l.push("minFloatValue"), l.push("maxFloatValue"), l.push("defaultFloatValue")) : "2" === a && l.push("defaultAppointedFloat")), 
      l;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleSubmit", (function(e) {
      e.preventDefault();
      var t = [].concat(fieldNames, (0, _toConsumableArray2.default)(r.getDynamicCodeName()));
      r.props.form.validateFields(t, {}, (function(e, t) {
        e || (t = (0, _validate.objOfStrPropTrim)(t), r.handleSave(t));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleSave", (function(e) {
      console.log(e);
      var t = 0, a = 0, l = "", n = "", u = 0;
      for (var d in e) e.hasOwnProperty(d) && d.startsWith("min") ? t = e[d] : e.hasOwnProperty(d) && d.startsWith("max") ? a = e[d] : e.hasOwnProperty(d) && d.startsWith("default") ? l = "".concat(e[d]) : e.hasOwnProperty(d) && "enumRange" === d ? n = e[d] : e.hasOwnProperty(d) && "precision" === d && (u = e[d]);
      r.props.addIntfcArrt ? (e.uuid = _amosTool.UUID.uuid(8, 2), e.minValue = t, e.maxValue = a, 
      e.valueStr = l, e.enumRange = n, e.precision = u, r.props.addIntfcArrt(e), _amosFramework.message.success("成功！")) : (e.minValue = t, 
      e.maxValue = a, e.valueStr = l, e.enumRange = n, e.precision = u, r.saveIntfcAttr(e)), 
      r.props.form.resetFields(), r.props.callBack();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "saveIntfcAttr", (function(e) {
      var t = r.props, a = t.intfcId, l = t.propertyInfo, n = a || l.intfcId;
      l && l.id && (e.id = l.id), _processor.AmosFetch.post((0, _processor.formatUrl)(_urlConsts.OltSerUrl.intfcAttrSave, {
        id: n
      }), {
        data: e
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        "SUCCESS" === e.result ? (_amosFramework.message.success("操作成功！"), r.props.requestIntfcAttrs()) : _amosFramework.message.danger("操作失败！");
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleCancel", (function(e) {
      r.props.form.resetFields(), r.props.callBack();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkInt", (function(e, t, a) {
      if ("" === (t = (0, _amosTool.trim)(t)) || null == t) a(); else if ((0, _rayValidate.isInt)(parseInt(t))) {
        var r = t.toString().length;
        r > 0 && r < 33 ? a() : a("最多支持32位整型数据");
      } else a("最多支持32位整型数据");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkFloat", (function(e, t, a) {
      if ("" === (t = (0, _amosTool.trim)(t)) || null == t) a(); else if ((0, _rayValidate.isNum)(parseInt(t))) {
        var r = t.toString().length;
        r > 0 && r < 33 ? a() : a("最多支持小数点前后32位浮点型数据");
      } else a("最多支持小数点前后32位浮点型数据");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkFloatExcludeNull", (function(e, t, a) {
      if ("" === (t = (0, _amosTool.trim)(t)) || null == t) a(); else if ((0, _rayValidate.isNum)(parseInt(t))) {
        var r = t.toString().length;
        r > 0 && r < 33 ? a() : a("最多支持小数点前后32位浮点型数据");
      } else a("最多支持小数点前后32位浮点型数据");
    })), r.state = {
      currentenumRange: void 0,
      isEdited: !1
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "render",
    value: function() {
      var e = this.props, t = e.form, a = e.propertyInfo, r = t.getFieldProps, l = r("name", {
        initialValue: a ? a.name : a,
        rules: [ {
          required: !0,
          min: 1,
          max: 20,
          message: "支持1-20位非空格字符！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(20, !0, "属性名不能为空！")
        } ]
      }), n = r("type", {
        initialValue: a && a.type ? "".concat(a.type) : "1",
        rules: [ {
          required: !0,
          message: "分类不能为空！"
        } ]
      }), u = r("displayName", {
        initialValue: a ? a.displayName : a,
        rules: [ {
          required: !0,
          min: 1,
          max: 20,
          message: "支持1-20位非空格字符！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(20, !0, "显示名称不能为空！")
        } ]
      }), d = r("dataType", {
        initialValue: a ? "".concat(a.dataType) : a,
        rules: [ {
          required: !0,
          message: "数据类型不能为空！"
        } ]
      }), o = r("unit", {
        initialValue: a ? a.unit : a,
        rules: [ {
          required: !1,
          min: 1,
          max: 20,
          message: "支持1-20位非空格字符！"
        } ]
      }), s = r("descr", {
        initialValue: a ? a.descr : a,
        rules: []
      }), i = r("isRequired", {
        initialValue: !!a && a.isRequired,
        valuePropName: "checked",
        rules: []
      });
      return _react.default.createElement("div", {
        className: "interface-property-add-modal"
      }, _react.default.createElement(_amosAntd.Form, {
        horizontal: !0,
        onSubmit: this.handleSubmit
      }, _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "属性名: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, l, {
        placeholder: "属性名（支持1-20位非空格字符）"
      }))), _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "分类: "
      }), _react.default.createElement(RadioGroup, n, classifyOption)), _react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "显示名称: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, u, {
        placeholder: "属性名（支持1-20位非空格字符）"
      }))), _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "数据类型："
      }), _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({
        style: {
          width: "100%",
          height: "32px"
        }
      }, d), dataTypeOption)), _react.default.createElement("div", null, this.getDynamicCode()), _react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "单位: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, o, {
        placeholder: "单位（支持1-20位非空格字符）"
      }))), _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "描述: "
      }), _react.default.createElement(_amosAntd.Input, s)), _react.default.createElement(FormItem, (0, 
      _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "是否必填: "
      }), _react.default.createElement(_amosAntd.Checkbox, (0, _extends2.default)({}, i, {
        style: {
          lineHeight: "31px",
          float: "left",
          "margin-left": "7px"
        }
      }))), _react.default.createElement(FormItem, {
        wrapperCol: {
          xs: {
            span: 24,
            offset: 0
          },
          sm: {
            span: 24,
            offset: 0
          }
        }
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 3,
        offset: 14
      }, _react.default.createElement(_amosAntd.Button, {
        type: "primary",
        htmlType: "submit"
      }, "提交")), _react.default.createElement(_amosAntd.Col, {
        span: 3,
        offset: 1
      }, _react.default.createElement(_amosAntd.Button, {
        onClick: this.handleCancel
      }, "取消"))))));
    }
  } ]), a;
}(_react.Component);

AddEditInterfaceProperty.displayName = "AddEditInterfaceProperty", AddEditInterfaceProperty.propTypes = {
  form: _propTypes.default.any,
  callBack: _propTypes.default.func,
  propertyInfo: _propTypes.default.any
}, AddEditInterfaceProperty.defaultProps = {
  propertyInfo: {
    type: 1,
    dataType: 1,
    enumRange: ""
  }
};

var _default = AddEditInterfaceProperty;

exports.default = _default;