"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _amosAntd = require("amos-antd"),
  _amosFramework = require("amos-framework"),
  _ToolBar = _interopRequireDefault(require("./ToolBar")),
  _deviceService = require("../../../services/deviceService");

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 n, r, a = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (n in e) Object.prototype.hasOwnProperty.call(e, n) && ((r = o ? Object.getOwnPropertyDescriptor(e, n) : null) && (r.get || r.set) ? Object.defineProperty(a, n, r) : a[n] = e[n]);
  return a.default = e, t && t.set(e, a), a
}

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 n, r = arguments[t];
      for (n in r) Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n])
    }
    return e
  }).apply(this, arguments)
}

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

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

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var n = 0; n < t.length; n++) {
    var r = t[n];
    r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r)
  }
}

function _createClass(e, t, n) {
  return t && _defineProperties(e.prototype, t), n && _defineProperties(e, n), 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(n) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(n);
    return _possibleConstructorReturn(this, r ? (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, n) {
  return t in e ? Object.defineProperty(e, t, {
    value: n,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = n, e
}
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() {
    _inherits(n, _react.Component);
    var t = _createSuper(n);

    function n(e) {
      var o;
      return _classCallCheck(this, n), _defineProperty(_assertThisInitialized(o = t.call(this, e)), "setOncontextmenu", function() {
        document.oncontextmenu = function(e) {
          return !1
        }
      }), _defineProperty(_assertThisInitialized(o), "_resize", function() {
        o.onscroll()
      }), _defineProperty(_assertThisInitialized(o), "onscroll", function(e) {
        o.state.rightClickNodeTreeItem && o.setState({
          rightClickNodeTreeItem: null
        })
      }), _defineProperty(_assertThisInitialized(o), "queryRiskSourceTree", function(e) {}), _defineProperty(_assertThisInitialized(o), "onSelect", function(e, t) {}), _defineProperty(_assertThisInitialized(o), "queryPLCChannelList", function() {
        (0, _deviceService.getChannelByType)("IEC_SERVER").then(function(e) {
          o.setState({
            channels: e
          })
        })
      }), _defineProperty(_assertThisInitialized(o), "refeshPLCDetail", function(e) {}), _defineProperty(_assertThisInitialized(o), "questItemsData", function(e, t) {
        return console.log(e), e ? void(0, _deviceService.getIecChannelPoint)(e, t).then(function(e) {
          "yx" === t ? o.setState({
            yxDataSource: e
          }) : "yc" === t && o.setState({
            ycDataSource: e
          })
        }) : (o.setState({
          yxDataSource: []
        }), void o.setState({
          ycDataSource: []
        }))
      }), _defineProperty(_assertThisInitialized(o), "queryPLCListData", function(e, t, n) {}), _defineProperty(_assertThisInitialized(o), "onClick", function(e, t) {}), _defineProperty(_assertThisInitialized(o), "onToolBarClick", function(e) {
        var t, n, r, a;
        "point-1" === e ? o.state.selectedNode ? o.setState({
          modal: !0,
          toolBarFlag: e
        }) : _amosFramework.message.danger("请选择通道") : "point-3" === e ? 1 < (t = o.state.selectedRows).length ? _amosFramework.message.danger("行数大于1，请重新选择") : t.length < 1 ? _amosFramework.message.danger("请重新选择数据项") : o.setState({
          modal: !0,
          toolBarFlag: e,
          form: t[0]
        }) : "point-2" === e ? (n = o.state.selectedRowKeys, o.deletePoints(n)) : "point-5" === e ? (n = o.state, r = n.selectedNode, a = n.pointType, (0, _deviceService.deleteIecChannelPoint)(r, a).then(function(e) {
          _amosFramework.message.success("操作成功"), o.questItemsData(r, a)
        })) : "point-6" === e && (0, _deviceService.downloadIecTmpl)()
      }), _defineProperty(_assertThisInitialized(o), "deletePoints", function(e) {
        var t = o.state,
          n = t.selectedNode,
          r = t.pointType;
        (0, _deviceService.deletePoint)(e).then(function(e) {
          _amosFramework.message.success("操作成功"), o.questItemsData(n, r)
        })
      }), _defineProperty(_assertThisInitialized(o), "onSelectTreeNode", function(e, t) {
        t = t.selectedNodes;
        console.log(t), o.setState({
          selectedNode: t[0].props.channelNo,
          selectedKeys: e,
          pointType: "yx"
        }), o.questItemsData(t[0].props.channelNo, "yx")
      }), _defineProperty(_assertThisInitialized(o), "reload", function() {
        var e = o.state,
          t = e.selectedNode,
          e = e.pointType;
        o.questItemsData(t, e)
      }), _defineProperty(_assertThisInitialized(o), "getToolBar", function(e) {
        var t = o.state.selectedNode;
        return _react.default.createElement(_ToolBar.default, {
          reload: o.reload,
          onButtonClick: o.onToolBarClick,
          pointType: e,
          serviceId: t
        })
      }), _defineProperty(_assertThisInitialized(o), "readerTreeNode", function() {
        var e = o.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
          })
        }))
      }), _defineProperty(_assertThisInitialized(o), "onRightClick", function(e) {
        var t = e.event,
          e = e.node;
        o.setState({
          rightClickNodeTreeItem: {
            pageX: t.pageX,
            pageY: t.pageY
          },
          selectedNode: e.props.channelNo,
          channel: e.props.channel
        })
      }), _defineProperty(_assertThisInitialized(o), "_handleClick", function(e) {
        o.setState({
          rightClickNodeTreeItem: null
        })
      }), _defineProperty(_assertThisInitialized(o), "onButtonClick", function(e) {
        var t = o.state.selectedNode,
          n = o.state.channel;
        "1" === e ? o.setState({
          modal: !0,
          toolBarFlag: e,
          form: {}
        }) : "2" === e ? o.setState({
          modal: !0,
          toolBarFlag: e,
          form: n
        }) : "3" === e && o.channelDelete(t), o.setState({
          rightClickNodeTreeItem: null
        })
      }), _defineProperty(_assertThisInitialized(o), "channelDelete", function(e) {
        (0, _deviceService.deleteChannel)(e).then(function(e) {
          _amosFramework.message.success("删除成功"), o.queryPLCChannelList()
        })
      }), _defineProperty(_assertThisInitialized(o), "getModalHeader", function(e) {
        var t = "";
        return "2" === e ? t = "编辑通道" : "2" === e ? t = "添加通道" : "point-1" === e ? t = "新增数据项" : "point-3" === e && (t = "编辑数据项"), t
      }), _defineProperty(_assertThisInitialized(o), "getNodeTreeRightClickMenu", function() {
        var e = _objectSpread({}, o.state.rightClickNodeTreeItem),
          t = e.pageX,
          n = e.pageY,
          r = o.state.selectedNode,
          e = document.body.offsetHeight;
        0 < e - (n + 120) || (n = e - 120);
        n = {
          position: "absolute",
          left: "".concat(t, "px"),
          top: "".concat(n - 45, "px"),
          backgroundColor: "#ffffff",
          border: "solid",
          height: "70px",
          borderWidth: "1px",
          borderColor: "#c9c9c9"
        }, r = _react.default.createElement("div", {
          style: n
        }, r ? _react.default.createElement(_amosFramework.Button, {
          onClick: function() {
            return o.onButtonClick("2")
          },
          className: "risk-model-button",
          transparent: !0
        }, "编辑") : _react.default.createElement(_amosFramework.Button, {
          onClick: function() {
            return o.onButtonClick("1")
          },
          className: "risk-model-button",
          transparent: !0
        }, "添加"), r ? _react.default.createElement(_amosFramework.Button, {
          onClick: function() {
            return o.onButtonClick("3")
          },
          className: "risk-model-button",
          transparent: !0
        }, "删除") : "");
        return o.state.rightClickNodeTreeItem ? r : ""
      }), _defineProperty(_assertThisInitialized(o), "onOk", function() {
        var t, n, e = o.state.form,
          r = o.state.toolBarFlag;
        "1" === r || "2" === r ? (e.serviceType = "IEC_SERVER", (0, _deviceService.createChannel)(e).then(function(e) {
          e ? _amosFramework.message.danger(e) : (_amosFramework.message.success("操作成功"), o.setState({
            modal: !1
          }), o.queryPLCChannelList())
        })) : "point-1" !== r && "point-3" !== r || (t = o.state.selectedNode, n = o.state.pointType, e.channelNo = t, e.pointType = n, (0, _deviceService.addPoint)(e).then(function(e) {
          _amosFramework.message.success("操作成功"), o.setState({
            modal: !1
          }), o.questItemsData(t, n)
        }))
      }), _defineProperty(_assertThisInitialized(o), "cancel", function() {
        o.setState({
          modal: !1
        })
      }), _defineProperty(_assertThisInitialized(o), "getModalFooter", function() {
        return [_react.default.createElement(_amosFramework.Button, {
          className: "amos-btn-minor",
          key: "cancel",
          onClick: o.cancel
        }, "取消"), _react.default.createElement(_amosFramework.Button, {
          key: "ok",
          onClick: function() {
            return o.onOk()
          }
        }, "确定")]
      }), _defineProperty(_assertThisInitialized(o), "onChange", function(e, t) {
        t = t.target.value, t = _extends({}, o.state.form, _defineProperty({}, e, t));
        o.setState({
          form: t
        })
      }), _defineProperty(_assertThisInitialized(o), "getContext", function(e) {
        var t = o.state.form,
          n = o.state.rules,
          r = {
            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 o.form = e
          },
          model: t,
          rules: n
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "通道名称"),
          field: "name"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.name,
          placeholder: "请输入通道名称",
          onChange: function(e) {
            return o.onChange("name", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "对端地址"),
          field: "ip"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.ip,
          placeholder: "请输入对端地址",
          onChange: function(e) {
            return o.onChange("ip", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "本地端口"),
          field: "port"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.port,
          placeholder: "请输入端口号",
          onChange: function(e) {
            return o.onChange("port", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "公共地址",
          field: "commonAddress"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.commonAddress,
          placeholder: "请输入公共地址",
          onChange: function(e) {
            return o.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 o.form = e
          },
          model: t,
          rules: n
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "数据项名称"),
          field: "name"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.name,
          placeholder: "请输入通道名称",
          onChange: function(e) {
            return o.onChange("name", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "数据项编码"),
          field: "pointCode"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.pointCode,
          placeholder: "请输入数据项编码",
          onChange: function(e) {
            return o.onChange("pointCode", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "信息地址"),
          field: "originatorAddress"
        }, r), _react.default.createElement(_amosFramework.Input, {
          value: t.originatorAddress,
          placeholder: "请输入信息地址",
          onChange: function(e) {
            return o.onChange("originatorAddress", e)
          }
        }))) : ""
      }), _defineProperty(_assertThisInitialized(o), "onPointTypeChange", function(e, t) {
        e = _extends({}, o.state.form, {
          pointType: e
        });
        o.setState({
          form: e
        })
      }), _defineProperty(_assertThisInitialized(o), "onSelectChange", function(e, t) {
        o.setState({
          selectedRowKeys: e,
          selectedRows: t
        })
      }), _defineProperty(_assertThisInitialized(o), "handleChange", function(e) {
        o.setState({
          pointType: e
        });
        var t = o.state.selectedNode;
        o.questItemsData(t, e)
      }), o.pageConfig = {
        pageNumber: 0,
        pageSize: 10
      }, o.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: "请输入端口"
          }]
        }
      }, o
    }
    return _createClass(n, [{
      key: "componentDidMount",
      value: function() {
        document.addEventListener("click", this._handleClick), window.addEventListener("resize", this._resize), this.setOncontextmenu(), this.queryPLCChannelList()
      }
    }, {
      key: "componentWillReceiveProps",
      value: function() {}
    }, {
      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,
          n = t.selectedKeys,
          r = t.selectedNode,
          a = t.toolBarFlag,
          o = t.selectedRowKeys,
          i = t.pointType,
          t = t.modal,
          o = {
            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: n,
          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: i,
          defaultActiveKey: i,
          onChange: this.handleChange,
          tabBarExtraContent: this.getToolBar(i)
        }, _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: o,
          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: o,
          bordered: !0,
          dataSource: this.state.ycDataSource
        })))))), _react.default.createElement(_amosFramework.Modal, {
          header: this.getModalHeader(a),
          visible: t,
          className: "risk-model-model",
          destroyContent: !0,
          width: "30%",
          content: this.getContext(a),
          onCancel: function() {
            return e.cancel()
          },
          onOk: function() {
            return e.onOk()
          },
          footer: this.getModalFooter(),
          outterClosable: !1
        }), this.getNodeTreeRightClickMenu())
      }
    }]), n
  }();
IEC104ClientManager.displayName = "IEC104ClientManager", IEC104ClientManager.propTypes = {};
var _default = IEC104ClientManager;
exports.default = IEC104ClientManager, module.exports = exports.default;
