"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 _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")), _amosAntd = require("amos-antd"), _dt2react = require("dt2react"), _processor = require("../../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../../consts/urlConsts")), _AmosGridTable = _interopRequireDefault(require("./../../common/tableComponent/table/AmosGridTable")), _AlarmDetail = _interopRequireDefault(require("./AlarmDetail"));

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

var timestampToTime = function(e) {
  var t = new Date(e);
  return "".concat(t.getFullYear(), "-") + "".concat(t.getMonth() + 1 < 10 ? "0".concat(t.getMonth() + 1) : t.getMonth() + 1, "-") + "".concat(t.getDate(), " ") + "".concat(t.getHours(), ":") + "".concat(t.getMinutes(), ":") + t.getSeconds();
}, alarmColumns = function(e) {
  return [ {
    title: "告警级别",
    dataIndex: "level",
    key: "level",
    width: "8%",
    query: !0,
    required: !0,
    primary: !0,
    st: "list",
    list: [ {
      name: "一级",
      value: 1
    }, {
      name: "二级",
      value: 2
    }, {
      name: "三级",
      value: 3
    } ],
    render: function(e) {
      return 1 === e ? "一级" : 2 === e ? "二级" : "三级";
    }
  }, {
    title: "告警类型",
    dataIndex: "type",
    key: "type",
    width: "8%",
    query: !0,
    required: !0,
    primary: !0,
    st: "list",
    list: [ {
      name: "指标越界",
      value: 1
    }, {
      name: "采集异常",
      value: 2
    }, {
      name: "设备掉线",
      value: 3
    } ],
    render: function(e) {
      return 1 === e ? "指标越界" : 2 === e ? "采集异常" : "设备掉线";
    }
  }, {
    title: "告警源",
    dataIndex: "name",
    key: "name",
    query: !0,
    required: !0,
    primary: !0,
    st: "text",
    width: "20%"
  }, {
    title: "描述",
    dataIndex: "descr",
    key: "descr",
    width: "22%"
  }, {
    title: "发生时间",
    dataIndex: "raiseTime",
    key: "raiseTime",
    width: "12%",
    render: function(e) {
      return timestampToTime(e);
    }
  }, {
    title: "清除时间",
    dataIndex: "clearTime",
    key: "clearTime",
    width: "12%",
    render: function(e) {
      return timestampToTime(e);
    }
  }, {
    title: "状态",
    dataIndex: "status",
    key: "status",
    width: "6%",
    render: function(e) {
      return 1 === e ? "未处理" : 2 === e ? "历史告警" : "已删除";
    }
  }, {
    title: "操作",
    key: "action",
    width: "10%",
    render: function(t, r) {
      return _react.default.createElement("span", null, _react.default.createElement(_AlarmDetail.default, {
        alarmInfo: r,
        clearAlarm: function() {
          return e.oneClearAlarm(r.id);
        }
      }), _react.default.createElement("label", {
        className: "delete-alarm-label",
        onClick: function() {
          return e.oneClearAlarm(r.id);
        }
      }, "删除"));
    }
  } ];
}, headHeight = 278, offsetHeight = 160, defaultHeight = 450, HistoryAlarmTable = 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), "onChange", (function(e) {
      var t = e.nodes, r = e.connections;
      a.setState({
        nodes: t,
        connections: r
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "onWindowResize", (function(e) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "oneClearAlarm", (function(e) {
      _amosAntd.Modal.confirm({
        content: "确定删除吗？",
        onCancel: function() {},
        onOk: function() {
          a.clearAlarm([ e ]);
        }
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getSelectedRows", (function(e, t) {
      a.setState({
        selectedRows: e,
        selectedRowKeys: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "addButtons", (function() {
      var e = [];
      return e.push(_react.default.createElement(_amosAntd.Button, {
        type: "primary",
        onClick: function() {
          return a.batchClearAlarm();
        }
      }, "批量删除")), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "alarmDetail", (function(e) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "clearAlarm", (function(e) {
      var t = {
        alarmIds: e,
        status: 3
      };
      _processor.AmosFetch.post(_urlConsts.default.deleteAlarm, {
        data: t
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        if ("SUCCESS" === e.result) {
          a.refreshData(a.filter);
          var t = _amosAntd.Modal.warning({
            title: "系统提示",
            content: "删除成功！",
            okText: "确定"
          });
          setTimeout((function() {
            return t.destroy();
          }), 2e3);
        } else {
          var r = _amosAntd.Modal.warning({
            title: "系统提示",
            content: "删除失败！",
            okText: "确定"
          });
          setTimeout((function() {
            return r.destroy();
          }), 2e3);
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "fetchCurrentAlarm", (function(e, t) {
      e ? a.filter = e : e = a.filter || {}, t ? "{}" === t ? a.searchCondition && (t = a.searchCondition) : a.searchCondition = t : t = a.searchCondition || {};
      var r = [];
      t.level && "-1" !== t.level && r.push({
        name: "level",
        type: "EQUAL",
        value: t.level
      }), t.type && "-1" !== t.type && r.push({
        name: "type",
        type: "EQUAL",
        value: t.type
      }), t.name && r.push({
        name: "name",
        type: "LIKE",
        value: t.name
      }), r.push({
        name: "status",
        type: "EQUAL",
        value: 2
      }), r.push({
        name: "clearTime",
        type: "ORDER BY",
        value: "DESC"
      });
      var n = "".concat(_urlConsts.default.getHistoryAlarm, "?pageNumber=").concat(e.current, "&pageSize=").concat(e.pageSize);
      _processor.AmosFetch.post(n, {
        data: r
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        var r = new Date, n = r.getHours(), i = r.getMinutes();
        i < 10 && (i = "0".concat(i));
        var l = "".concat(n, "时").concat(i, "分");
        if ("SUCCESS" === t.result) {
          var o = t.dataList.totalElements;
          null !== t.content && a.setState({
            dataList: t.dataList.content,
            refreshTime: l,
            total: o,
            filter: e
          });
        } else a.setState({
          dataList: [],
          refreshTime: l,
          total: 0,
          filter: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "batchClearAlarm", (function() {
      if (0 !== a.state.selectedRowKeys.length) _amosAntd.Modal.confirm({
        content: "确定删除吗？",
        onCancel: function() {},
        onOk: function() {
          var e = a.state.selectedRowKeys;
          a.clearAlarm(e);
        }
      }); else {
        var e = _amosAntd.Modal.warning({
          title: "系统提示",
          content: "请选择数据！",
          okText: "确定"
        });
        setTimeout((function() {
          return e.destroy();
        }), 2e3);
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "reload", (function(e) {
      a.setState({
        reload: function() {
          e(), a.setState({
            selectedRows: [],
            selectedRowKeys: []
          });
        }
      }, e());
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "refreshData", (function(e, t) {
      a.fetchCurrentAlarm(e, t);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getRefreshTime", (function() {
      if (a.state.refreshTime) return a.state.refreshTime;
      var e = new Date, t = e.getHours(), r = e.getMinutes();
      return r < 10 && (r = "0".concat(r)), "".concat(t, "时").concat(r, "分");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "refreshTime", (function() {
      a.refreshData(a.filter);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getPanelHeight", (function() {
      var e = a.alarmRoot, t = (0, _dt2react.getOffset)(e) || {};
      return void 0 !== t ? t.height - offsetHeight : defaultHeight;
    })), a.filter = {
      current: 0,
      pageSize: 10
    }, a.state = {
      dataList: [],
      selectedRows: [],
      selectedRowKeys: [],
      total: 1,
      reload: function() {},
      maxHeight: 450,
      searchCondition: {}
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentDidMount",
    value: function() {
      window.addEventListener("resize", this.onWindowResize), this.props.updateStatus();
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {}
  }, {
    key: "componentWillUnmount",
    value: function() {
      window.removeEventListener("resize", this.onWindowResize);
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.state, r = t.dataList, a = t.total, n = (t.refreshTime, t.maxHeight), i = {
        alarmDetail: this.alarmDetail,
        oneClearAlarm: this.oneClearAlarm
      };
      return _react.default.createElement("div", {
        className: "history-alarm-root",
        ref: function(t) {
          return e.alarmRoot = t;
        }
      }, _react.default.createElement("div", {
        className: "recent-alarm-table"
      }, _react.default.createElement(_AmosGridTable.default, {
        columns: alarmColumns(i),
        callBack: this.reload,
        dataList: r,
        totals: a,
        getTableDataAction: this.fetchCurrentAlarm,
        getSelectedRows: this.getSelectedRows,
        maxHeight: n,
        getPanelHeight: this.getPanelHeight
      })));
    }
  } ]), r;
}(_react.Component);

HistoryAlarmTable.displayName = "HistoryAlarmTable", HistoryAlarmTable.propTypes = {
  updateStatus: _propTypes.default.func
};

var _default = HistoryAlarmTable;

exports.default = _default;