"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = AlarmRecord;
var _react = _interopRequireWildcard(require("react"));
require("./index.less");
var _index2 = require("../../index");
var _ahooks = require("ahooks");
var _api = require("../../api");
var _moment = _interopRequireDefault(require("moment"));
var _AlarmTrend = _interopRequireDefault(require("./AlarmTrend"));
var _AlarmTotal = _interopRequireDefault(require("./AlarmTotal"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _vmFilter = require("../../../vm-filter");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function AlarmRecord() {
  var _useContext = (0, _react.useContext)(_index2.PumpContext),
    prefix = _useContext.prefix,
    id = _useContext.id;
  var _useSetState = (0, _ahooks.useSetState)({
      currentData: [],
      dataSource: [],
      totalAlarmNum: 0,
      alarmStartTime: (0, _moment["default"])().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      alarmEndTime: (0, _moment["default"])().endOf('day').format('YYYY-MM-DD HH:mm:ss')
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var currentData = state.currentData,
    totalAlarmNum = state.totalAlarmNum,
    dataSource = state.dataSource,
    alarmStartTime = state.alarmStartTime,
    alarmEndTime = state.alarmEndTime;
  (0, _react.useEffect)(function () {
    _api.AlarmService.alarmList({
      facilityIds: [id],
      alarmStartTimeBegin: (0, _moment["default"])().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      alarmStartTimeEnd: (0, _moment["default"])().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
      dimension: 'alarmType',
      alarmTypes: ['FACTOR']
    }).then(function (data) {
      if (data && data.length) {
        var newItem = data[0];
        setState({
          currentData: [Object.assign(Object.assign({}, newItem), {
            monitorItemName: "\u5F53\u524D".concat(newItem.monitorItemName, "(").concat(newItem.alarmDataUnit, ")")
          })],
          totalAlarmNum: data.length
        });
      }
    });
  }, []);
  (0, _react.useEffect)(function () {
    _api.AlarmService.alarmList({
      facilityIds: [id],
      alarmStartTimeBegin: (0, _moment["default"])(alarmStartTime).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      alarmStartTimeEnd: (0, _moment["default"])(alarmEndTime).endOf('day').format('YYYY-MM-DD HH:mm:ss'),
      dimension: 'alarmType',
      alarmTypes: ['FACTOR']
    }).then(function (data) {
      if (data && data.length) {
        setState({
          dataSource: data
        });
      }
    });
  }, [alarmStartTime, alarmEndTime]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-top")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-top-left")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-card")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-card-title")
  }, /*#__PURE__*/_react["default"].createElement("span", null, "\u5F53\u524D\u62A5\u8B66")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-card-content")
  }, [{
    monitorItemName: '当前报警总数(次)',
    key: 'all',
    alarmData: totalAlarmNum
  }].concat(_toConsumableArray(currentData)).map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("span", {
      key: item.key,
      className: "".concat(prefix, "-alarm-current-item")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "-alarm-current-item-name")
    }, item.monitorItemName), item.key == 'all' ? (/*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "-alarm-current-item-alarm-value")
    }, item.alarmData)) : (/*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "-alarm-current-item-value")
    }, item.alarmData)));
  }))), /*#__PURE__*/_react["default"].createElement(_AlarmTotal["default"], {
    id: id,
    prefix: prefix
  })), /*#__PURE__*/_react["default"].createElement(_AlarmTrend["default"], {
    id: id,
    prefix: prefix
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-bottom")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-card")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-card-title")
  }, /*#__PURE__*/_react["default"].createElement("span", null, "\u62A5\u8B66\u8BB0\u5F55"), /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
    style: {
      width: 240
    },
    value: [(0, _moment["default"])(alarmStartTime), (0, _moment["default"])(alarmEndTime)],
    format: 'YYYY-MM-DD',
    onChange: function onChange(date) {
      setState({
        alarmStartTime: date.length ? (0, _moment["default"])(date[0]).format('YYYY-MM-DD HH:mm:ss') : '',
        alarmEndTime: date.length ? (0, _moment["default"])(date[1]).format('YYYY-MM-DD HH:mm:ss') : ''
      });
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-alarm-card-content")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], {
    pagination: false,
    columns: [{
      title: '监测项目',
      dataIndex: 'monitorItemName',
      key: 'monitorItemName',
      width: 100,
      ellipsis: true
    }, {
      title: '报警类型',
      dataIndex: 'alarmTypeName',
      key: 'alarmTypeName',
      width: 100
    }, {
      title: '报警等级',
      dataIndex: 'alarmLevelName',
      key: 'alarmLevelName',
      width: 100
    }, {
      title: '报警时间',
      dataIndex: 'alarmStartTime',
      key: 'alarmStartTime',
      width: 160
    }, {
      title: '结束时间',
      dataIndex: 'alarmEndTime',
      key: 'alarmEndTime',
      width: 160
    }, {
      title: '持续时长',
      dataIndex: 'alarmDurationStr',
      key: 'alarmDurationStr',
      width: 150
    }, {
      title: '报警状态',
      dataIndex: 'alarmStatusName',
      key: 'alarmStatusName',
      width: 150
    }],
    dataSource: dataSource,
    height: 350
  }))))));
}
//# sourceMappingURL=index.js.map
