"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")), _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")), _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")), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _propTypes = _interopRequireDefault(require("prop-types")), _processor = require("../../utils/processor"), _amosTool = require("amos-tool"), _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")), _AddInterfaceProperty = _interopRequireDefault(require("./privateInterface/AddInterfaceProperty"));

require("./../common/style/commonStyle.scss");

var _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 = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var i = n ? Object.getOwnPropertyDescriptor(e, l) : null;
    i && (i.get || i.set) ? Object.defineProperty(r, l, i) : r[l] = e[l];
  }
  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 n = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, n);
    } 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 createForm = _amosAntd.Form.create(), FormItem = _amosAntd.Form.Item, Panel = _amosAntd.Collapse.Panel, Option = _amosFramework.Select.Option, maxDescLength = 500, AddInterface = 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), "onClickDown", (function(e) {
      e.preventDefault(), r.props.form.validateFields((function(e, t) {
        e || (t = (0, _validate.objOfStrPropTrim)(t), r.setState({
          itemInfo: t,
          activeKey: "2"
        }));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClickUp", (function() {
      r.setState({
        activeKey: "1"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClick", (function() {
      r.setState({
        waiting: !0
      });
      var e = r.state, t = e.itemInfo, a = e.interfaceProList;
      t.dicIdCommMode = parseInt(t.type), t.remark = t.desc, t.attributes = a, t.visibility = 1, 
      _processor.AmosFetch.post(_urlConsts.default.interfaceSave, {
        data: t
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        "SUCCESS" === e.result ? (_amosFramework.message.success("新增通讯方式成功！"), r.props.updateAddView("2")) : (r.setState({
          waiting: !1
        }), _amosFramework.message.danger("新增接口失败！"));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "delBtn", (function(e) {
      _amosAntd.Modal.confirm({
        title: "删除",
        content: "是否删除所选信息？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {
          for (var t = r.state.interfaceProList, a = 0; a < t.length; a++) {
            if (t[a].uuid === e) {
              t.splice(a, 1);
              break;
            }
          }
          r.setState({
            interfaceProList: t
          });
        },
        onCancel: function() {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "autoProView", (function() {
      var e = r.state.interfaceProList, t = [];
      return t.push(_react.default.createElement("div", {
        className: "table-card",
        key: 0
      }, _react.default.createElement(_amosAntd.Card, {
        style: {
          width: 250,
          height: 170
        }
      }, _react.default.createElement("div", {
        style: {
          textAlign: "center",
          marginTop: "1rem"
        }
      }, _react.default.createElement(_AddInterfaceProperty.default, {
        addIntfcArrt: r.addIntfcArrt,
        repuestType: "addProperty"
      }), _react.default.createElement("h3", null, "新建设备接口参数"))))), e.length > 0 && e.map((function(e) {
        t.push(_react.default.createElement("div", {
          key: e.uuid,
          className: "table-card"
        }, _react.default.createElement(_amosAntd.Card, {
          title: e.name,
          extra: _react.default.createElement("a", {
            onClick: function() {
              return r.delBtn(e.uuid);
            }
          }, _react.default.createElement(_amosAntd.Icon, {
            type: "close",
            className: "basic-info-add"
          })),
          style: {
            width: 280,
            height: 170
          }
        }, _react.default.createElement("a", {
          style: {
            textDecoration: "none"
          }
        }, _react.default.createElement("p", null, "分  类：", "1" === e.type ? "变量" : "2" === e.type ? "常量" : "3" === e.type ? "标签" : ""), _react.default.createElement("p", null, "数据类型：", "1" === e.dataType ? "整型" : "2" === e.dataType ? "浮点型" : "3" === e.dataType ? "布尔型" : "4" === e.dataType ? "枚举" : "5" === e.dataType ? "字符串" : "6" === e.dataType ? "密码" : "")))));
      })), t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "addIntfcArrt", (function(e) {
      var t = r.state.interfaceProList;
      r.setState({
        interfaceProList: [].concat((0, _toConsumableArray2.default)(t), [ e ])
      }), r.autoProView();
    })), r.state = {
      activeKey: "1",
      interfaceProList: [],
      itemInfo: {},
      waiting: !1
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "render",
    value: function() {
      var e = this.state.itemInfo, t = e.name, a = e.type, r = e.desc, n = this.props.communityDatas, l = this.props.form.getFieldProps, i = {
        labelCol: {
          span: 10
        },
        wrapperCol: {
          span: 4
        }
      }, o = l("name", {
        initialValue: t,
        rules: [ {
          required: !0,
          message: "名称不能为空！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
        } ]
      }), u = l("type", {
        initialValue: a,
        rules: [ {
          required: !0,
          message: "通讯方式不能为空！"
        } ]
      }), s = l("desc", {
        initialValue: r,
        rules: [ {
          validator: (0, _validate.noSpaceLengthValidate)(maxDescLength, !1, null)
        } ]
      });
      return _react.default.createElement("div", {
        className: "table-container"
      }, _react.default.createElement(_amosAntd.Collapse, {
        activeKey: this.state.activeKey,
        accordion: !0
      }, _react.default.createElement(Panel, {
        header: "新建设备接口",
        key: "1",
        showArrow: !1
      }, _react.default.createElement("div", {
        style: {
          textAlign: "center"
        }
      }, _react.default.createElement(_amosAntd.Form, {
        onSubmit: this.onClickDown
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        hasFeedback: !0,
        label: "名称"
      }, i), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, o, {
        placeholder: "请输入名称"
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        hasFeedback: !0,
        label: "通讯方式"
      }, i), _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({}, u, {
        style: {
          width: "100%",
          textAlign: "left",
          height: "32px"
        },
        dropdownStyle: {
          width: "260px",
          maxHeight: "240px"
        },
        placeholder: "请选择通讯方式",
        className: "interface-add-select"
      }), n.map((function(e) {
        return _react.default.createElement(Option, {
          key: "".concat(e.id, "Option"),
          value: "".concat(e.id)
        }, e.name);
      })))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "描述"
      }, i), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, s, {
        placeholder: "请输入描述"
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Button, {
        onClick: this.onClickDown
      }, "下一步"))))), _react.default.createElement(Panel, {
        header: "新建设备接口参数",
        key: "2",
        showArrow: !1
      }, _react.default.createElement(_amosAntd.Row, null, this.autoProView()), _react.default.createElement("div", {
        style: {
          height: "3rem"
        }
      }), _react.default.createElement(_amosAntd.Row, {
        type: "flex",
        justify: "center"
      }, _react.default.createElement(_amosAntd.Button, {
        onClick: this.onClickUp
      }, "上一步"), _react.default.createElement("div", {
        style: {
          width: "1.5rem"
        }
      }), _react.default.createElement(_amosAntd.Button, {
        onClick: this.onClick,
        disabled: this.state.waiting
      }, "确定")))));
    }
  } ]), a;
}(_react.Component);

AddInterface.displayName = "AddInterface", AddInterface.propTypes = {
  form: _propTypes.default.any,
  updateAddView: _propTypes.default.func,
  communityDatas: _propTypes.default.array
};

var _default = createForm(AddInterface);

exports.default = _default;