"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 _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 _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : 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 r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var i in e) if ("default" !== i && Object.prototype.hasOwnProperty.call(e, i)) {
    var o = n ? Object.getOwnPropertyDescriptor(e, i) : null;
    o && (o.get || o.set) ? Object.defineProperty(a, i, o) : a[i] = e[i];
  }
  return a.default = e, r && r.set(e, a), a;
}

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
    }
  }
}, AddEditDeviceInterface = 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.interfaceMap, r = (new Date).getTime();
      (0, _extends2.default)(e, {
        key: r,
        intfcDisplayName: t[parseInt(e.intfcId)]
      });
      var n = [ {
        key: e.key,
        intfcId: e.intfcId,
        intfcDirection: e.intfcDirection,
        displayName: t[parseInt(e.intfcId)],
        name: t[parseInt(e.intfcId)]
      } ];
      void 0 === a.props.deviceId ? (a.props.addDeviceInterface(e), a.props.autoCardCalculate(n), 
      a.props.form.resetFields(), a.props.callBack()) : a.saveDeviceInterface(e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleCancel", (function(e) {
      a.props.form.resetFields(), a.props.callBack();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "saveDeviceInterface", (function(e) {
      var t = a.props, r = t.deviceId, n = t.propertyInfo, i = n ? n.devIntfcID : void 0;
      (0, _extends2.default)(e, {
        deviceId: r,
        id: i
      }), _processor.AmosFetch.post(_urlConsts.OltSerUrl.deviceInterfaceUpdate, {
        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.props.getDeviceInfoById(r), a.props.form.resetFields(), a.props.callBack();
      }));
    })), a.state = {}, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentDidMount",
    value: function() {}
  }, {
    key: "render",
    value: function() {
      var e = this.props.form.getFieldProps, t = this.props, r = t.interfaceOption, a = t.propertyInfo, n = a.intfcId, i = a.intfcDirection, o = e("intfcId", {
        initialValue: n ? "".concat(n) : r.length > 0 ? r[0].key : "",
        rules: [ {
          required: !0,
          message: "设备接口不能为空！"
        } ]
      }), l = e("intfcDirection", {
        initialValue: i ? "".concat(i) : Direction[0].key,
        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: "设备接口"
      }, o), r)), _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "设备接口方向: "
      }), _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({
        style: {
          width: "100%",
          height: "32px"
        }
      }, l), Direction)), _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);

AddEditDeviceInterface.displayName = "AddEditDeviceInterface", AddEditDeviceInterface.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,
  getDeviceInfoById: _propTypes.default.func,
  propertyInfo: _propTypes.default.any
}, AddEditDeviceInterface.defaultProps = {
  propertyInfo: {
    intfcDirection: "0"
  }
};

var _default = AddEditDeviceInterface;

exports.default = _default;