"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"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _antd = require("antd");
var _dayjs = _interopRequireDefault(require("dayjs"));
var _moment = _interopRequireDefault(require("moment"));
require("moment/locale/zh-cn");
var _zh_CN = _interopRequireDefault(require("antd/es/date-picker/locale/zh_CN"));
require("../index.less");
var _utils = require("@vtx/utils");
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 _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; }
var getAlarmList = function getAlarmList(params) {
  return _utils.request.post('/cloud/device/alarmInfo/list', {
    data: JSON.stringify(params)
  });
};
var Alarm = function Alarm(props) {
  var detail = props.detail,
    alarmDate = props.alarmDate,
    _props$theme = props.theme,
    theme = _props$theme === void 0 ? 'light' : _props$theme;
  var _useSetState = (0, _ahooks.useSetState)({
      date: (0, _dayjs["default"])(alarmDate).format('YYYY-MM-DD'),
      alarmList: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var date = state.date,
    alarmList = state.alarmList;
  (0, _react.useEffect)(function () {
    detail.id && getList();
  }, [detail.id]);
  var getList = function getList() {
    return getAlarmList({
      // deviceName: detail.name,
      facilityIds: [detail.id],
      alarmStatuses: ['OCCURRING'],
      alarmTypes: ['FACTOR'],
      alarmStartTimeBegin: (0, _dayjs["default"])(date).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      alarmStartTimeEnd: (0, _dayjs["default"])(date).endOf('day').format('YYYY-MM-DD HH:mm:ss')
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
        setState({
          alarmList: res.data
        });
      }
    });
  };
  (0, _react.useEffect)(function () {
    getList();
  }, [date]);
  var columns = [{
    title: '监测指标',
    dataIndex: 'factorName',
    key: 'factorName'
  }, {
    title: '报警等级',
    dataIndex: 'alarmLevelName',
    key: 'alarmLevelName'
  }, {
    title: '监测开始时间',
    dataIndex: 'alarmStartTime',
    key: 'alarmStartTime'
  }, {
    title: '监测结束时间',
    dataIndex: 'alarmEndTime',
    key: 'alarmEndTime'
  }];
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: 'monitor'
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: 'searchType'
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      marginRight: '10px'
    }
  }, "\u62A5\u8B66\u65F6\u95F4"), /*#__PURE__*/_react["default"].createElement(_antd.DatePicker, {
    style: {
      marginLeft: '12px'
    },
    locale: _zh_CN["default"],
    disabledDate: function disabledDate(current) {
      return current && current > (0, _dayjs["default"])().endOf('day');
    },
    allowClear: false,
    value: (0, _moment["default"])(date),
    onChange: function onChange(_, dateStr) {
      return setState({
        date: dateStr
      });
    },
    popupClassName: theme === 'blue' ? 'popupDate' : ''
  }), "\u2003", /*#__PURE__*/_react["default"].createElement(_antd.Button, {
    type: 'primary',
    onClick: getList
  }, "\u67E5\u8BE2"), "\u2002", /*#__PURE__*/_react["default"].createElement(_antd.Button, {
    onClick: function onClick() {
      return setState({
        date: (0, _dayjs["default"])().format('YYYY-MM-DD')
      });
    }
  }, "\u6E05\u7A7A")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "charts"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Table, {
    columns: columns,
    dataSource: alarmList,
    pagination: false,
    locale: {
      emptyText: '暂无数据'
    }
  })));
};
var _default = exports["default"] = Alarm;
//# sourceMappingURL=Alarm.js.map
