"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")), _dt2react = require("dt2react"), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _processor = require("../../../utils/processor"), _urlConsts = require("../../../consts/urlConsts"), _DeviceEnum = require("./../../deviceManage/common/DeviceEnum"), _DeviceLang = require("./../../deviceManage/common/DeviceLang");

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;
  }
}

require("./topo.scss");

var createForm = _amosAntd.Form.create(), Panel = _amosFramework.Collapse.Panel, collapseHeadHeight = 95, DevicePropertyPanel = 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) {
      r.savePropertyToEquipment();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClickCapacity", (function(e, t) {
      var a = r.props, i = a.showDeviceCapacityPanel, n = a.closeCapacityInterfacePanel;
      i(t, r.getCurrentEquipment), n();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onAttributeChange", (function(e, t) {
      var a = r.state.attributes;
      void 0 !== a && (a.map((function(a) {
        a.id === t && (a.valueStr = e.target.value);
      })), r.setState({
        attributes: a
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getPropertyData", (function(e, t) {
      if (void 0 !== e) {
        var a = r.props.config;
        if (a && a.data) {
          var i = a.data.eqpTmplId, n = "".concat(_urlConsts.OltSerUrl.fetchDeviceById, "/").concat(i);
          _processor.AmosFetch.get(n).then((function(e) {
            if (e.ok) return e.json();
            throw new Error("从服务端获取数据失败！");
          })).then((function(e) {
            if ("SUCCESS" === e.result) {
              var a = e.dataList;
              if (void 0 !== a) {
                var i = a.capabilities ? a.capabilities : [];
                r.getEquipmentData(t, a.attributes ? a.attributes : [], i);
              }
            }
          }));
        }
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceData", (function(e) {
      if (void 0 !== e) {
        var t = r.props.config;
        if (t && t.data) {
          var a = t.data.eqpTmplId, i = "".concat(_urlConsts.OltSerUrl.fetchDeviceInterfaceById, "/").concat(a);
          _processor.AmosFetch.get(i).then((function(e) {
            if (e.ok) return e.json();
            throw new Error("从服务端获取数据失败！");
          })).then((function(e) {
            if ("SUCCESS" === e.result) {
              var t = e.dataList;
              r.setState({
                intfcList: t || []
              });
            }
          }));
        }
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getEquipmentData", (function(e, t, a) {
      if (void 0 !== e) {
        var i = "".concat(_urlConsts.OltSerUrl.getEquipmentData, "/").concat(e);
        _processor.AmosFetch.get(i).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          if ("SUCCESS" === e.result) {
            var i = e.dataList, n = i.cfgParamMap.selCpblIds, l = [];
            n && a.map((function(e) {
              n.includes(String(e.id)) && l.push(e);
            })), t.map((function(e) {
              e.valueStr = i.cfgParamMap["equip_".concat(e.id)];
            })), r.setState({
              equipment: i,
              attributes: t,
              capabilities: l
            });
          }
        }));
      } else r.setState({
        equipment: {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getAttributesEditContent", (function() {
      var e = r.state, t = e.attributes, a = e.equipment, i = [];
      return void 0 !== a.cfgParamMap ? t.map((function(e) {
        var t = e.valueStr;
        i.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          title: e.displayName,
          span: 8,
          offset: 1,
          style: {
            textAlign: "right",
            height: "30px",
            lineHeight: "30px",
            textOverflow: "ellipsis",
            whiteSpace: "nowrap",
            overflow: "hidden"
          }
        }, e.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(t) {
            return r.onAttributeChange(t, e.id);
          },
          value: t
        }))));
      })) : t.map((function(e) {
        i.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          title: e.displayName,
          span: 8,
          offset: 1,
          style: {
            textAlign: "right",
            height: "30px",
            lineHeight: "30px",
            textOverflow: "ellipsis",
            whiteSpace: "nowrap",
            overflow: "hidden"
          }
        }, e.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(t) {
            return r.onAttributeChange(t, e.id);
          },
          value: e.valueStr
        }))));
      })), i;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacitysContent", (function() {
      var e = r.state.capabilities, t = [];
      return e.map((function(e) {
        t.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 21,
          offset: 1,
          style: {
            height: "30px",
            lineHeight: "30px",
            textOverflow: "ellipsis",
            whiteSpace: "nowrap",
            overflow: "hidden",
            textAlign: "left"
          }
        }, e.name), _react.default.createElement(_amosFramework.Col, {
          span: 2,
          style: {
            height: "30px",
            lineHeight: "30px"
          }
        }, _react.default.createElement("div", {
          onClick: function(t) {
            return r.onClickCapacity(t, e);
          },
          className: "edit-interface-img"
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_nlsx.png"),
          alt: "",
          style: {
            position: "relative",
            top: "5px"
          }
        })))));
      })), t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCurrentEquipment", (function() {
      return r.state.equipment;
    })), (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), "savePropertyToEquipment", (function() {
      var e = r.state, t = e.attributes, a = e.equipment, i = a.cfgParamMap;
      void 0 !== t && (t.map((function(e) {
        var t = "equip_".concat(e.id), a = e.valueStr;
        i.hasOwnProperty(t) ? i[t] = a : (0, _extends3.default)(i, (0, _defineProperty2.default)({}, t, a)), 
        "sourceId" === e.name && (i.hasOwnProperty("sid") ? i.sid = a : (0, _extends3.default)(i, {
          sid: a
        }));
      })), i.hasOwnProperty("sid") || (0, _extends3.default)(i, {
        sid: ""
      }), a.cfgParamJson = JSON.stringify(i), _processor.AmosFetch.post(_urlConsts.OltSerUrl.addEquipmentAttribute, {
        data: a
      }).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), "updateName", (function(e) {
      var t = r.state.equipment, a = r.props, i = a.config, n = a.getSubgraphData, l = a.subviewId, o = a.nodeId, s = r.name;
      if (r.name = e, void 0 !== t.id) {
        var u = i.data, c = {
          label: e,
          type: i.type,
          data: u,
          style: i.style
        }, p = {
          id: u.id,
          name: e,
          nodeId: o,
          config: JSON.stringify(c)
        }, d = "".concat(_urlConsts.OltSerUrl.updateNodeName);
        _processor.AmosFetch.post(d, {
          data: p
        }).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          "SUCCESS" === e.result ? -1 === e.dataList ? (_amosFramework.message.danger("设备名称重复！"), 
          r.name = s, r.setState({
            attributes: r.state.attributes
          })) : n(l, o) : _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 = {
      attributes: [],
      intfcList: [],
      capabilities: [],
      equipment: {},
      collapseKey: [ "1", "2", "3" ]
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      var e = this.props, t = e.config, a = e.equipmentId, r = t.data ? t.data : {};
      this.getPropertyData(r.id, a), this.getInterfaceData(r.id), this.changeCollapseSize();
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props, a = t.nodeId, r = t.cfgParamJson, i = e.config.data ? e.config.data : {};
      a === e.nodeId && r === e.cfgParamJson || (this.getPropertyData(i.id, e.equipmentId), 
      this.getInterfaceData(i.id));
    }
  }, {
    key: "render",
    value: function() {
      var e, t, a = this, r = this.props, i = r.config, n = r.deleteNode, l = r.nodeId, o = r.doHiddenProperty, s = this.state.collapseKey;
      return void 0 !== i && (e = i.data ? i.data : {}, t = void 0 === i.label ? this.name : i.label), 
      _react.default.createElement("div", {
        className: "device-property-panel"
      }, _react.default.createElement("div", {
        className: "head-one"
      }, "设备信息"), _react.default.createElement("div", {
        className: "head-two"
      }, _react.default.createElement("div", {
        className: "head-two-one"
      }), _react.default.createElement("div", {
        className: "head-two-two",
        onClick: function(e) {
          return n(l);
        }
      }, "移出"), _react.default.createElement("div", {
        className: "head-two-three",
        onClick: function(e) {
          return o(e);
        }
      }, "取消"), _react.default.createElement("div", {
        className: "head-two-four",
        onClick: function(e) {
          return a.onClickProperty(e);
        }
      }, "完成")), _react.default.createElement("div", {
        className: "amos-collapse-panel",
        ref: function(e) {
          return a.collapsepanel = e;
        }
      }, _react.default.createElement(_amosFramework.Collapse, {
        activeKey: s,
        onChange: function(e) {
          return a.changeCollapseSize(e);
        }
      }, _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("基本信息", "1"),
        key: "1"
      }, _react.default.createElement("div", {
        className: "property-basic-info"
      }, _react.default.createElement("div", {
        style: {
          height: "100%"
        }
      }, _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"
        }
      }, _react.default.createElement(_amosFramework.Editable, {
        value: t,
        onChange: this.updateName,
        showOkCancel: !1
      }))), _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"
        }
      }, e.model)), _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"
        }
      }, e ? (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, parseInt(e.type)) : "")), _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"
        }
      }, e.descr))))), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("基本属性", "2"),
        key: "2"
      }, _react.default.createElement("div", {
        className: "property-property-info"
      }, this.getAttributesEditContent())), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("数据采集", "3"),
        key: "3"
      }, _react.default.createElement("div", {
        className: "property-interface-info"
      }, this.getCapacitysContent())))));
    }
  } ]), a;
}(_react.Component);

DevicePropertyPanel.displayName = "DevicePropertyPanel", DevicePropertyPanel.propTypes = {
  config: _propTypes.default.object,
  form: _propTypes.default.any,
  getSubgraphData: _propTypes.default,
  subviewId: _propTypes.default.string,
  nodeId: _propTypes.default.string,
  showDeviceCapacityPanel: _propTypes.default.func,
  equipmentId: _propTypes.default.number,
  updateNodeConfig: _propTypes.default.func,
  cfgParamJson: _propTypes.default.object,
  deviceLabel: _propTypes.default.string,
  deleteNode: _propTypes.default.func,
  doHiddenProperty: _propTypes.default.func,
  closeCapacityInterfacePanel: _propTypes.default.func
};

var _default = createForm(DevicePropertyPanel);

exports.default = _default;