"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 _extends4 = _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"), _processor = require("../../../../../utils/processor"), _urlConsts = require("../../../../../consts/urlConsts"), _DeviceEnum = require("./../../../../deviceManage/common/DeviceEnum");

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 = {}, l = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var i in e) if ("default" !== i && Object.prototype.hasOwnProperty.call(e, i)) {
    var n = l ? Object.getOwnPropertyDescriptor(e, i) : null;
    n && (n.get || n.set) ? Object.defineProperty(r, i, n) : r[i] = e[i];
  }
  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 l = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, l);
    } 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 DeviceCapacityPanel = 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), "onClickInterface", (function(e, t) {
      var a = r.props;
      (0, a.showCapacityInterfacePanel)(t, a.getCurrentEquipment);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClickProperty", (function(e, t) {
      t || r.savePropertyToEquipment(), r.setState({
        editProperty: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onAttributeChange", (function(e, t) {
      var a = r.state.propertyList;
      void 0 !== a && a.map((function(a) {
        a.id === t && (a.valueStr = e.target.value);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityData", (function(e) {
      if (void 0 !== e) {
        var t = "".concat(_urlConsts.OltSerUrl.fetchCapacityListInfoById, "/").concat(e);
        _processor.AmosFetch.get(t).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          if ("SUCCESS" === e.result) {
            var t = e.dataList;
            if (void 0 !== t) {
              var a = t.interface, l = t.protocolName, i = t.property, n = [];
              i.map((function(e) {
                e.type !== _DeviceEnum.capacatyclassifyEnum.get("output").value && n.push(e);
              })), r.setState({
                interfaceList: a,
                protocolName: l,
                propertyList: n
              });
            }
          }
        }));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInterfaceContent", (function() {
      var e = [];
      r.state.interfaceList;
      return "压力" === r.props.capacityBasicInfo ? e.push(_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"
        }
      }, _react.default.createElement("div", {
        onClick: function(e) {
          return r.onClickInterface(e, "压力");
        },
        className: "edit-interface-img"
      }, _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/img/list_nlsx.png"),
        alt: "",
        style: {
          paddingTop: "3px"
        }
      }))))) : e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
        span: 4,
        offset: 1,
        style: {
          height: "30px",
          lineHeight: "30px"
        }
      }, "采集GPS"), _react.default.createElement(_amosFramework.Col, {
        span: 18,
        offset: 1,
        style: {
          textAlign: "left",
          height: "30px",
          lineHeight: "30px"
        }
      }, _react.default.createElement("div", {
        onClick: function(e) {
          return r.onClickInterface(e, "采集GPS");
        },
        className: "edit-interface-img"
      }, _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/img/list_nlsx.png"),
        alt: "",
        style: {
          paddingTop: "3px"
        }
      }))))), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityPropertyContent", (function() {
      var e = [];
      return "压力" === r.props.capacityBasicInfo ? e.push(_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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: "2.6mPa"
      })))) : (e.push(_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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: "113:42E"
      })))), e.push(_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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: "34:44N"
      }))))), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityPropertyEditContent", (function() {
      var e = [], t = r.state.propertyList, a = r.props, l = a.getCurrentEquipment, i = a.capacityBasicInfo;
      if (void 0 !== l) {
        var n = l();
        return void 0 !== t && void 0 !== n.cfgParamMap ? t.map((function(t) {
          var a = n.cfgParamMap["cpbl_".concat(i.id, "_").concat(t.id)];
          a = void 0 === a ? t.valueStr : a, t.valueStr = a, e.push(_react.default.createElement("div", {
            className: "device-capacity-text"
          }, _react.default.createElement("label", null, t.displayName, "："), _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "60%"
            },
            onChange: function(e) {
              return r.onAttributeChange(e, t.id);
            },
            defaultValue: a
          })));
        })) : void 0 !== t && void 0 === n.cfgParamMap && t.map((function(t) {
          e.push(_react.default.createElement("div", {
            className: "device-capacity-text"
          }, _react.default.createElement("label", null, t.displayName, "："), _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "60%"
            },
            onChange: function(e) {
              return r.onAttributeChange(e, t.id);
            },
            defaultValue: t.valueStr
          })));
        })), e;
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "closedPanel", (function() {
      (0, r.props.closeDeviceCapacityPanel)();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "savePropertyToEquipment", (function() {
      var e = r.props, t = e.getCurrentEquipment, a = e.capacityBasicInfo;
      if (void 0 !== t) {
        var l = t(), i = r.state.propertyList;
        if (void 0 === l.id) {
          var n = r.props, c = n.updateNodeConfig, o = n.nodeId, s = n.cfgParamJson;
          void 0 !== i && (i.map((function(e) {
            var t = "cpbl_".concat(a.id, "_").concat(e.id), r = e.valueStr;
            s.hasOwnProperty(t) ? s[t] = r : (0, _extends4.default)(s, (0, _defineProperty2.default)({}, t, r));
          })), c(o, s));
        } else {
          var u = l.cfgParamMap;
          void 0 !== i && (i.map((function(e) {
            var t = "cpbl_".concat(a.id, "_").concat(e.id), r = e.valueStr;
            u.hasOwnProperty(t) ? u[t] = r : (0, _extends4.default)(u, (0, _defineProperty2.default)({}, t, r));
          })), l.cfgParamJson = JSON.stringify(u), _processor.AmosFetch.post(_urlConsts.OltSerUrl.addEquipmentAttribute, {
            data: l
          }).then((function(e) {
            if (e.ok) return e.json();
            throw new Error("从服务端获取数据失败！");
          })).then((function(e) {
            "SUCCESS" === e.result ? _amosAntd.Modal.warning({
              title: "系统提示",
              content: "编辑成功！",
              okText: "确定"
            }) : _amosAntd.Modal.error({
              title: "系统提示",
              content: "编辑失败！",
              okText: "确定"
            });
          })));
        }
      }
    })), r.state = {
      interfaceList: [],
      protocolName: "",
      propertyList: [],
      editProperty: !1
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      var e = this.props.capacityBasicInfo;
      this.getCapacityData(e.id);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props, a = t.capacityBasicInfo, r = t.nodeId;
      e.capacityBasicInfo.id === a.id && r === e.nodeId || this.getCapacityData(e.capacityBasicInfo.id);
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props.capacityBasicInfo, t = this.state, a = (t.protocolName, t.editProperty);
      return _react.default.createElement("div", {
        className: "device-capacity-panel-content"
      }, _react.default.createElement("div", {
        className: "head-one"
      }, "数据采集"), _react.default.createElement(_amosAntd.Icon, {
        type: "close",
        onClick: this.closedPanel,
        style: {
          position: "absolute",
          top: "8px",
          right: "5px"
        }
      }), _react.default.createElement("div", {
        className: "head-two"
      }, _react.default.createElement("div", {
        className: "head-two-one"
      }), _react.default.createElement("div", {
        className: "head-two-two"
      }, "删除"), _react.default.createElement("div", {
        className: "head-two-three"
      }, "取消"), _react.default.createElement("div", {
        className: "head-two-four"
      }, "完成")), _react.default.createElement("div", {
        className: "device-capacity-basic"
      }, _react.default.createElement("div", {
        className: "device-capacity-basic-label"
      }, _react.default.createElement("label", null, "设备接口"), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/u2074.png"),
        alt: "",
        className: "img-line"
      }), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/expand.png"),
        alt: "",
        className: "img-last-temp"
      })), _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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: e
      }))), _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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: "压力" === e ? "压力数据" : "GPS数据"
      }))), _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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        defaultValue: "采集"
      }))))), _react.default.createElement("div", {
        className: "device-capacity-property"
      }, _react.default.createElement("div", {
        className: "device-capacity-property-label"
      }, _react.default.createElement("label", null, "采集指标"), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/u2074.png"),
        alt: "",
        className: "img-line"
      }), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/expand.png"),
        alt: "",
        className: "img-last-temp"
      })), a ? this.getCapacityPropertyEditContent() : this.getCapacityPropertyContent()), _react.default.createElement("div", {
        className: "device-capacity-interface"
      }, _react.default.createElement("div", {
        className: "device-capacity-interface-label"
      }, _react.default.createElement("label", null, "设备接口"), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/u2074.png"),
        alt: "",
        className: "img-line"
      }), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/expand.png"),
        alt: "",
        className: "img-last-temp"
      })), this.getCapacityInterfaceContent()));
    }
  } ]), a;
}(_react.Component);

DeviceCapacityPanel.displayName = "DeviceCapacityPanel", DeviceCapacityPanel.propTypes = {
  closeDeviceCapacityPanel: _propTypes.default.func,
  capacityBasicInfo: _propTypes.default.object,
  showCapacityInterfacePanel: _propTypes.default.func,
  getCurrentEquipment: _propTypes.default.func,
  updateNodeConfig: _propTypes.default.func,
  cfgParamJson: _propTypes.default.object,
  nodeId: _propTypes.default.string
}, DeviceCapacityPanel.defaultProps = {
  capacityBasicInfo: {}
};

var _default = DeviceCapacityPanel;

exports.default = _default;