"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 _extends2 = _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("./../../common/DeviceEnum"), _DeviceLang = require("./../../common/DeviceLang");

function _createSuper(e) {
    var t = _isNativeReflectConstruct();
    return function() {
        var r, a = (0, _getPrototypeOf2.default)(e);
        if (t) {
            var n = (0, _getPrototypeOf2.default)(this).constructor;
            r = Reflect.construct(a, arguments, n);
        } else r = a.apply(this, arguments);
        return (0, _possibleConstructorReturn2.default)(this, r);
    };
}

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 Option = _amosFramework.Select.Option, FormItem = _amosAntd.Form.Item, Direction = (0, 
_DeviceLang.enums2array)(_DeviceEnum.interfaceDirectionEnum).map((function(e) {
    return _react.default.createElement(Option, {
        key: e.key,
        value: "".concat(e.key)
    }, e.label);
})), formItemLayout = {
    labelCol: {
        xs: {
            span: 24
        },
        sm: {
            span: 5
        }
    },
    wrapperCol: {
        xs: {
            span: 24
        },
        sm: {
            span: 16
        }
    }
}, AddEditCapacityInterface = function(e) {
    (0, _inherits2.default)(r, e);
    var t = _createSuper(r);
    function r(e) {
        var a;
        return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(a), "handleSubmit", (function(e) {
            e.preventDefault(), a.props.form.validateFields((function(e, t) {
                e || a.handleSave(t);
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleSave", (function(e) {
            var t = a.props, r = t.interfaceMap, n = t.protocolId, o = t.capacityId, i = t.propertyInfo, l = (new Date).getTime(), s = [ {
                key: e.key,
                displayName: r[e.empIntfcId].interfaceMultiName
            } ], p = a.props.deviceId;
            void 0 === p ? ((0, _extends2.default)(e, {
                key: l
            }), a.props.addDeviceInterface(e), a.props.autoCardCalculate(s), a.props.form.resetFields(), 
            a.props.callBack()) : ((0, _extends2.default)(e, {
                cpblId: o,
                protocolId: n,
                intfcId: r[e.empIntfcId].interfaceID
            }), i.capaIntId && (e.id = i.capaIntId), e.empIntfcId = r[e.empIntfcId].devIntfcID, 
            e.empTmplIntfcId = e.empIntfcId, a.saveCapacityInterface(e), a.props.getDeviceInfoById(p), 
            a.props.form.resetFields(), a.props.callBack());
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleCancel", (function(e) {
            a.props.form.resetFields(), a.props.callBack();
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "saveCapacityInterface", (function(e) {
            _processor.AmosFetch.post(_urlConsts.OltSerUrl.capacityIntfUpdate, {
                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("操作失败！");
            }));
        })), a.state = {}, a;
    }
    return (0, _createClass2.default)(r, [ {
        key: "componentDidMount",
        value: function() {}
    }, {
        key: "render",
        value: function() {
            var e = this.props, t = e.propertyInfo, r = e.form, a = e.interfaceMap, n = t.empIntfcId, o = r.getFieldProps;
            for (var i in a) {
                a[i].devIntfcID === n && (n = i);
            }
            var l = this.props.interfaceOption, s = o("empIntfcId", {
                initialValue: "".concat(n),
                rules: [ {
                    required: !0,
                    message: "设备接口不能为空！"
                } ]
            });
            return _react.default.createElement("div", {
                className: "device-interface-add-modal"
            }, _react.default.createElement(_amosAntd.Form, {
                horizontal: !0,
                onSubmit: this.handleSubmit
            }, _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
                hasFeedback: !0,
                label: "设备接口: "
            }), _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({
                style: {
                    width: "100%",
                    height: "32px"
                },
                placeholder: "接口"
            }, s), l)), _react.default.createElement(FormItem, {
                wrapperCol: {
                    xs: {
                        span: 24,
                        offset: 0
                    },
                    sm: {
                        span: 24,
                        offset: 0
                    }
                }
            }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
                span: 3,
                offset: 14
            }, _react.default.createElement(_amosAntd.Button, {
                type: "primary",
                htmlType: "submit"
            }, "提交")), _react.default.createElement(_amosAntd.Col, {
                span: 3,
                offset: 1
            }, _react.default.createElement(_amosAntd.Button, {
                onClick: this.handleCancel
            }, "取消"))))));
        }
    } ]), r;
}(_react.Component);

AddEditCapacityInterface.displayName = "AddEditCapacityInterface", AddEditCapacityInterface.propTypes = {
    form: _propTypes.default.any,
    callBack: _propTypes.default.func,
    addDeviceInterface: _propTypes.default.func,
    autoCardCalculate: _propTypes.default.func,
    interfaceOption: _propTypes.default.array,
    interfaceMap: _propTypes.default.object,
    deviceId: _propTypes.default.number,
    protocolId: _propTypes.default.number,
    getDeviceInfoById: _propTypes.default.func,
    capacityId: _propTypes.default.number,
    propertyInfo: _propTypes.default.any
}, AddEditCapacityInterface.defaultProps = {
    propertyInfo: {
        empIntfcId: ""
    }
};

var _default = AddEditCapacityInterface;

exports.default = _default;