"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"), _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 l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var n = i ? Object.getOwnPropertyDescriptor(e, l) : null;
    n && (n.get || n.set) ? Object.defineProperty(r, l, n) : r[l] = e[l];
  }
  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, 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) {
      r.savePropertyToEquipment();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onAttributeChange", (function(e, t) {
      var a = r.state, i = a.propertyList, l = a.tempEdit;
      void 0 !== i && (i.map((function(a) {
        a.id === t && (a.valueStr = e.target.value, l[t] = e.target.value);
      })), r.setState({
        tempEdit: l
      }));
    })), (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, i = t.protocolName, l = t.property, n = [];
              l.map((function(e) {
                e.type !== _DeviceEnum.capacatyclassifyEnum.get("output").value && n.push(e);
              })), r.setState({
                interfaceList: a,
                protocolName: i,
                propertyList: n
              });
            }
          }
        }));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInterfaceContent", (function() {
      var e = [], t = r.state.interfaceList;
      return void 0 !== t && t.map((function(t) {
        e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 21,
          offset: 1,
          style: {
            textAlign: "left",
            height: "30px",
            lineHeight: "30px",
            textOverflow: "ellipsis",
            whiteSpace: "nowrap",
            overflow: "hidden"
          }
        }, t.intfcName), _react.default.createElement(_amosFramework.Col, {
          span: 2,
          style: {
            height: "30px",
            lineHeight: "30px"
          }
        }, _react.default.createElement("div", {
          onClick: function(e) {
            return r.onClickInterface(e, t);
          },
          className: "edit-interface-img"
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_nlsx.png"),
          alt: ""
        })))));
      })), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityPropertyContent", (function() {
      var e = [], t = r.state.propertyList, a = r.props, i = a.getCurrentEquipment, l = a.capacityBasicInfo;
      if (void 0 !== i) {
        var n = i();
        return void 0 !== t && void 0 !== n.cfgParamMap ? t.map((function(t) {
          var a = n.cfgParamMap["cpbl_".concat(l.id, "_").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 === n.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), "getCapacityPropertyEditContent", (function() {
      var e = [], t = r.state, a = t.propertyList, i = t.tempEdit, l = r.props, n = l.getCurrentEquipment, o = l.capacityBasicInfo;
      if (void 0 !== n) {
        var s = n();
        if (void 0 !== a && void 0 !== s.cfgParamMap) {
          var c = s.cfgParamMap.quotaSelected[o.id];
          a.map((function(t) {
            if (c && c.includes(t.id)) {
              var a = s.cfgParamMap["cpbl_".concat(o.id, "_").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
              }))));
            }
          }));
        } else 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
          }))));
        }));
        return e;
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCollapseHead", (function(e, t) {
      var a = r.getImgPath(t), i = [], l = 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: l
      }), 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.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 i = t(), l = r.state.propertyList, n = i.cfgParamMap;
        void 0 !== l && (l.map((function(e) {
          var t = "cpbl_".concat(a.id, "_").concat(e.id), r = e.valueStr;
          n.hasOwnProperty(t) ? n[t] = r : (0, _extends3.default)(n, (0, _defineProperty2.default)({}, t, r));
        })), i.cfgParamJson = JSON.stringify(n), _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 = {
      interfaceList: [],
      protocolName: "",
      propertyList: [],
      collapseKey: [ "1", "2", "3" ],
      tempEdit: {}
    }, 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), 
      this.setState({
        tempEdit: {}
      }));
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.props.capacityBasicInfo, a = this.state, r = a.protocolName, i = a.collapseKey;
      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: "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: i,
        onChange: function(t) {
          return e.changeCollapseSize(t);
        }
      }, _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("基本信息", "1"),
        key: "1"
      }, _react.default.createElement("div", {
        className: "device-capacity-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.name)), _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"
        }
      }, r)), _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"
        }
      }, (0, _DeviceLang.stringUtil)(_DeviceEnum.capacityClassifyEnum, parseInt(t.type))))))), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("采集指标", "2"),
        key: "2"
      }, _react.default.createElement("div", {
        className: "device-capacity-property"
      }, this.getCapacityPropertyEditContent())), _react.default.createElement(Panel, {
        showArrow: !1,
        header: this.getCollapseHead("设备接口", "3"),
        key: "3"
      }, _react.default.createElement("div", {
        className: "device-capacity-interface"
      }, 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;