"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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");

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 CapacityInterfacePanel = 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), "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), "getInterfaceData", (function(e) {
            if (void 0 !== e) {
                var t = "".concat(_urlConsts.OltSerUrl.deviceInterfaceByid, "/").concat(e);
                _processor.AmosFetch.post(t).then((function(e) {
                    if (e.ok) return e.json();
                    throw new Error("从服务端获取数据失败！");
                })).then((function(e) {
                    r.setState({
                        propertyList: e.dataList.content
                    });
                }));
            }
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInterfaceContent", (function() {
            var e = [], t = (r.state.propertyList, r.props);
            t.getCurrentEquipment, t.capacityBasicInfo;
            return e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
                span: 4,
                offset: 1,
                style: {
                    height: "30px",
                    "line-height": "30px"
                }
            }, "设备ID", "："), _react.default.createElement(_amosFramework.Col, {
                span: 18,
                offset: 1,
                style: {
                    "text-align": "left",
                    height: "30px",
                    "line-height": "30px"
                }
            }, _react.default.createElement(_amosAntd.Input, {
                style: {
                    width: "60%"
                },
                defaultValue: ""
            })))), e.push(_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"
                }
            }, _react.default.createElement(_amosAntd.Input, {
                style: {
                    width: "60%"
                },
                defaultValue: "1"
            })))), e;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCapacityInterfaceEditContent", (function() {
            var e = [], t = r.state.propertyList, a = r.props, n = a.getCurrentEquipment, i = a.capacityBasicInfo;
            if (void 0 !== n) {
                var l = n();
                return void 0 !== t && void 0 !== l.cfgParamMap ? t.map((function(t) {
                    var a = l.cfgParamMap["cpbl_intfc_".concat(i.id, "_").concat(t.id)];
                    a = void 0 === a ? t.valueStr : a, t.valueStr = a, e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
                        span: 4,
                        offset: 1,
                        style: {
                            height: "30px",
                            "line-height": "30px"
                        }
                    }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
                        span: 18,
                        offset: 1,
                        style: {
                            "text-align": "left",
                            height: "30px",
                            "line-height": "30px"
                        }
                    }, _react.default.createElement(_amosAntd.Input, {
                        style: {
                            width: "60%"
                        },
                        onChange: function(e) {
                            return r.onAttributeChange(e, t.id);
                        },
                        defaultValue: a
                    }))));
                })) : void 0 !== t && void 0 === l.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",
                            "line-height": "30px"
                        }
                    }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
                        span: 18,
                        offset: 1,
                        style: {
                            "text-align": "left",
                            height: "30px",
                            "line-height": "30px"
                        }
                    }, _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.closeCapacityInterfacePanel)();
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "savePropertyToEquipment", (function() {
            var e = r.props, t = e.getCurrentEquipment, a = e.capacityBasicInfo;
            if (void 0 !== t) {
                var n = t(), i = r.state.propertyList;
                if (void 0 === n.id) {
                    var l = r.props, o = l.updateNodeConfig, s = l.nodeId, c = l.cfgParamJson;
                    void 0 !== i && (i.map((function(e) {
                        var t = "cpbl_intfc_".concat(a.id, "_").concat(e.id), r = e.valueStr;
                        c.hasOwnProperty(t) ? c[t] = r : (0, _extends4.default)(c, (0, _defineProperty2.default)({}, t, r));
                    })), o(s, c));
                } else {
                    var u = n.cfgParamMap;
                    void 0 !== i && (i.map((function(e) {
                        var t = "cpbl_intfc_".concat(a.id, "_").concat(e.id), r = e.valueStr;
                        u.hasOwnProperty(t) ? u[t] = r : (0, _extends4.default)(u, (0, _defineProperty2.default)({}, t, r));
                    })), n.cfgParamJson = JSON.stringify(u), _processor.AmosFetch.post(_urlConsts.OltSerUrl.addEquipmentAttribute, {
                        data: n
                    }).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 = {
            propertyList: [],
            editProperty: !1
        }, r;
    }
    return (0, _createClass2.default)(a, [ {
        key: "componentDidMount",
        value: function() {
            var e = this.props.interfaceBasicInfo;
            this.getInterfaceData(e.intfcId);
        }
    }, {
        key: "componentWillReceiveProps",
        value: function(e) {
            var t = this.props, a = t.interfaceBasicInfo, r = t.nodeId;
            e.capacityBasicInfo.id === a.id && r === e.nodeId || this.getInterfaceData(e.interfaceBasicInfo.intfcId);
        }
    }, {
        key: "render",
        value: function() {
            var e = this.props.interfaceBasicInfo, t = this.state.editProperty;
            return _react.default.createElement("div", {
                className: "capacity-interface-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: "capacity-interface-basic"
            }, _react.default.createElement("div", {
                className: "capacity-interface-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",
                    "line-height": "30px"
                }
            }, "名称："), _react.default.createElement(_amosFramework.Col, {
                span: 18,
                offset: 1,
                style: {
                    "text-align": "left",
                    height: "30px",
                    "line-height": "30px"
                }
            }, _react.default.createElement(_amosAntd.Input, {
                style: {
                    width: "60%"
                },
                value: e
            }))))), _react.default.createElement("div", {
                className: "capacity-interface-property"
            }, _react.default.createElement("div", {
                className: "capacity-interface-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"
            })), t ? this.getCapacityInterfaceEditContent() : this.getCapacityInterfaceContent()));
        }
    } ]), a;
}(_react.Component);

CapacityInterfacePanel.displayName = "CapacityInterfacePanel", CapacityInterfacePanel.propTypes = {
    closeCapacityInterfacePanel: _propTypes.default.func,
    interfaceBasicInfo: _propTypes.default.object,
    capacityBasicInfo: _propTypes.default.object,
    getCurrentEquipment: _propTypes.default.func,
    updateNodeConfig: _propTypes.default.func,
    cfgParamJson: _propTypes.default.object,
    nodeId: _propTypes.default.string
}, CapacityInterfacePanel.defaultProps = {
    interfaceBasicInfo: {},
    capacityBasicInfo: {}
};

var _default = CapacityInterfacePanel;

exports.default = _default;