"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")), _urlConsts = require("./../../../../../consts/urlConsts"), _amosAntd = require("amos-antd"), _processor = require("../../../../../utils/processor"), _amosFramework = require("amos-framework");

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 = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var i = n ? Object.getOwnPropertyDescriptor(e, l) : null;
    i && (i.get || i.set) ? Object.defineProperty(r, l, i) : 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 n = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, n);
    } 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 createForm = _amosAntd.Form.create(), FormItem = _amosAntd.Form.Item, formItemLayout = {
  labelCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 6
    }
  },
  wrapperCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 16
    }
  }
}, 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, t) {
      t || r.savePropertyToEquipment(), r.setState({
        editProperty: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClickCapacity", (function(e, t) {
      (0, r.props.showDeviceCapacityPanel)(t, r.getCurrentEquipment);
    })), (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);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getPropertyData", (function(e, t) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getInterfaceData", (function(e) {
      if (void 0 !== e) {
        var t = "".concat(_urlConsts.OltSerUrl.fetchDeviceInterfaceById, "/").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;
            r.setState({
              intfcList: t || []
            });
          }
        }));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getEquipmentData", (function(e, t) {
      if (void 0 !== e) {
        var a = "".concat(_urlConsts.OltSerUrl.getEquipmentData, "/").concat(e);
        _processor.AmosFetch.get(a).then((function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！");
        })).then((function(e) {
          if ("SUCCESS" === e.result) {
            var a = e.dataList;
            t.map((function(e) {
              e.valueStr = a.cfgParamMap["equip_".concat(e.id)];
            })), r.setState({
              equipment: a,
              attributes: t
            });
          }
        }));
      } else r.setState({
        equipment: {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getAttributesContent", (function() {
      var e = r.state, t = (e.attributes, e.equipment, []);
      return t.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%"
        },
        defaultValue: "BGK-Micro-40D"
      })))), t.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%"
        },
        defaultValue: "10003"
      })))), t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getAttributesEditContent", (function() {
      var e = r.state, t = e.attributes, a = e.equipment, n = [];
      return void 0 !== a.cfgParamMap ? t.map((function(e) {
        var t = void 0 === a.cfgParamMap["equip_".concat(e.id)] ? e.valueStr : a.cfgParamMap["equip_".concat(e.id)];
        n.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            lineHeight: "30px"
          }
        }, e.name, "："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            textAlign: "left",
            height: "30px",
            lineHeight: "30px"
          }
        }, _react.default.createElement(_amosAntd.Input, {
          style: {
            width: "60%"
          },
          onChange: function(t) {
            return r.onAttributeChange(t, e.id);
          },
          defaultValue: t
        }))));
      })) : t.map((function(e) {
        n.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            lineHeight: "30px"
          }
        }, e.name, "："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            textAlign: "left",
            height: "30px",
            lineHeight: "30px"
          }
        }, _react.default.createElement(_amosAntd.Input, {
          style: {
            width: "60%"
          },
          onChange: function(t) {
            return r.onAttributeChange(t, e.id);
          },
          defaultValue: e.valueStr
        }))));
      })), n;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacitysContent", (function() {
      r.state.capabilities;
      var e = [];
      return 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.onClickCapacity(e, "经纬度");
        },
        className: "edit-interface-img"
      }, _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/img/list_nlsx.png"),
        alt: "",
        style: {
          position: "relative",
          top: "5px"
        }
      }))))), 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.onClickCapacity(e, "压力");
        },
        className: "edit-interface-img"
      }, _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/img/list_nlsx.png"),
        alt: "",
        style: {
          position: "relative",
          top: "5px"
        }
      }))))), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCurrentEquipment", (function() {
      return r.state.equipment;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "savePropertyToEquipment", (function() {
      var e = r.state, t = e.attributes, a = e.equipment;
      if (void 0 === a.id) {
        var n = r.props, l = n.updateNodeConfig, i = n.nodeId, o = n.cfgParamJson;
        void 0 !== t && (t.map((function(e) {
          var t = "equip_".concat(e.id), a = e.valueStr;
          o.hasOwnProperty(t) ? o[t] = a : (0, _extends4.default)(o, (0, _defineProperty2.default)({}, t, a));
        })), l(i, o));
      } else {
        var s = a.cfgParamMap;
        void 0 !== t && (t.map((function(e) {
          var t = "equip_".concat(e.id), a = e.valueStr;
          s.hasOwnProperty(t) ? s[t] = a : (0, _extends4.default)(s, (0, _defineProperty2.default)({}, t, a));
        })), a.cfgParamJson = JSON.stringify(s), _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 ? _amosAntd.Modal.warning({
            title: "系统提示",
            content: "编辑成功！",
            okText: "确定"
          }) : _amosAntd.Modal.error({
            title: "系统提示",
            content: "编辑失败！",
            okText: "确定"
          });
        })));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "updateName", (function(e) {})), 
    r.state = {
      attributes: [],
      intfcList: [],
      capabilities: [],
      equipment: {},
      editProperty: !1
    }, 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);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props, a = t.nodeId, r = t.cfgParamJson, n = e.config.data ? e.config.data : {};
      a === e.nodeId && r === e.cfgParamJson || (this.getPropertyData(n.id, e.equipmentId), 
      this.getInterfaceData(n.id));
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props, t = e.config, a = e.deviceLabel, r = this.state.editProperty, n = t.data ? t.data : {};
      void 0 === t.label ? n.name : t.label;
      return _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"
      }, "删除"), _react.default.createElement("div", {
        className: "head-two-three"
      }, "取消"), _react.default.createElement("div", {
        className: "head-two-four"
      }, "完成")), _react.default.createElement("div", {
        className: "property-basic-info"
      }, _react.default.createElement("div", {
        className: "property-basic-info-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", {
        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(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: a
      }))), _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: "BGK-Micro-40D"
      }))), _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(_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: a
      }))))), _react.default.createElement("div", {
        className: "property-property-info"
      }, _react.default.createElement("div", {
        className: "property-property-info-title"
      }, _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"
      })), r ? this.getAttributesEditContent() : this.getAttributesContent()), _react.default.createElement("div", {
        className: "property-interface-info"
      }, _react.default.createElement("div", {
        className: "property-interface-info-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.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,
  updateNodeName: _propTypes.default.func,
  deviceLabel: _propTypes.default.string
};

var _default = createForm(DevicePropertyPanel);

exports.default = _default;