"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _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 _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

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

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

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r, a = arguments[t];
      for (r in a) Object.prototype.hasOwnProperty.call(a, r) && (e[r] = a[r])
    }
    return e
  }).apply(this, arguments)
}

function _toConsumableArray(e) {
  return _arrayWithoutHoles(e) || _iterableToArray(e) || _unsupportedIterableToArray(e) || _nonIterableSpread()
}

function _nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
}

function _unsupportedIterableToArray(e, t) {
  if (e) {
    if ("string" == typeof e) return _arrayLikeToArray(e, t);
    var r = Object.prototype.toString.call(e).slice(8, -1);
    return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0
  }
}

function _iterableToArray(e) {
  if ("undefined" != typeof Symbol && Symbol.iterator in Object(e)) return Array.from(e)
}

function _arrayWithoutHoles(e) {
  if (Array.isArray(e)) return _arrayLikeToArray(e)
}

function _arrayLikeToArray(e, t) {
  (null == t || t > e.length) && (t = e.length);
  for (var r = 0, a = new Array(t); r < t; r++) a[r] = e[r];
  return a
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

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

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var createForm = _amosAntd.Form.create(),
  FormItem = _amosAntd.Form.Item,
  Panel = _amosAntd.Collapse.Panel,
  Option = _amosFramework.Select.Option,
  maxDescLength = 500,
  AddInterface = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var a;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(a = t.call(this, e)), "onClickDown", function(e) {
        e.preventDefault(), a.props.form.validateFields(function(e, t) {
          e || (t = (0, _validate.objOfStrPropTrim)(t), a.setState({
            itemInfo: t,
            activeKey: "2"
          }))
        })
      }), _defineProperty(_assertThisInitialized(a), "onClickUp", function() {
        a.setState({
          activeKey: "1"
        })
      }), _defineProperty(_assertThisInitialized(a), "onClick", function() {
        a.setState({
          waiting: !0
        });
        var e = a.state,
          t = e.itemInfo,
          e = e.interfaceProList;
        t.dicIdCommMode = parseInt(t.type), t.remark = t.desc, t.attributes = e, 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("新增通讯方式成功！"), a.props.updateAddView("2")) : (a.setState({
            waiting: !1
          }), _amosFramework.message.danger("新增接口失败！"))
        })
      }), _defineProperty(_assertThisInitialized(a), "delBtn", function(r) {
        _amosAntd.Modal.confirm({
          title: "删除",
          content: "是否删除所选信息？",
          okText: "确定",
          cancelText: "取消",
          onOk: function() {
            for (var e = a.state.interfaceProList, t = 0; t < e.length; t++)
              if (e[t].uuid === r) {
                e.splice(t, 1);
                break
              } a.setState({
              interfaceProList: e
            })
          },
          onCancel: function() {}
        })
      }), _defineProperty(_assertThisInitialized(a), "autoProView", function() {
        var e = a.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: a.addIntfcArrt,
          repuestType: "addProperty"
        }), _react.default.createElement("h3", null, "新建设备接口参数"))))), 0 < e.length && 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 a.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
      }), _defineProperty(_assertThisInitialized(a), "addIntfcArrt", function(e) {
        var t = a.state.interfaceProList;
        a.setState({
          interfaceProList: [].concat(_toConsumableArray(t), [e])
        }), a.autoProView()
      }), a.state = {
        activeKey: "1",
        interfaceProList: [],
        itemInfo: {},
        waiting: !1
      }, a
    }
    return _createClass(r, [{
      key: "render",
      value: function() {
        var e = this.state.itemInfo,
          t = e.name,
          r = e.type,
          a = e.desc,
          n = this.props.communityDatas,
          o = this.props.form.getFieldProps,
          e = {
            labelCol: {
              span: 10
            },
            wrapperCol: {
              span: 4
            }
          },
          t = o("name", {
            initialValue: t,
            rules: [{
              required: !0,
              message: "名称不能为空！"
            }, {
              validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
            }]
          }),
          r = o("type", {
            initialValue: r,
            rules: [{
              required: !0,
              message: "通讯方式不能为空！"
            }]
          }),
          a = o("desc", {
            initialValue: a,
            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, _extends({
          hasFeedback: !0,
          label: "名称"
        }, e), _react.default.createElement(_amosAntd.Input, _extends({
          className: "amos-grid-form-input"
        }, t, {
          placeholder: "请输入名称"
        }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
          span: 24
        }, _react.default.createElement(FormItem, _extends({
          hasFeedback: !0,
          label: "通讯方式"
        }, e), _react.default.createElement(_amosFramework.Select, _extends({}, r, {
          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, _extends({
          label: "描述"
        }, e), _react.default.createElement(_amosAntd.Input, _extends({
          className: "amos-grid-form-input"
        }, a, {
          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
        }, "确定")))))
      }
    }]), r
  }();
AddInterface.displayName = "AddInterface", AddInterface.propTypes = {
  form: _propTypes.default.any,
  updateAddView: _propTypes.default.func,
  communityDatas: _propTypes.default.array
};
var _default = createForm(AddInterface);
exports.default = _default, module.exports = exports.default;
