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

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

function _objectSpread(t) {
  for (var e = 1; e < arguments.length; e++) {
    var r = null != arguments[e] ? arguments[e] : {};
    e % 2 ? ownKeys(Object(r), !0).forEach(function(e) {
      _defineProperty(t, e, r[e])
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach(function(e) {
      Object.defineProperty(t, e, Object.getOwnPropertyDescriptor(r, 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 r = 0; r < t.length; r++) {
    var n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
  }
}

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 n = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, n ? (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 = _amosFramework.Form.Item,
  TabPane = _amosAntd.Tabs.TabPane,
  TreeNode = _amosFramework.Tree.TreeNode,
  TabList = _amosAntd.Tabs.TabList,
  Tab = _amosAntd.Tabs.Tab,
  TabPanel = _amosAntd.Tabs.TabPanel,
  tableColumns = [{
    title: "名称",
    dataIndex: "name",
    key: "name"
  }, {
    title: "编码",
    dataIndex: "pointCode",
    key: "pointCode"
  }, {
    title: "地址",
    dataIndex: "originatorAddress",
    key: "originatorAddress"
  }, {
    title: "值",
    dataIndex: "value",
    key: "value"
  }],
  PLCManager = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var a;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(a = t.call(this, e)), "setOncontextmenu", function() {
        document.oncontextmenu = function(e) {
          return !1
        }
      }), _defineProperty(_assertThisInitialized(a), "_resize", function() {
        a.onscroll()
      }), _defineProperty(_assertThisInitialized(a), "onscroll", function(e) {
        a.state.rightClickNodeTreeItem && a.setState({
          rightClickNodeTreeItem: null
        })
      }), _defineProperty(_assertThisInitialized(a), "queryRiskSourceTree", function(e) {}), _defineProperty(_assertThisInitialized(a), "onSelect", function(e, t) {}), _defineProperty(_assertThisInitialized(a), "queryPLCChannelList", function() {
        (0, _deviceService.getChannelByType)("OPC_CLIENT").then(function(e) {
          a.setState({
            channels: e
          })
        })
      }), _defineProperty(_assertThisInitialized(a), "refeshPLCDetail", function(e) {}), _defineProperty(_assertThisInitialized(a), "questItemsData", function(e) {
        console.log(e), (0, _deviceService.getChannelPoint)(e).then(function(e) {
          a.setState({
            dataSource: e
          })
        })
      }), _defineProperty(_assertThisInitialized(a), "queryPLCListData", function(e, t, r) {}), _defineProperty(_assertThisInitialized(a), "onClick", function(e, t) {}), _defineProperty(_assertThisInitialized(a), "onToolBarClick", function(e) {
        var t;
        "point-1" === e ? a.state.selectedNode ? a.setState({
          modal: !0,
          toolBarFlag: e
        }) : _amosFramework.message.danger("请选择通道") : "point-3" === e ? 1 < (t = a.state.selectedRows).length ? _amosFramework.message.danger("行数大于1，请重新选择") : t.length < 1 ? _amosFramework.message.danger("请重新选择数据项") : a.setState({
          modal: !0,
          toolBarFlag: e,
          form: t[0]
        }) : "point-2" === e && (e = a.state.selectedRowKeys, a.deletePoints(e))
      }), _defineProperty(_assertThisInitialized(a), "deletePoints", function(e) {
        var t = a.state.selectedNode;
        (0, _deviceService.deletePoint)(e).then(function(e) {
          _amosFramework.message.success("操作成功"), a.questItemsData(t)
        })
      }), _defineProperty(_assertThisInitialized(a), "onSelectTreeNode", function(e, t) {
        t = t.selectedNodes;
        console.log(t), a.setState({
          selectedNode: t[0].props.channelNo,
          selectedKeys: e
        }), a.questItemsData(t[0].props.channelNo)
      }), _defineProperty(_assertThisInitialized(a), "getToolBar", function(e) {
        return _react.default.createElement(_ToolBar.default, {
          onButtonClick: a.onToolBarClick,
          parent: e
        })
      }), _defineProperty(_assertThisInitialized(a), "readerTreeNode", function() {
        var e = a.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(a), "onRightClick", function(e) {
        var t = e.event,
          e = e.node;
        a.setState({
          rightClickNodeTreeItem: {
            pageX: t.pageX,
            pageY: t.pageY
          },
          selectedNode: e.props.channelNo,
          channel: e.props.channel
        })
      }), _defineProperty(_assertThisInitialized(a), "_handleClick", function(e) {
        a.setState({
          rightClickNodeTreeItem: null
        })
      }), _defineProperty(_assertThisInitialized(a), "onButtonClick", function(e) {
        var t = a.state.selectedNode,
          r = a.state.channel;
        "1" === e ? a.setState({
          modal: !0,
          toolBarFlag: e,
          form: {}
        }) : "2" === e ? a.setState({
          modal: !0,
          toolBarFlag: e,
          form: r
        }) : "3" === e && a.channelDelete(t), a.setState({
          rightClickNodeTreeItem: null
        })
      }), _defineProperty(_assertThisInitialized(a), "channelDelete", function(e) {
        (0, _deviceService.deleteChannel)(e).then(function(e) {
          _amosFramework.message.success("删除成功"), a.queryPLCChannelList()
        })
      }), _defineProperty(_assertThisInitialized(a), "getModalHeader", function(e) {
        var t = "";
        return "2" === e ? t = "编辑通道" : "2" === e ? t = "添加通道" : "point-1" === e ? t = "新增数据项" : "point-3" === e && (t = "编辑数据项"), t
      }), _defineProperty(_assertThisInitialized(a), "getNodeTreeRightClickMenu", function() {
        var e = _objectSpread({}, a.state.rightClickNodeTreeItem),
          t = e.pageX,
          r = e.pageY,
          n = a.state.selectedNode,
          e = document.body.offsetHeight;
        0 < e - (r + 120) || (r = e - 120);
        r = {
          position: "absolute",
          left: "".concat(t, "px"),
          top: "".concat(r - 45, "px"),
          backgroundColor: "#ffffff",
          border: "solid",
          height: "70px",
          borderWidth: "1px",
          borderColor: "#c9c9c9"
        }, n = _react.default.createElement("div", {
          style: r
        }, n ? _react.default.createElement(_amosFramework.Button, {
          onClick: function() {
            return a.onButtonClick("2")
          },
          className: "risk-model-button",
          transparent: !0
        }, "编辑") : _react.default.createElement(_amosFramework.Button, {
          onClick: function() {
            return a.onButtonClick("1")
          },
          className: "risk-model-button",
          transparent: !0
        }, "添加"), n ? _react.default.createElement(_amosFramework.Button, {
          onClick: function() {
            return a.onButtonClick("3")
          },
          className: "risk-model-button",
          transparent: !0
        }, "删除") : "");
        return a.state.rightClickNodeTreeItem ? n : ""
      }), _defineProperty(_assertThisInitialized(a), "onOk", function() {
        var t, e = a.state.form,
          r = a.state.toolBarFlag;
        "1" === r || "2" === r ? (e.serviceType = "OPC_CLIENT", (0, _deviceService.createChannel)(e).then(function(e) {
          _amosFramework.message.success("操作成功"), a.setState({
            modal: !1
          }), a.queryPLCChannelList()
        })) : "point-1" !== r && "point-3" !== r || (t = a.state.selectedNode, e.channelNo = t, (0, _deviceService.addPoint)(e).then(function(e) {
          _amosFramework.message.success("操作成功"), a.setState({
            modal: !1
          }), a.questItemsData(t)
        }))
      }), _defineProperty(_assertThisInitialized(a), "cancel", function() {
        a.setState({
          modal: !1
        })
      }), _defineProperty(_assertThisInitialized(a), "getModalFooter", function() {
        return [_react.default.createElement(_amosFramework.Button, {
          className: "amos-btn-minor",
          key: "cancel",
          onClick: a.cancel
        }, "取消"), _react.default.createElement(_amosFramework.Button, {
          key: "ok",
          onClick: function() {
            return a.onOk()
          }
        }, "确定")]
      }), _defineProperty(_assertThisInitialized(a), "onChange", function(e, t) {
        t = t.target.value, t = _extends({}, a.state.form, _defineProperty({}, e, t));
        a.setState({
          form: t
        })
      }), _defineProperty(_assertThisInitialized(a), "getContext", function(e) {
        var t = a.state.form,
          r = a.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 a.form = e
          },
          model: t,
          rules: r
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "通道名称"),
          field: "name"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.name,
          placeholder: "请输入通道名称",
          onChange: function(e) {
            return a.onChange("name", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "服务器地址"),
          field: "ip"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.ip,
          placeholder: "请输入服务器地址",
          onChange: function(e) {
            return a.onChange("ip", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "用户名"),
          field: "userName"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.userName,
          placeholder: "请输入用户名",
          onChange: function(e) {
            return a.onChange("userName", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "密码",
          field: "password"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.password,
          type: "password",
          placeholder: "请输入密码",
          onChange: function(e) {
            return a.onChange("password", 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 a.form = e
          },
          model: t,
          rules: r
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "数据项名称"),
          field: "name"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.name,
          placeholder: "请输入通道名称",
          onChange: function(e) {
            return a.onChange("name", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "itemId"),
          field: "originatorAddress"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.originatorAddress,
          placeholder: "请输入itemId",
          onChange: function(e) {
            return a.onChange("originatorAddress", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "数据项编码"),
          field: "pointCode"
        }, n), _react.default.createElement(_amosFramework.Input, {
          value: t.pointCode,
          placeholder: "请输入数据项编码",
          onChange: function(e) {
            return a.onChange("pointCode", e)
          }
        }))) : ""
      }), _defineProperty(_assertThisInitialized(a), "onSelectChange", function(e, t) {
        a.setState({
          selectedRowKeys: e,
          selectedRows: t
        })
      }), a.pageConfig = {
        pageNumber: 0,
        pageSize: 10
      }, a.state = {
        dataSource: [],
        selectedKeys: [],
        channels: [],
        form: {},
        modal: !1,
        rules: {
          name: [{
            required: !0,
            message: "请输入通道名称"
          }],
          userName: [{
            required: !0,
            message: "请输入用户名"
          }],
          ip: [{
            required: !0,
            message: "请输入IP地址"
          }],
          password: [{
            required: !0,
            message: "请输入密码"
          }]
        }
      }, a
    }
    return _createClass(r, [{
      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,
          r = t.selectedKeys,
          n = t.selectedNode,
          a = t.toolBarFlag,
          o = t.selectedRowKeys,
          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: r,
          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"
        }, n)), _react.default.createElement(_amosFramework.Divider, {
          className: "plc-divider"
        }), _react.default.createElement("div", {
          className: "plc-body"
        }, _react.default.createElement(_amosAntd.Tabs, {
          className: "quyu-info-tab",
          type: "card",
          tabBarExtraContent: this.getToolBar(this)
        }, _react.default.createElement(TabPane, {
          tab: _react.default.createElement("span", null, "数据项")
        }, _react.default.createElement(_amosAntd.Table, {
          columns: tableColumns,
          rowKey: function(e) {
            return e.id
          },
          rowSelection: o,
          bordered: !0,
          dataSource: this.state.dataSource
        })))))), _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())
      }
    }]), r
  }();
PLCManager.displayName = "PLCManager", PLCManager.propTypes = {};
var _default = PLCManager;
exports.default = PLCManager, module.exports = exports.default;
