"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 _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")), _amosFramework = require("amos-framework"), _urlConsts = _interopRequireDefault(require("../../../../consts/urlConsts")), _TopoUpLoadIcon = _interopRequireDefault(require("./TopoUpLoadIcon")), _DeviceEnum = require("./../../../deviceManage/common/DeviceEnum"), _DeviceLang = require("./../../../deviceManage/common/DeviceLang"), _topoService = require("./../../../../services/topoService");

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, DeviceBasicInfoConfig = 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), "onChangeCollapseSize", (function(e) {
      void 0 !== e && void 0 !== e.length && r.setState({
        collapseKey: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onAttributeChange", (function(e, t) {
      var a = r.props, i = a.equipmentId, n = a.nodeId, l = a.showProperty, o = {
        id: i
      };
      r.props.currentDeviceConfig.device.attributes.map((function(e) {
        var a = e.name;
        a && "sourceId" === a && (o.sid = t);
      })), o[e] = t, (0, _topoService.updateEquipmentConfigAction)(o).then((function(a) {
        r.deviceConfigParam[e] = t, l(n);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "setImgFile", (function(e) {
      var t = new FileReader;
      if (t.addEventListener("load", (function() {
        return r.saveImgFileAction(t.result, e.name);
      })), "{}" === JSON.stringify(e)) {
        r.saveEquipmnet({
          binaryImg: null,
          imgName: null
        });
      } else t.readAsBinaryString(e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCollapseHead", (function(e, t) {
      var a = r.props.getImgPath(t, r.state.collapseKey), i = [];
      return i.push(_react.default.createElement("div", {
        className: "config-collapse-head"
      }, _react.default.createElement("label", {
        className: "config-collapse-text"
      }, e), a)), i;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getDeviceConfigInfo", (function() {
      var e = r.props.currentDeviceConfig, t = e ? e.eqp : void 0, a = e ? e.eqpProperty : void 0, i = r.deviceConfigParam, n = [];
      return a && a.map((function(e) {
        var a = i["equip_".concat(e.id)];
        if (void 0 === a) {
          var l = t.cfgParamMap;
          a = l["equip_".concat(e.id)] ? l["equip_".concat(e.id)] : a;
        }
        i["equip_".concat(e.id)] = a, n.push(_react.default.createElement("div", {
          key: e.id,
          className: "topo-property-common"
        }, _react.default.createElement("div", {
          className: "property-label-name",
          title: e.displayName
        }, e.displayName, "："), _react.default.createElement(_amosFramework.Editable, {
          value: a,
          onChange: function(t) {
            return r.onAttributeChange("equip_".concat(e.id), t);
          },
          showOkCancel: !1,
          style: {
            width: "126px",
            marginLeft: "10px"
          },
          innerValueStyle: {
            width: "126px"
          },
          placeholder: "请输入"
        })));
      })), n;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "saveImgFileAction", (function(e, t) {
      var a = {
        id: r.props.equipmentId,
        binaryImg: e,
        imgName: t
      };
      (0, _topoService.addeEditEqpImgAction)(a).then((function(e) {}));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "updateEquipmentName", (function(e, t) {
      var a = r.props, i = a.currentDeviceConfig, n = a.showProperty;
      if (i ? i.eqp : void 0) {
        var l = r.props, o = l.config, c = l.getSubgraphData, u = l.subviewId, s = l.nodeId, p = r.name;
        r.name = t;
        var d = o.data, f = {
          label: t,
          type: o.type,
          data: d,
          style: o.style
        }, m = {
          id: d.id,
          name: t,
          nodeId: s,
          config: JSON.stringify(f)
        };
        (0, _topoService.updateEquipmentNameAction)(m).then((function(e) {
          -1 === e ? (_amosFramework.message.danger("设备名称重复！"), r.name = p) : (c(u, s), n(s));
        }));
      }
    })), r.deviceConfigParam = {}, r.state = {
      collapseKey: [ "1", "2" ]
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {}
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {}
  }, {
    key: "componentWillUnmount",
    value: function() {}
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.state.collapseKey, a = this.props.currentDeviceConfig, r = a ? a.eqp : void 0, i = a ? a.device : void 0, n = r && r.logo ? "".concat(_urlConsts.default.fetchDeviceImg, "/icon/").concat(r.logo) : void 0;
      return _react.default.createElement("div", {
        className: "topo-config-basic-root"
      }, _react.default.createElement(_amosFramework.Collapse, {
        activeKey: t,
        onChange: function(t) {
          return e.onChangeCollapseSize(t);
        }
      }, _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("设备信息", "1"),
        key: "1"
      }, _react.default.createElement("div", {
        className: "device-basic-info"
      }, _react.default.createElement("div", {
        className: "topo-basic-name"
      }, _react.default.createElement("div", {
        className: "property-label-name"
      }, "设备名称："), _react.default.createElement(_amosFramework.Editable, {
        value: r && r.name,
        onChange: function(t) {
          return e.updateEquipmentName("name", t);
        },
        showOkCancel: !1,
        style: {
          width: "140px",
          marginLeft: "10px"
        },
        innerValueStyle: {
          width: "140px"
        },
        placeholder: "请输入"
      })), _react.default.createElement("div", {
        className: "topo-basic-descr"
      }, _react.default.createElement("div", {
        className: "property-label-name"
      }, "设备描述："), _react.default.createElement("div", {
        className: "property-normal-label",
        title: r && r.descr
      }, r && r.descr)), _react.default.createElement("div", {
        className: "topo-basic-icon"
      }, _react.default.createElement(_TopoUpLoadIcon.default, {
        enable: !0,
        style: {
          top: "-18px",
          "max-width": "130px",
          "max-height": "130px"
        },
        setImgFile: this.setImgFile,
        defaultImg: n
      })), _react.default.createElement("div", {
        className: "topo-basic-catalog"
      }, _react.default.createElement("div", {
        className: "property-label-name"
      }, "设备类别："), _react.default.createElement("div", {
        className: "property-normal-label",
        title: (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, i && i.type)
      }, (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, i && i.type))), _react.default.createElement("div", {
        className: "topo-basic-industry"
      }, _react.default.createElement("div", {
        className: "property-label-name"
      }, "所属行业："), _react.default.createElement("div", {
        className: "property-normal-label",
        title: i && i.equipTemplateIndustry.name
      }, i && i.equipTemplateIndustry.name)), _react.default.createElement("div", {
        className: "topo-type-name"
      }, _react.default.createElement("div", {
        className: "property-label-name"
      }, "设备类型："), _react.default.createElement("div", {
        className: "property-normal-label",
        title: i && i.name
      }, i && i.name)), _react.default.createElement("div", {
        className: "topo-basic-model"
      }, _react.default.createElement("div", {
        className: "property-label-name"
      }, "备注："), _react.default.createElement("div", {
        className: "property-normal-label",
        title: i && i.model
      }, i && i.model)))), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("设备属性", "2"),
        key: "2"
      }, _react.default.createElement("div", {
        className: "device-basic-property"
      }, this.getDeviceConfigInfo()))));
    }
  } ]), a;
}(_react.Component);

DeviceBasicInfoConfig.displayName = "DeviceBasicInfoConfig", DeviceBasicInfoConfig.propTypes = {
  getImgPath: _propTypes.default.func,
  currentDeviceConfig: _propTypes.default.object,
  getSubgraphData: _propTypes.default.func,
  subviewId: _propTypes.default.string,
  nodeId: _propTypes.default.string,
  equipmentId: _propTypes.default.number,
  config: _propTypes.default.object,
  showProperty: _propTypes.default.func
};

var _default = DeviceBasicInfoConfig;

exports.default = _default;