"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _sumBy = _interopRequireDefault(require("lodash/sumBy"));
var _react = _interopRequireWildcard(require("react"));
var _util = require("../../../util");
var _vmFilter = require("../../../vm-filter");
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _api = require("../../api");
var _AlarmType = _interopRequireDefault(require("./AlarmType"));
var _BaseInner = _interopRequireDefault(require("./BaseInner"));
require("./index.less");
var _Situation = _interopRequireDefault(require("./Situation"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var BaseInfo = function BaseInfo(props) {
  var id = props.id;
  // console.warn(1)
  var nowDate = (0, _moment["default"])().format('YYYY-MM-DD');
  var _useSetState = (0, _ahooks.useSetState)({
      standardCode: '',
      startDate: nowDate,
      endDate: nowDate,
      alarmTabs: [{
        key: '',
        name: '全部',
        value: 0
      }],
      alarmTabsValue: [{}],
      totalCount: 0,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      }
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var standardCode = state.standardCode,
    startDate = state.startDate,
    endDate = state.endDate,
    alarmTabs = state.alarmTabs,
    alarmTabsValue = state.alarmTabsValue,
    totalCount = state.totalCount,
    pagination = state.pagination;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  var _BaseService$useBaseI = _api.BaseService.useBaseInfo(id, nowDate, nowDate),
    baseInfo = _BaseService$useBaseI.baseInfo,
    photos = _BaseService$useBaseI.photos,
    situationRes = _BaseService$useBaseI.situationRes;
  var _BaseService$useBaseA = _api.BaseService.useBaseAlarmInfo(id, (0, _moment["default"])(nowDate).startOf('M').format('YYYY-MM-DD'), (0, _moment["default"])(nowDate).format('YYYY-MM-DD')),
    alarmTypeRes = _BaseService$useBaseA.alarmTypeRes;
  var _BaseService$useBaseA2 = _api.BaseService.useBaseAlarmTypes(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59")),
    alarmTs = _BaseService$useBaseA2.alarmTypeRes;
  // 格式化报警类型数据
  var formatAlarmType = function formatAlarmType(dataList) {
    var list = [];
    var totalCount = 0; // 报警类型总数
    totalCount = (0, _sumBy["default"])(dataList, function (o) {
      return o.count;
    });
    dataList.forEach(function (ele) {
      var obj = {
        key: ele.standardCode,
        name: ele.standardName,
        value: ele.count
      };
      list.push(obj);
    });
    return {
      list: list,
      totalCount: totalCount
    };
  };
  (0, _react.useEffect)(function () {
    if (alarmTypeRes.length > 0) {
      var _formatAlarmType = formatAlarmType(alarmTypeRes),
        list = _formatAlarmType.list,
        _totalCount = _formatAlarmType.totalCount;
      setState({
        alarmTabsValue: list,
        totalCount: _totalCount
      });
    }
  }, [alarmTypeRes]);
  (0, _react.useEffect)(function () {
    var arr = [{
      key: '',
      name: '全部',
      value: 0
    }]; // 报警明细标签
    if (alarmTs.length > 0) {
      var _formatAlarmType2 = formatAlarmType(alarmTs),
        list = _formatAlarmType2.list,
        _totalCount2 = _formatAlarmType2.totalCount;
      arr[0].value = _totalCount2;
      setState({
        alarmTabs: arr.concat(list)
      });
    }
  }, [alarmTs]);
  var _BaseService$useAlarm = _api.BaseService.useAlarmDetails(id, standardCode, startDate, endDate, pagination.current, pagination.pageSize),
    detail = _BaseService$useAlarm.detail;
  var columns = [{
    title: '监测指标',
    dataIndex: 'standardName',
    key: 'standardName',
    width: 80,
    ellipsis: true
  }, {
    title: '报警名称',
    dataIndex: 'name',
    key: 'name',
    width: 80,
    ellipsis: true
  }, {
    title: '报警等级',
    dataIndex: 'level',
    key: 'level'
  }, {
    title: '报警开始时间',
    dataIndex: 'startDate',
    key: 'startDate',
    width: 120
  }, {
    title: '报警结束时间',
    dataIndex: 'endDate',
    key: 'endDate',
    width: 120
  }, {
    title: '报警时长',
    dataIndex: 'endDate',
    key: 'endDate',
    width: 80,
    render: function render(text, record) {
      return (record === null || record === void 0 ? void 0 : record.startDate) && text && (0, _util.secondToFormatTime)((0, _moment["default"])(text).diff((0, _moment["default"])(record.startDate)) / 1000);
    }
  }];
  var pageChange = function pageChange(page) {
    setState({
      pagination: Object.assign(Object.assign({}, pagination), {
        current: page
      })
    });
  };
  var tableProps = {
    pagination: Object.assign(Object.assign({}, pagination), {
      total: detail === null || detail === void 0 ? void 0 : detail.total,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    height: 160,
    dataSource: detail === null || detail === void 0 ? void 0 : detail.dataSource
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "wr-baseContent"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-top"
  }, /*#__PURE__*/_react["default"].createElement(_BaseInner["default"], {
    photos: photos,
    baseInfo: baseInfo
  }), /*#__PURE__*/_react["default"].createElement(_AlarmType["default"], {
    data: alarmTabsValue,
    total: totalCount
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom"
  }, /*#__PURE__*/_react["default"].createElement(_Situation["default"], {
    situationRes: situationRes
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom-alarm-detail"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom-alarm-detail-date"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u62A5\u8B66\u660E\u7EC6"
  }), /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
    value: [(0, _moment["default"])(startDate), (0, _moment["default"])(endDate)],
    size: "small",
    onChange: function onChange(dates) {
      return dates && handleDateChange((0, _moment["default"])(dates[0]).format('YYYY-MM-DD'), (0, _moment["default"])(dates[1]).format('YYYY-MM-DD'));
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom-alarm-detail-tab"
  }, alarmTabs.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: item.key,
      className: "base-bottom-alarm-detail-tab-item ".concat(standardCode === item.key && 'base-bottom-alarm-detail-tab-item_active'),
      onClick: function onClick() {
        setState({
          standardCode: item.key
        });
      }
    }, "".concat(item.name, " (").concat(item.value, ")"));
  })), /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns
  }, tableProps)))));
};
var _default = BaseInfo;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
