"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _processor = require("../../../utils/processor"),
  _urlConsts = require("../../../consts/urlConsts"),
  _amosAntd = require("amos-antd"),
  _amosFramework = require("amos-framework"),
  _amosTool = require("amos-tool"),
  _InterfacePropertyCell = _interopRequireDefault(require("./InterfacePropertyCell")),
  _AddInterfaceProperty = _interopRequireDefault(require("./AddInterfaceProperty"));
require("./interface-detail.scss");
var _validate = require("./../../common/utils/validate");

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 r, a, n = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (a.get || a.set) ? Object.defineProperty(n, r, a) : n[r] = e[r]);
  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 r, a = arguments[t];
      for (r in a) Object.prototype.hasOwnProperty.call(a, r) && (e[r] = a[r])
    }
    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 r = 0; r < t.length; r++) {
    var a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), 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(r) {
  var a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (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, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var FormItem = _amosAntd.Form.Item,
  createForm = _amosAntd.Form.create(),
  Option = _amosFramework.Select.Option,
  PrivateInterfaceDetail = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var s;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(s = t.call(this, e)), "requestIntfcAttrs", function() {
        var e = s.props.carInfo.id,
          e = "".concat(_urlConsts.OltSerUrl.deviceInterfaceByid, "/").concat(e);
        _processor.AmosFetch.post(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          s.setState({
            propertyList: e.dataList.content
          }), s.fetchInterfaceProperty()
        })
      }), _defineProperty(_assertThisInitialized(s), "handleEditParam", function(e) {
        var r = s.props.form.getFieldValue("commType"),
          a = s.props.form.getFieldValue("detail"),
          n = s.props.form.getFieldValue("name"),
          t = s.props.communityDatas,
          o = null,
          i = null;
        if (isNaN(r)) {
          for (var l = 0; l < t.length; l++)
            if ((i = t[l]).name === r) {
              r = i.id, o = i;
              break
            }
        } else
          for (var c = 0; c < t.length; c++)
            if ((i = t[c]).id === parseInt(r)) {
              r = i.id, o = i;
              break
            } s.setState({
          textEdit: !s.state.textEdit
        }), s.state.textEdit && s.props.form.validateFields(function(e, t) {
          e ? s.setState({
            textEdit: !0
          }) : (e = _extends(s.props.carInfo, {
            dicIdCommMode: r,
            remark: a,
            attributes: null,
            communityProtocol: o,
            name: n
          }), s.submitBasicData(e))
        })
      }), _defineProperty(_assertThisInitialized(s), "submitBasicData", function(e) {
        _processor.AmosFetch.post(_urlConsts.OltSerUrl.interfaceSave, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? _amosFramework.message.success("编辑成功") : (s.setState({
            textEdit: !0
          }), _amosFramework.message.danger("编辑失败！"))
        })
      }), _defineProperty(_assertThisInitialized(s), "handleAddProperty", function(e) {}), _defineProperty(_assertThisInitialized(s), "fetchInterfaceProperty", function(t) {
        var e = s.state.propertyList,
          r = [];
        return e.map(function(e) {
          r.push(_react.default.createElement(_InterfacePropertyCell.default, {
            visibility: t,
            key: e.id,
            requestIntfcAttrs: s.requestIntfcAttrs,
            propertyName: "null",
            deleteInterfaceProperty: s.deleteInterfaceProperty,
            propertyInfo: e
          }))
        }), r
      }), _defineProperty(_assertThisInitialized(s), "deleteInterfaceProperty", function(e) {
        var t = s.delProperty;
        _amosAntd.Modal.confirm({
          title: "删除",
          content: "是否删除所选属性？",
          okText: "确定",
          cancelText: "取消",
          onOk: function() {
            t(e)
          },
          onCancel: function() {}
        })
      }), _defineProperty(_assertThisInitialized(s), "delProperty", function(e) {
        e = "".concat(_urlConsts.OltSerUrl.intfcAttrDelete, "/").concat(e);
        _processor.AmosFetch.del(e).then(function(e) {
          if (e.ok) return e.text();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          _amosFramework.message.success("删除成功！"), s.requestIntfcAttrs()
        })
      }), s.state = {
        textEdit: !1,
        propertyList: []
      }, s
    }
    return _createClass(r, [{
      key: "componentDidMount",
      value: function() {
        this.requestIntfcAttrs()
      }
    }, {
      key: "render",
      value: function() {
        var e = this.props.form.getFieldProps,
          t = this.state.textEdit,
          r = this.props,
          a = r.carInfo,
          n = r.communityDatas,
          o = a ? a.name : "",
          i = a && a.communityProtocol ? a.communityProtocol.name : "",
          l = a ? a.remark : "",
          c = !1 === t ? "interface-detail-title-button" : "interface-detail-title-button-hidden",
          s = !1 === t ? "interface-detail-title-button-hidden" : "interface-detail-title-button",
          u = !1 === t ? "interface-detail-title-content" : "interface-detail-title-content-hidden",
          f = !1 === t ? "interface-detail-title-content-hidden" : "interface-detail-title-content",
          d = a.visibility;
        console.log(a);
        r = e("name", {
          initialValue: o || "",
          rules: [{
            required: !0,
            message: "名称不能为空！"
          }, {
            validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
          }]
        }), t = e("commType", {
          initialValue: "".concat(i),
          rules: [{
            required: !0,
            message: "通讯方式不能为空！"
          }]
        }), e = e("detail", {
          initialValue: l || "",
          rules: [{
            validator: (0, _validate.noSpaceLengthValidate)(500, !1, null)
          }]
        });
        return _react.default.createElement("div", {
          className: "interface-detail"
        }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement("div", {
          className: "interface-detail-name"
        }, _react.default.createElement("div", {
          className: "interface-detail-title"
        }, _react.default.createElement("label", null, "基本信息"), 1 === d ? _react.default.createElement("span", null, _react.default.createElement("div", {
          onClick: this.handleEditParam,
          className: c
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_edit.png"),
          alt: ""
        }), _react.default.createElement("label", null, "编辑")), _react.default.createElement("div", {
          onClick: this.handleEditParam,
          className: s
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_edit.png"),
          alt: ""
        }), _react.default.createElement("label", null, "确认"))) : null), _react.default.createElement("div", {
          className: u
        }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement("label", {
          className: "interface-title-name"
        }, "名称：", o)), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement("label", {
          className: "interface-title-name"
        }, "通讯方式：", i)), _react.default.createElement(_amosAntd.Row, {
          style: {
            height: "65px",
            "overflow-y": "auto"
          }
        }, _react.default.createElement("label", {
          className: "interface-title-name"
        }, "说明：", l))), _react.default.createElement("div", {
          className: f
        }, _react.default.createElement(_amosAntd.Form, {
          horizontal: !0
        }, _react.default.createElement(FormItem, {
          label: "名称: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22
          },
          style: {
            marginBottom: "10px"
          }
        }, _react.default.createElement(_amosAntd.Input, _extends({}, r, {
          style: {
            width: 250
          }
        }))), _react.default.createElement(FormItem, {
          label: "通讯方式: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22
          },
          style: {
            marginBottom: "10px"
          }
        }, _react.default.createElement(_amosFramework.Select, _extends({}, t, {
          dropdownStyle: {
            maxHeight: "200px",
            overflow: "overlay"
          },
          style: {
            width: 250,
            height: "32px"
          }
        }), n.map(function(e) {
          return _react.default.createElement(Option, {
            key: "".concat(e.id, "Option"),
            value: "".concat(e.id)
          }, e.name)
        }))), _react.default.createElement(FormItem, {
          label: "说明: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22
          },
          style: {
            marginBottom: "10px"
          }
        }, _react.default.createElement(_amosAntd.Input, _extends({}, e, {
          style: {
            width: 250
          }
        }))))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement("div", {
          className: "interface-detail-name"
        }, _react.default.createElement("div", {
          className: "interface-detail-property"
        }, _react.default.createElement("label", null, "接口参数"), 1 === d ? _react.default.createElement(_AddInterfaceProperty.default, {
          requestIntfcAttrs: this.requestIntfcAttrs,
          intfcId: a.id
        }) : null), _react.default.createElement("div", {
          className: "interface-detail-property-content"
        }, _react.default.createElement("div", {
          className: "interface-detail-property-scroll"
        }, this.fetchInterfaceProperty(d))))))
      }
    }]), r
  }();
PrivateInterfaceDetail.displayName = "PrivateInterfaceDetail", PrivateInterfaceDetail.propTypes = {
  form: _propTypes.default.any,
  callBack: _propTypes.default.func,
  carInfo: _propTypes.default.any,
  communityDatas: _propTypes.default.any
};
var _default = createForm(PrivateInterfaceDetail);
exports.default = _default, module.exports = exports.default;
