"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")), _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 _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 = {}, l = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var n in e) if ("default" !== n && Object.prototype.hasOwnProperty.call(e, n)) {
    var i = l ? Object.getOwnPropertyDescriptor(e, n) : null;
    i && (i.get || i.set) ? Object.defineProperty(a, n, i) : a[n] = e[n];
  }
  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 l = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, l);
    } 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 FormItem = _amosAntd.Form.Item, createForm = _amosAntd.Form.create(), Option = _amosFramework.Select.Option, PrivateInterfaceDetail = 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), "requestIntfcAttrs", (function() {
      var e = a.props.carInfo.id, 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) {
        a.setState({
          propertyList: e.dataList.content
        }), a.fetchInterfaceProperty();
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleEditParam", (function(e) {
      var t = a.props.form.getFieldValue("commType"), r = a.props.form.getFieldValue("detail"), l = a.props.form.getFieldValue("name"), n = a.props.communityDatas, i = null, o = null;
      if (isNaN(t)) {
        for (var c = 0; c < n.length; c++) if ((o = n[c]).name === t) {
          t = o.id, i = o;
          break;
        }
      } else for (var s = 0; s < n.length; s++) if ((o = n[s]).id === parseInt(t)) {
        t = o.id, i = o;
        break;
      }
      a.setState({
        textEdit: !a.state.textEdit
      }), a.state.textEdit && a.props.form.validateFields((function(e, n) {
        if (e) a.setState({
          textEdit: !0
        }); else {
          var o = a.props.carInfo, c = (0, _extends2.default)(o, {
            dicIdCommMode: t,
            remark: r,
            attributes: null,
            communityProtocol: i,
            name: l
          });
          a.submitBasicData(c);
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "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("编辑成功") : (a.setState({
          textEdit: !0
        }), _amosFramework.message.danger("编辑失败！"));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleAddProperty", (function(e) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "fetchInterfaceProperty", (function(e) {
      var t = a.state.propertyList, r = [];
      return t.map((function(t) {
        r.push(_react.default.createElement(_InterfacePropertyCell.default, {
          visibility: e,
          key: t.id,
          requestIntfcAttrs: a.requestIntfcAttrs,
          propertyName: "null",
          deleteInterfaceProperty: a.deleteInterfaceProperty,
          propertyInfo: t
        }));
      })), r;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "deleteInterfaceProperty", (function(e) {
      var t = a.delProperty;
      _amosAntd.Modal.confirm({
        title: "删除",
        content: "是否删除所选属性？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {
          t(e);
        },
        onCancel: function() {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "delProperty", (function(e) {
      var t = "".concat(_urlConsts.OltSerUrl.intfcAttrDelete, "/").concat(e);
      _processor.AmosFetch.del(t).then((function(e) {
        if (e.ok) return e.text();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        _amosFramework.message.success("删除成功！"), a.requestIntfcAttrs();
      }));
    })), a.state = {
      textEdit: !1,
      propertyList: []
    }, a;
  }
  return (0, _createClass2.default)(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, l = r.communityDatas, n = a ? a.name : "", i = a && a.communityProtocol ? a.communityProtocol.name : "", o = 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", d = !1 === t ? "interface-detail-title-content-hidden" : "interface-detail-title-content", f = a.visibility;
      console.log(a);
      var p = e("name", {
        initialValue: n || "",
        rules: [ {
          required: !0,
          message: "名称不能为空！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
        } ]
      }), m = e("commType", {
        initialValue: "".concat(i),
        rules: [ {
          required: !0,
          message: "通讯方式不能为空！"
        } ]
      }), _ = e("detail", {
        initialValue: o || "",
        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 === f ? _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"
      }, "名称：", n)), _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"
      }, "说明：", o))), _react.default.createElement("div", {
        className: d
      }, _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, (0, _extends2.default)({}, p, {
        style: {
          width: 250
        }
      }))), _react.default.createElement(FormItem, {
        label: "通讯方式: ",
        labelCol: {
          span: 2
        },
        wrapperCol: {
          span: 22
        },
        style: {
          marginBottom: "10px"
        }
      }, _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({}, m, {
        dropdownStyle: {
          maxHeight: "200px",
          overflow: "overlay"
        },
        style: {
          width: 250,
          height: "32px"
        }
      }), l.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, (0, _extends2.default)({}, _, {
        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 === f ? _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(f))))));
    }
  } ]), r;
}(_react.Component);

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;