"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")), _CellOperatePanel = _interopRequireDefault(require("./CellOperatePanel")), _urlConsts = require("../../../../consts/urlConsts"), _amosAntd = require("amos-antd"), _processor = require("../../../../utils/processor"), _amosFramework = require("amos-framework");

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 = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var n = i ? Object.getOwnPropertyDescriptor(e, l) : null;
    n && (n.get || n.set) ? Object.defineProperty(a, l, n) : a[l] = e[l];
  }
  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 i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } 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;
  }
}

require("./commonDeviceCell.scss");

var createForm = _amosAntd.Form.create(), FormItem = _amosAntd.Form.Item, formItemLayout = {
  labelCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 6
    }
  },
  wrapperCol: {
    xs: {
      span: 24
    },
    sm: {
      span: 16
    }
  }
}, CommonDeviceCell = 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), "onIntoViewPanel", (function() {
      var e = a.props, t = e.subviewInfo, r = e.treeName, i = e.treeKey, l = e.orgId;
      t.orgName = r, t.expandedKeys = i, t.orgId = l, a.props.updateView("2", t);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getBodyBottomContent", (function() {
      var e = a.props, t = e.type, r = e.subviewInfo, i = [];
      return 1 === t ? i.push(_react.default.createElement("div", {
        style: {
          paddingTop: "10px"
        }
      }, "创建一个您的新视图")) : 2 === t && (i.push(_react.default.createElement("div", {
        style: {
          paddingTop: "10px"
        }
      }, "说明：房间设备最主要的是监控设备")), i.push(_react.default.createElement(_CellOperatePanel.default, (0, 
      _extends2.default)({
        device: r,
        showEditPanel: a.showEditPanel,
        delView: a.delView
      }, a.props)))), i;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getImg", (function() {
      var e = [], t = a.props.imgUrl;
      return void 0 === t ? e.push(_react.default.createElement("img", {
        src: "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/equip-view.png"),
        alt: ""
      })) : e.push(_react.default.createElement("img", {
        src: "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/").concat(t),
        alt: ""
      })), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "delView", (function(e) {
      var t = a.props, r = t.delSubgraph, i = t.subviewInfo;
      _amosAntd.Modal.confirm({
        title: "删除视图",
        content: "是否删除信息？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {
          r(i.id);
        },
        onCancel: function() {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "clickCard", (function(e) {
      e.stopPropagation();
      var t = a.props.type;
      1 === t ? a.setState({
        visible: !0
      }) : 2 === t && a.onIntoViewPanel();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "showEditPanel", (function() {
      a.setState({
        visible: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleSubmit", (function() {
      a.props.form.validateFields((function(e, t) {
        if (!e) {
          var r = a.props.subviewInfo, i = {
            name: t.newNodeName,
            orgCode: a.props.orgId
          };
          void 0 !== r.id && (0, _extends2.default)(i, {
            id: r.id
          }), a.saveSubgraphData(i);
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handCancel", (function() {
      a.props.form.resetFields(), a.setState({
        visible: !1
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "saveSubgraphData", (function(e) {
      _processor.AmosFetch.post(_urlConsts.OltSerUrl.addSubgraph, {
        data: e
      }).then((function(e) {
        if (e.ok) return e.text();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        var r = JSON.parse(t);
        "SUCCESS" === r.result ? -1 === r.dataList ? _amosFramework.message.danger("视图名称重复") : (a.props.getSubviewByOrgCode(e.orgCode), 
        _amosFramework.message.success("操作成功"), a.props.form.resetFields(), a.setState({
          visible: !1
        })) : _amosFramework.message.danger("操作失败：".concat(r.message));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "checkValidate", (function(e, t, r) {
      new RegExp(/^\S*$/).test(t) ? r() : r("支持1-20位非空格字符！");
    })), a.state = {
      visible: !1
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "render",
    value: function() {
      var e = this.props, t = e.type, r = e.subviewInfo, a = (0, this.props.form.getFieldProps)("newNodeName", {
        initialValue: void 0 === r.id ? "" : r.name,
        rules: [ {
          required: !0,
          message: "支持1-20位非空格字符！"
        }, {
          validator: this.checkValidate
        } ]
      });
      return _react.default.createElement("div", {
        tabIndex: "0",
        className: "subgraph-card-root",
        onClick: this.clickCard
      }, _react.default.createElement("div", {
        className: "subgraph-card-head"
      }, _react.default.createElement("div", {
        className: "subgraph-card-head-text"
      }, void 0 !== r ? r.name : "")), _react.default.createElement("div", {
        className: "subgraph-card-body"
      }, _react.default.createElement("div", {
        className: "subgraph-card-body-center"
      }, 1 === t ? _react.default.createElement("img", {
        src: require("./../../../../assets/iot/deviceManage/add_template.png"),
        alt: ""
      }) : this.getImg()), _react.default.createElement("div", {
        className: "subgraph-card-body-text"
      }, this.getBodyBottomContent())), _react.default.createElement(_amosAntd.Modal, {
        className: "subgraph-modal",
        maskClosable: !1,
        title: "创建视图",
        closable: !0,
        visible: this.state.visible,
        width: 350,
        footer: null,
        onCancel: this.handCancel
      }, _react.default.createElement(_amosAntd.Form, {
        horizontal: !0
      }, _react.default.createElement(FormItem, (0, _extends2.default)({}, formItemLayout, {
        hasFeedback: !0,
        label: "名称: "
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({}, a, {
        placeholder: "名称（支持1-20位非空格字符）"
      })))), _react.default.createElement("div", {
        className: "modal-operate-root"
      }, _react.default.createElement("div", {
        className: "modal-operate-clone",
        onClick: this.handCancel
      }, "取消"), _react.default.createElement("div", {
        className: "modal-operate-view",
        onClick: this.handleSubmit
      }, "确定"))));
    }
  } ]), r;
}(_react.Component);

CommonDeviceCell.displayName = "CommonDeviceCell", CommonDeviceCell.propTypes = {
  form: _propTypes.default.any,
  type: _propTypes.default.number,
  imgUrl: _propTypes.default.string,
  clickDeviceTemplate: _propTypes.default.func,
  subviewInfo: _propTypes.default.func,
  cardData: _propTypes.default.any,
  updateAddView: _propTypes.default.func,
  getSubviewByOrgCode: _propTypes.default.func,
  updateView: _propTypes.default.func,
  orgId: _propTypes.default.any,
  delSubgraph: _propTypes.default.func
};

var _default = createForm(CommonDeviceCell);

exports.default = _default;