"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 _extends3 = _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"), _dt2react = require("dt2react"), _processor = require("../../../utils/processor"), _urlConsts = require("../../../consts/urlConsts");

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 = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var n in e) if ("default" !== n && Object.prototype.hasOwnProperty.call(e, n)) {
    var l = i ? Object.getOwnPropertyDescriptor(e, n) : null;
    l && (l.get || l.set) ? Object.defineProperty(r, n, l) : 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 i = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, i);
    } 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 Panel = _amosFramework.Collapse.Panel, collapseHeadHeight = 95, CapacityInterfacePanel = 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), "onClickProperty", (function(e, t) {
      r.savePropertyToEquipment();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onAttributeChange", (function(e, t) {
      var a = r.state, i = a.propertyList, n = a.tempEdit;
      void 0 !== i && (i.map((function(a) {
        a.id === t && (a.valueStr = e.target.value, n[t] = e.target.value);
      })), r.setState({
        tempEdit: n
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceData", (function(e) {
      if (void 0 !== e) {
        var t = "".concat(_urlConsts.OltSerUrl.deviceInterfaceByid, "/").concat(e);
        _processor.AmosFetch.post(t).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          r.setState({
            propertyList: e.dataList.content
          });
        }));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInterfaceContent", (function() {
      var e = [], t = r.state.propertyList, a = r.props, i = a.getCurrentEquipment, n = a.capacityBasicInfo;
      if (void 0 !== i) {
        var l = i();
        return void 0 !== t && void 0 !== l.cfgParamMap ? t.map((function(t) {
          var a = l.cfgParamMap["cpbl_intfc_".concat(n.id, "_").concat(t.intfcId, "_").concat(t.id)];
          a = void 0 === a ? t.valueStr : a, e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            span: 4,
            offset: 1,
            style: {
              height: "30px",
              lineHeight: "30px",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
              overflow: "hidden"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 18,
            offset: 1,
            style: {
              textAlign: "left",
              height: "30px",
              lineHeight: "30px"
            }
          }, a)));
        })) : void 0 !== t && void 0 === l.cfgParamMap && t.map((function(t) {
          e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            span: 4,
            offset: 1,
            style: {
              height: "30px",
              lineHeight: "30px",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
              overflow: "hidden"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 18,
            offset: 1,
            style: {
              textAlign: "left",
              height: "30px",
              lineHeight: "30px"
            }
          }, t.valueStr)));
        })), e;
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInterfaceEditContent", (function() {
      var e = [], t = r.state, a = t.propertyList, i = t.tempEdit, n = r.props, l = n.getCurrentEquipment, o = n.capacityBasicInfo;
      if (void 0 !== l) {
        var s = l();
        return void 0 !== a && void 0 !== s.cfgParamMap ? a.map((function(t) {
          var a = s.cfgParamMap["cpbl_intfc_".concat(o.id, "_").concat(t.intfcId, "_").concat(t.id)];
          a = void 0 === a ? t.valueStr : a, t.valueStr = i[t.id] ? i[t.id] : a, e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            title: t.displayName,
            span: 8,
            offset: 1,
            style: {
              textAlign: "right",
              height: "30px",
              lineHeight: "30px",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
              overflow: "hidden"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 14,
            offset: 1,
            style: {
              textAlign: "left",
              height: "30px",
              lineHeight: "30px"
            }
          }, _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "90%"
            },
            onChange: function(e) {
              return r.onAttributeChange(e, t.id);
            },
            value: t.valueStr
          }))));
        })) : void 0 !== a && void 0 === s.cfgParamMap && a.map((function(t) {
          e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            title: t.displayName,
            span: 8,
            offset: 1,
            style: {
              textAlign: "right",
              height: "30px",
              lineHeight: "30px",
              textOverflow: "ellipsis",
              whiteSpace: "nowrap",
              overflow: "hidden"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 14,
            offset: 1,
            style: {
              textAlign: "left",
              height: "30px",
              lineHeight: "30px"
            }
          }, _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "90%"
            },
            onChange: function(e) {
              return r.onAttributeChange(e, t.id);
            },
            value: t.valueStr
          }))));
        })), e;
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCollapseHead", (function(e, t) {
      var a = r.getImgPath(t), i = [], n = e.length > 4 ? "img-line" : "img-short-line";
      return i.push(_react.default.createElement("div", {
        className: "img-line-root"
      }, _react.default.createElement("label", null, e), _react.default.createElement("img", {
        src: require("./../../../assets/iot/topo/u2074.png"),
        alt: "",
        className: n
      }), a)), i;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getImgPath", (function(e) {
      return r.state.collapseKey.includes(e) ? _react.default.createElement("img", {
        src: require("./../../../assets/iot/topo/expand.png"),
        alt: "",
        className: "img-last"
      }) : _react.default.createElement("img", {
        src: require("./../../../assets/iot/topo/shrink.png"),
        alt: "",
        className: "img-last"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "closedPanel", (function() {
      (0, r.props.closeCapacityInterfacePanel)();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "savePropertyToEquipment", (function() {
      var e = r.props, t = e.getCurrentEquipment, a = e.capacityBasicInfo;
      if (void 0 !== t) {
        var i = t(), n = r.state.propertyList, l = i.cfgParamMap;
        void 0 !== n && (n.map((function(e) {
          var t = "cpbl_intfc_".concat(a.id, "_").concat(e.intfcId, "_").concat(e.id), r = e.valueStr;
          l.hasOwnProperty(t) ? l[t] = r : (0, _extends3.default)(l, (0, _defineProperty2.default)({}, t, r));
        })), i.cfgParamJson = JSON.stringify(l), _processor.AmosFetch.post(_urlConsts.OltSerUrl.addEquipmentAttribute, {
          data: i
        }).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          "SUCCESS" === e.result ? _amosFramework.message.success("编辑成功！") : _amosFramework.message.danger("编辑失败！");
        })));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "changeCollapseSize", (function(e) {
      var t = r.collapsepanel, a = (0, _dt2react.getOffsetParent)(t).clientHeight - collapseHeadHeight;
      (0, _dt2react.addStyle)(t, "height", "".concat(a, "px")), void 0 !== e && void 0 !== e.length && r.setState({
        collapseKey: e
      });
    })), r.state = {
      propertyList: [],
      collapseKey: [ "1", "2" ],
      tempEdit: {}
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      var e = this.props.interfaceBasicInfo;
      this.getInterfaceData(e.intfcId);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props, a = t.interfaceBasicInfo, r = t.nodeId;
      e.capacityBasicInfo.id === a.id && r === e.nodeId || (this.getInterfaceData(e.interfaceBasicInfo.intfcId), 
      this.setState({
        tempEdit: {}
      }));
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.props.interfaceBasicInfo, a = this.state.collapseKey;
      return _react.default.createElement("div", {
        className: "capacity-interface-panel-content"
      }, _react.default.createElement("div", {
        className: "head-one"
      }, "设备接口"), _react.default.createElement(_amosAntd.Icon, {
        type: "close",
        onClick: this.closedPanel,
        style: {
          position: "relative",
          top: "-26px",
          left: "14rem"
        }
      }), _react.default.createElement("div", {
        className: "head-two",
        style: {
          position: "relative",
          top: "21px"
        }
      }, _react.default.createElement("div", {
        className: "head-two-five",
        style: {
          position: "relative",
          top: "-42px"
        }
      }), _react.default.createElement("div", {
        className: "head-two-six",
        style: {
          position: "relative",
          top: "-72px"
        },
        onClick: function(t) {
          return e.onClickProperty(t);
        }
      }, "完成")), _react.default.createElement("div", {
        className: "amos-collapse-panel",
        style: {
          position: "relative",
          top: "-21px"
        },
        ref: function(t) {
          return e.collapsepanel = t;
        }
      }, _react.default.createElement(_amosFramework.Collapse, {
        activeKey: a,
        onChange: function(t) {
          return e.changeCollapseSize(t);
        }
      }, _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("基本信息", "1"),
        key: "1"
      }, _react.default.createElement("div", {
        className: "capacity-interface-basic"
      }, _react.default.createElement("div", null, _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
        span: 4,
        offset: 1,
        style: {
          height: "30px",
          lineHeight: "30px"
        }
      }, "名称："), _react.default.createElement(_amosFramework.Col, {
        span: 18,
        offset: 1,
        style: {
          textAlign: "left",
          height: "30px",
          lineHeight: "30px"
        }
      }, t.intfcName))))), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("通讯参数", "2"),
        key: "2"
      }, _react.default.createElement("div", {
        className: "capacity-interface-property"
      }, this.getCapacityInterfaceEditContent())))));
    }
  } ]), a;
}(_react.Component);

CapacityInterfacePanel.displayName = "CapacityInterfacePanel", CapacityInterfacePanel.propTypes = {
  closeCapacityInterfacePanel: _propTypes.default.func,
  interfaceBasicInfo: _propTypes.default.object,
  capacityBasicInfo: _propTypes.default.object,
  getCurrentEquipment: _propTypes.default.func,
  updateNodeConfig: _propTypes.default.func,
  cfgParamJson: _propTypes.default.object,
  nodeId: _propTypes.default.string
}, CapacityInterfacePanel.defaultProps = {
  interfaceBasicInfo: {},
  capacityBasicInfo: {}
};

var _default = CapacityInterfacePanel;

exports.default = _default;