"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 _extends3 = _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")), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _ToolBar = _interopRequireDefault(require("./ToolBar")), _deviceService = require("../../../services/deviceService");

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

function ownKeys(e, t) {
  var a = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var r = Object.getOwnPropertySymbols(e);
    t && (r = r.filter((function(t) {
      return Object.getOwnPropertyDescriptor(e, t).enumerable;
    }))), a.push.apply(a, r);
  }
  return a;
}

function _objectSpread(e) {
  for (var t = 1; t < arguments.length; t++) {
    var a = null != arguments[t] ? arguments[t] : {};
    t % 2 ? ownKeys(Object(a), !0).forEach((function(t) {
      (0, _defineProperty2.default)(e, t, a[t]);
    })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(a)) : ownKeys(Object(a)).forEach((function(t) {
      Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(a, t));
    }));
  }
  return e;
}

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

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 = _amosFramework.Form.Item, TabPane = _amosAntd.Tabs.TabPane, TreeNode = _amosFramework.Tree.TreeNode, TabList = _amosAntd.Tabs.TabList, Tab = _amosAntd.Tabs.Tab, TabPanel = _amosAntd.Tabs.TabPanel, Option = _amosFramework.Select.Option, tableColumns = [ {
  title: "名称",
  dataIndex: "name",
  key: "name"
}, {
  title: "编码",
  dataIndex: "pointCode",
  key: "pointCode"
}, {
  title: "地址",
  dataIndex: "originatorAddress",
  key: "originatorAddress"
}, {
  title: "值",
  dataIndex: "value",
  key: "value"
} ], IEC104ClientManager = function(e) {
  (0, _inherits2.default)(a, e);
  var t = _createSuper(a);
  function a(e) {
    var r;
    return (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(r), "setOncontextmenu", (function() {
      document.oncontextmenu = function(e) {
        return !1;
      };
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "_resize", (function() {
      r.onscroll();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onscroll", (function(e) {
      r.state.rightClickNodeTreeItem && r.setState({
        rightClickNodeTreeItem: null
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "queryRiskSourceTree", (function(e) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onSelect", (function(e, t) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "queryPLCChannelList", (function() {
      (0, _deviceService.getChannelByType)("IEC_CLIENT").then((function(e) {
        r.setState({
          channels: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "refeshPLCDetail", (function(e) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "questItemsData", (function(e, t) {
      if (console.log(e), !e) return r.setState({
        yxDataSource: []
      }), void r.setState({
        ycDataSource: []
      });
      (0, _deviceService.getIecChannelPoint)(e, t).then((function(e) {
        "yx" === t ? r.setState({
          yxDataSource: e
        }) : "yc" === t && r.setState({
          ycDataSource: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "queryPLCListData", (function(e, t, a) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClick", (function(e, t) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onToolBarClick", (function(e) {
      if ("point-1" === e) {
        if (!r.state.selectedNode) return void _amosFramework.message.danger("请选择通道");
        r.setState({
          modal: !0,
          toolBarFlag: e
        });
      } else if ("point-3" === e) {
        var t = r.state.selectedRows;
        if (t.length > 1) return void _amosFramework.message.danger("行数大于1，请重新选择");
        if (t.length < 1) return void _amosFramework.message.danger("请重新选择数据项");
        r.setState({
          modal: !0,
          toolBarFlag: e,
          form: t[0]
        });
      } else if ("point-2" === e) {
        var a = r.state.selectedRowKeys;
        r.deletePoints(a);
      } else if ("point-5" === e) {
        var n = r.state, o = n.selectedNode, l = n.pointType;
        (0, _deviceService.deleteIecChannelPoint)(o, l).then((function(e) {
          _amosFramework.message.success("操作成功"), r.questItemsData(o, l);
        }));
      } else "point-6" === e && (0, _deviceService.downloadIecTmpl)();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "deletePoints", (function(e) {
      var t = r.state, a = t.selectedNode, n = t.pointType;
      (0, _deviceService.deletePoint)(e).then((function(e) {
        _amosFramework.message.success("操作成功"), r.questItemsData(a, n);
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onSelectTreeNode", (function(e, t) {
      var a = t.selectedNodes;
      console.log(a), r.setState({
        selectedNode: a[0].props.channelNo,
        selectedKeys: e,
        pointType: "yx"
      }), r.questItemsData(a[0].props.channelNo, "yx");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "reload", (function() {
      var e = r.state, t = e.selectedNode, a = e.pointType;
      r.questItemsData(t, a);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getToolBar", (function(e) {
      var t = r.state.selectedNode;
      return _react.default.createElement(_ToolBar.default, {
        reload: r.reload,
        onButtonClick: r.onToolBarClick,
        pointType: e,
        serviceId: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "readerTreeNode", (function() {
      var e = r.state.channels;
      return _react.default.createElement(TreeNode, {
        icon: _react.default.createElement(_amosFramework.Icon, {
          icon: "folder"
        }),
        title: "客户端通道",
        key: "0-0"
      }, e.map((function(e) {
        return _react.default.createElement(TreeNode, {
          icon: _react.default.createElement(_amosFramework.Icon, {
            icon: "file-leaf"
          }),
          channel: e,
          channelNo: e.channelNo,
          title: e.name,
          key: e.id
        });
      })));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onRightClick", (function(e) {
      var t = e.event, a = e.node;
      r.setState({
        rightClickNodeTreeItem: {
          pageX: t.pageX,
          pageY: t.pageY
        },
        selectedNode: a.props.channelNo,
        channel: a.props.channel
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "_handleClick", (function(e) {
      r.setState({
        rightClickNodeTreeItem: null
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onButtonClick", (function(e) {
      var t = r.state.selectedNode, a = r.state.channel;
      "1" === e ? r.setState({
        modal: !0,
        toolBarFlag: e,
        form: {}
      }) : "2" === e ? r.setState({
        modal: !0,
        toolBarFlag: e,
        form: a
      }) : "3" === e && r.channelDelete(t), r.setState({
        rightClickNodeTreeItem: null
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "channelDelete", (function(e) {
      (0, _deviceService.deleteChannel)(e).then((function(e) {
        _amosFramework.message.success("删除成功"), r.queryPLCChannelList();
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getModalHeader", (function(e) {
      var t = "";
      return "2" === e ? t = "编辑通道" : "2" === e ? t = "添加通道" : "point-1" === e ? t = "新增数据项" : "point-3" === e && (t = "编辑数据项"), 
      t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getNodeTreeRightClickMenu", (function() {
      var e = _objectSpread({}, r.state.rightClickNodeTreeItem), t = e.pageX, a = e.pageY, n = r.state.selectedNode, o = document.body.offsetHeight;
      !(o - (a + 120) > 0) && (a = o - 120);
      var l = {
        position: "absolute",
        left: "".concat(t, "px"),
        top: "".concat(a - 45, "px"),
        backgroundColor: "#ffffff",
        border: "solid",
        height: "70px",
        borderWidth: "1px",
        borderColor: "#c9c9c9"
      }, i = _react.default.createElement("div", {
        style: l
      }, n ? _react.default.createElement(_amosFramework.Button, {
        onClick: function() {
          return r.onButtonClick("2");
        },
        className: "risk-model-button",
        transparent: !0
      }, "编辑") : _react.default.createElement(_amosFramework.Button, {
        onClick: function() {
          return r.onButtonClick("1");
        },
        className: "risk-model-button",
        transparent: !0
      }, "添加"), n ? _react.default.createElement(_amosFramework.Button, {
        onClick: function() {
          return r.onButtonClick("3");
        },
        className: "risk-model-button",
        transparent: !0
      }, "删除") : "");
      return r.state.rightClickNodeTreeItem ? i : "";
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onOk", (function() {
      var e = r.state.form, t = r.state.toolBarFlag;
      if ("1" === t || "2" === t) e.serviceType = "IEC_CLIENT", (0, _deviceService.createChannel)(e).then((function(e) {
        e ? _amosFramework.message.danger(e) : (_amosFramework.message.success("操作成功"), 
        r.setState({
          modal: !1
        }), r.queryPLCChannelList());
      })); else if ("point-1" === t || "point-3" === t) {
        var a = r.state.selectedNode, n = r.state.pointType;
        e.channelNo = a, e.pointType = n, (0, _deviceService.addPoint)(e).then((function(e) {
          _amosFramework.message.success("操作成功"), r.setState({
            modal: !1
          }), r.questItemsData(a, n);
        }));
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "cancel", (function() {
      r.setState({
        modal: !1
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getModalFooter", (function() {
      return [ _react.default.createElement(_amosFramework.Button, {
        className: "amos-btn-minor",
        key: "cancel",
        onClick: r.cancel
      }, "取消"), _react.default.createElement(_amosFramework.Button, {
        key: "ok",
        onClick: function() {
          return r.onOk();
        }
      }, "确定") ];
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onChange", (function(e, t) {
      var a = t.target.value, n = (0, _extends3.default)({}, r.state.form, (0, _defineProperty2.default)({}, e, a));
      r.setState({
        form: n
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getContext", (function(e) {
      var t = r.state.form, a = r.state.rules, n = {
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 8
          },
          className: "colspanlab"
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
          className: "colspan"
        }
      };
      return "1" === e || "2" === e ? _react.default.createElement(_amosFramework.Form, {
        style: {
          width: 300,
          padding: "30px 0 0 0"
        },
        className: "basic-demo",
        ref: function(e) {
          return r.form = e;
        },
        model: t,
        rules: a
      }, _react.default.createElement(FormItem, (0, _extends3.default)({
        label: _react.default.createElement("span", null, "通道名称"),
        field: "name"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.name,
        placeholder: "请输入通道名称",
        onChange: function(e) {
          return r.onChange("name", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends3.default)({
        label: _react.default.createElement("span", null, "对端地址"),
        field: "ip"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.ip,
        placeholder: "请输入对端地址",
        onChange: function(e) {
          return r.onChange("ip", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends3.default)({
        label: _react.default.createElement("span", null, "本地端口"),
        field: "port"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.port,
        placeholder: "请输入端口号",
        onChange: function(e) {
          return r.onChange("port", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends3.default)({
        label: "公共地址",
        field: "commonAddress"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.commonAddress,
        placeholder: "请输入公共地址",
        onChange: function(e) {
          return r.onChange("commonAddress", e);
        }
      }))) : "point-1" === e || "point-3" === e ? _react.default.createElement(_amosFramework.Form, {
        style: {
          width: 300,
          padding: "30px 0 0 0"
        },
        className: "basic-demo",
        ref: function(e) {
          return r.form = e;
        },
        model: t,
        rules: a
      }, _react.default.createElement(FormItem, (0, _extends3.default)({
        label: _react.default.createElement("span", null, "数据项名称"),
        field: "name"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.name,
        placeholder: "请输入通道名称",
        onChange: function(e) {
          return r.onChange("name", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends3.default)({
        label: _react.default.createElement("span", null, "数据项编码"),
        field: "pointCode"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.pointCode,
        placeholder: "请输入数据项编码",
        onChange: function(e) {
          return r.onChange("pointCode", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends3.default)({
        label: _react.default.createElement("span", null, "信息地址"),
        field: "originatorAddress"
      }, n), _react.default.createElement(_amosFramework.Input, {
        value: t.originatorAddress,
        placeholder: "请输入信息地址",
        onChange: function(e) {
          return r.onChange("originatorAddress", e);
        }
      }))) : "";
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onPointTypeChange", (function(e, t) {
      var a = (0, _extends3.default)({}, r.state.form, {
        pointType: e
      });
      r.setState({
        form: a
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onSelectChange", (function(e, t) {
      r.setState({
        selectedRowKeys: e,
        selectedRows: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleChange", (function(e) {
      r.setState({
        pointType: e
      });
      var t = r.state.selectedNode;
      r.questItemsData(t, e);
    })), r.pageConfig = {
      pageNumber: 0,
      pageSize: 10
    }, r.state = {
      yxDataSource: [],
      yCDataSource: [],
      selectedKeys: [],
      channels: [],
      form: {},
      modal: !1,
      rules: {
        name: [ {
          required: !0,
          message: "请输入通道名称"
        } ],
        commonAddress: [ {
          required: !0,
          message: "请输入公共地址"
        } ],
        ip: [ {
          required: !0,
          message: "请输入IP地址"
        } ],
        port: [ {
          required: !0,
          message: "请输入端口"
        } ]
      }
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      document.addEventListener("click", this._handleClick), window.addEventListener("resize", this._resize), 
      this.setOncontextmenu(), this.queryPLCChannelList();
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {}
  }, {
    key: "ccomponentWillUnmount",
    value: function() {
      var e = document.getElementsByClassName("channel")[0], t = document.getElementsByClassName("device-data-items")[0];
      e && e.removeEventListener("click", this._handleClick), t && t.removeEventListener("click", this._handleClick), 
      window.addEventListener("resize", this._resize);
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.state, a = t.selectedKeys, r = t.selectedNode, n = t.toolBarFlag, o = t.selectedRowKeys, l = t.pointType, i = t.modal, s = {
        selectedRowKeys: o,
        onChange: this.onSelectChange
      };
      return _react.default.createElement("div", null, _react.default.createElement(_amosFramework.SplitPane, {
        percentage: !0,
        mainPaneMinSize: 15,
        secondaryMinSize: 85
      }, _react.default.createElement("div", {
        className: "channel"
      }, _react.default.createElement(_amosFramework.Tree, {
        showIcon: !0,
        defaultExpandAll: !0,
        selectedKeys: a,
        onSelect: this.onSelectTreeNode,
        onRightClick: this.onRightClick,
        defaultSelectedKeys: [ "0-0-0" ]
      }, this.readerTreeNode())), _react.default.createElement("div", {
        className: "device-data-items"
      }, _react.default.createElement("div", {
        className: "plc-title"
      }, _react.default.createElement("div", {
        className: "con-eva-key"
      }, "编号: "), _react.default.createElement("div", {
        className: "con-eva-value"
      }, r)), _react.default.createElement(_amosFramework.Divider, {
        className: "plc-divider"
      }), _react.default.createElement("div", {
        className: "plc-body"
      }, _react.default.createElement(_amosAntd.Tabs, {
        className: "quyu-info-tab",
        activeKey: l,
        defaultActiveKey: l,
        onChange: this.handleChange,
        tabBarExtraContent: this.getToolBar(l)
      }, _react.default.createElement(TabPane, {
        tab: _react.default.createElement("span", null, "遥信转发表"),
        key: "yx"
      }, _react.default.createElement(_amosAntd.Table, {
        columns: tableColumns,
        rowKey: function(e) {
          return e.id;
        },
        rowSelection: s,
        bordered: !0,
        dataSource: this.state.yxDataSource
      })), _react.default.createElement(TabPane, {
        tab: _react.default.createElement("span", null, "遥测转发表"),
        key: "yc"
      }, _react.default.createElement(_amosAntd.Table, {
        columns: tableColumns,
        rowKey: function(e) {
          return e.id;
        },
        rowSelection: s,
        bordered: !0,
        dataSource: this.state.ycDataSource
      })))))), _react.default.createElement(_amosFramework.Modal, {
        header: this.getModalHeader(n),
        visible: i,
        className: "risk-model-model",
        destroyContent: !0,
        width: "30%",
        content: this.getContext(n),
        onCancel: function() {
          return e.cancel();
        },
        onOk: function() {
          return e.onOk();
        },
        footer: this.getModalFooter(),
        outterClosable: !1
      }), this.getNodeTreeRightClickMenu());
    }
  } ]), a;
}(_react.Component);

IEC104ClientManager.displayName = "IEC104ClientManager", IEC104ClientManager.propTypes = {};

var _default = IEC104ClientManager;

exports.default = _default;