"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _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"),
  _dt2react = _interopRequireDefault(require("dt2react")),
  _DeviceEnum = require("./../../deviceManage/common/DeviceEnum"),
  _DeviceLang = require("./../../deviceManage/common/DeviceLang");

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

function _getRequireWildcardCache() {
  if ("function" != typeof WeakMap) return null;
  var e = new WeakMap;
  return _getRequireWildcardCache = function() {
    return e
  }, e
}

function _interopRequireWildcard(e) {
  if (e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache();
  if (t && t.has(e)) return t.get(e);
  var a, r, n = {},
    i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (a in e) Object.prototype.hasOwnProperty.call(e, a) && ((r = i ? Object.getOwnPropertyDescriptor(e, a) : null) && (r.get || r.set) ? Object.defineProperty(n, a, r) : n[a] = e[a]);
  return n.default = e, t && t.set(e, n), n
}

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var a, r = arguments[t];
      for (a in r) Object.prototype.hasOwnProperty.call(r, a) && (e[a] = r[a])
    }
    return e
  }).apply(this, arguments)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var a = 0; a < t.length; a++) {
    var r = t[a];
    r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r)
  }
}

function _createClass(e, t, a) {
  return t && _defineProperties(e.prototype, t), a && _defineProperties(e, a), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(a) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(a);
    return _possibleConstructorReturn(this, r ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Date.prototype.toString.call(Reflect.construct(Date, [], function() {})), !0
  } catch (e) {
    return !1
  }
}

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, a) {
  return t in e ? Object.defineProperty(e, t, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = a, e
}
var Panel = _amosFramework.Collapse.Panel,
  collapseHeadHeight = 95,
  DeviceCapacityPanel = function() {
    _inherits(a, _react.Component);
    var t = _createSuper(a);

    function a(e) {
      var c;
      return _classCallCheck(this, a), _defineProperty(_assertThisInitialized(c = t.call(this, e)), "onClickInterface", function(e, t) {
        var a = c.props;
        (0, a.showCapacityInterfacePanel)(t, a.getCurrentEquipment)
      }), _defineProperty(_assertThisInitialized(c), "onClickProperty", function(e) {
        c.savePropertyToEquipment()
      }), _defineProperty(_assertThisInitialized(c), "onAttributeChange", function(t, a) {
        var e = c.state,
          r = e.propertyList,
          n = e.tempEdit;
        void 0 !== r && (r.map(function(e) {
          e.id === a && (e.valueStr = t.target.value, n[a] = t.target.value)
        }), c.setState({
          tempEdit: n
        }))
      }), _defineProperty(_assertThisInitialized(c), "getCapacityData", function(e) {
        void 0 !== e && (e = "".concat(_urlConsts.OltSerUrl.fetchCapacityListInfoById, "/").concat(e), _processor.AmosFetch.get(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t, a, r;
          "SUCCESS" !== e.result || void 0 !== (a = e.dataList) && (t = a.interface, e = a.protocolName, a = a.property, r = [], a.map(function(e) {
            e.type !== _DeviceEnum.capacatyclassifyEnum.get("output").value && r.push(e)
          }), c.setState({
            interfaceList: t,
            protocolName: e,
            propertyList: r
          }))
        }))
      }), _defineProperty(_assertThisInitialized(c), "getCapacityInterfaceContent", function() {
        var e = [],
          t = c.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: {
              "text-align": "left",
              height: "30px",
              "line-height": "30px",
              "text-overflow": "ellipsis",
              "white-space": "nowrap",
              overflow: "hidden"
            }
          }, t.intfcName), _react.default.createElement(_amosFramework.Col, {
            span: 2,
            style: {
              height: "30px",
              "line-height": "30px"
            }
          }, _react.default.createElement("div", {
            onClick: function(e) {
              return c.onClickInterface(e, t)
            },
            className: "edit-interface-img"
          }, _react.default.createElement("img", {
            src: require("./../../../assets/iot/img/list_nlsx.png"),
            alt: ""
          })))))
        }), e
      }), _defineProperty(_assertThisInitialized(c), "getCapacityPropertyContent", function() {
        var a = [],
          e = c.state.propertyList,
          t = c.props,
          r = t.getCurrentEquipment,
          n = t.capacityBasicInfo;
        if (void 0 !== r) {
          var i = r();
          return void 0 !== e && void 0 !== i.cfgParamMap ? e.map(function(e) {
            var t = void 0 === (t = i.cfgParamMap["cpbl_".concat(n.id, "_").concat(e.id)]) ? e.valueStr : t;
            a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
              span: 4,
              offset: 1,
              style: {
                height: "30px",
                "line-height": "30px",
                "text-overflow": "ellipsis",
                "white-space": "nowrap",
                overflow: "hidden"
              }
            }, e.displayName, "："), _react.default.createElement(_amosFramework.Col, {
              span: 18,
              offset: 1,
              style: {
                "text-align": "left",
                height: "30px",
                "line-height": "30px"
              }
            }, t)))
          }) : void 0 !== e && void 0 === i.cfgParamMap && e.map(function(e) {
            a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
              span: 4,
              offset: 1,
              style: {
                height: "30px",
                "line-height": "30px",
                "text-overflow": "ellipsis",
                "white-space": "nowrap",
                overflow: "hidden"
              }
            }, e.displayName, "："), _react.default.createElement(_amosFramework.Col, {
              span: 18,
              offset: 1,
              style: {
                "text-align": "left",
                height: "30px",
                "line-height": "30px"
              }
            }, e.valueStr)))
          }), a
        }
      }), _defineProperty(_assertThisInitialized(c), "getCapacityPropertyEditContent", function() {
        var a = [],
          e = c.state,
          t = e.propertyList,
          r = e.tempEdit,
          n = c.props,
          e = n.getCurrentEquipment,
          i = n.capacityBasicInfo;
        if (void 0 !== e) {
          var o, l = e();
          return void 0 !== t && void 0 !== l.cfgParamMap ? (o = l.cfgParamMap.quotaSelected[i.id], t.map(function(t) {
            var e;
            o && o.includes(t.id) && (e = void 0 === (e = l.cfgParamMap["cpbl_".concat(i.id, "_").concat(t.id)]) ? t.valueStr : e, t.valueStr = r[t.id] || e, a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
              title: t.displayName,
              span: 8,
              offset: 1,
              style: {
                "text-align": "right",
                height: "30px",
                "line-height": "30px",
                "text-overflow": "ellipsis",
                "white-space": "nowrap",
                overflow: "hidden"
              }
            }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
              span: 14,
              offset: 1,
              style: {
                "text-align": "left",
                height: "30px",
                "line-height": "30px"
              }
            }, _react.default.createElement(_amosAntd.Input, {
              style: {
                width: "90%"
              },
              onChange: function(e) {
                return c.onAttributeChange(e, t.id)
              },
              value: t.valueStr
            })))))
          })) : void 0 !== t && void 0 === l.cfgParamMap && t.map(function(t) {
            a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
              title: t.displayName,
              span: 8,
              offset: 1,
              style: {
                "text-align": "right",
                height: "30px",
                "line-height": "30px",
                "text-overflow": "ellipsis",
                "white-space": "nowrap",
                overflow: "hidden"
              }
            }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
              span: 14,
              offset: 1,
              style: {
                "text-align": "left",
                height: "30px",
                "line-height": "30px"
              }
            }, _react.default.createElement(_amosAntd.Input, {
              style: {
                width: "90%"
              },
              onChange: function(e) {
                return c.onAttributeChange(e, t.id)
              },
              value: t.valueStr
            }))))
          }), a
        }
      }), _defineProperty(_assertThisInitialized(c), "getCollapseHead", function(e, t) {
        var a = c.getImgPath(t),
          r = [],
          t = 4 < e.length ? "img-line" : "img-short-line";
        return r.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: t
        }), a)), r
      }), _defineProperty(_assertThisInitialized(c), "getImgPath", function(e) {
        e = c.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"
        });
        return e
      }), _defineProperty(_assertThisInitialized(c), "closedPanel", function() {
        (0, c.props.closeDeviceCapacityPanel)()
      }), _defineProperty(_assertThisInitialized(c), "savePropertyToEquipment", function() {
        var a, e = c.props,
          t = e.getCurrentEquipment,
          r = e.capacityBasicInfo;
        void 0 !== t && (e = t(), t = c.state.propertyList, a = e.cfgParamMap, void 0 !== t && (t.map(function(e) {
          var t = "cpbl_".concat(r.id, "_").concat(e.id),
            e = e.valueStr;
          a.hasOwnProperty(t) ? a[t] = e : _extends(a, _defineProperty({}, t, e))
        }), e.cfgParamJson = JSON.stringify(a), _processor.AmosFetch.post(_urlConsts.OltSerUrl.addEquipmentAttribute, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? _amosFramework.message.success("编辑成功！") : _amosFramework.message.danger("编辑失败！")
        })))
      }), _defineProperty(_assertThisInitialized(c), "changeCollapseSize", function(e) {
        var t = c.collapsepanel,
          a = _dt2react.default.getOffsetParent(t).clientHeight - collapseHeadHeight;
        _dt2react.default.addStyle(t, "height", "".concat(a, "px")), void 0 !== e && void 0 !== e.length && c.setState({
          collapseKey: e
        })
      }), c.state = {
        interfaceList: [],
        protocolName: "",
        propertyList: [],
        collapseKey: ["1", "2", "3"],
        tempEdit: {}
      }, c
    }
    return _createClass(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,
          t = t.nodeId;
        e.capacityBasicInfo.id === a.id && t === e.nodeId || (this.getCapacityData(e.capacityBasicInfo.id), this.setState({
          tempEdit: {}
        }))
      }
    }, {
      key: "render",
      value: function() {
        var t = this,
          e = this.props.capacityBasicInfo,
          a = this.state,
          r = a.protocolName,
          a = 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(e) {
            return t.onClickProperty(e)
          }
        }, "完成")), _react.default.createElement("div", {
          className: "amos-collapse-panel",
          style: {
            position: "relative",
            top: "-21px"
          },
          ref: function(e) {
            return t.collapsepanel = e
          }
        }, _react.default.createElement(_amosFramework.Collapse, {
          activeKey: a,
          onChange: function(e) {
            return t.changeCollapseSize(e)
          }
        }, _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",
            "line-height": "30px"
          }
        }, "名称："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left",
            height: "30px",
            "line-height": "30px"
          }
        }, e.name)), _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            "line-height": "30px"
          }
        }, "协议："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left",
            height: "30px",
            "line-height": "30px"
          }
        }, r)), _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            "line-height": "30px"
          }
        }, "类型："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left",
            height: "30px",
            "line-height": "30px"
          }
        }, (0, _DeviceLang.stringUtil)(_DeviceEnum.capacityClassifyEnum, parseInt(e.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
  }();
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 = DeviceCapacityPanel, module.exports = exports.default;
