"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 _moment = _interopRequireDefault(require("moment"));
var _antd = require("antd");
var _sumBy = _interopRequireDefault(require("lodash/sumBy"));
var _util = require("../../../util");
var _vmFilter = require("../../../vm-filter");
var _vmSubTabs = require("../../../vm-sub-tabs");
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"));
var _Situation = _interopRequireDefault(require("./Situation"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
require("./index.less");
var _level = _interopRequireDefault(require("../../imgs/level1.png"));
var _level2 = _interopRequireDefault(require("../../imgs/level2.png"));
var _level3 = _interopRequireDefault(require("../../imgs/level3.png"));
var _level4 = _interopRequireDefault(require("../../imgs/level4.png"));
var _level5 = _interopRequireDefault(require("../../imgs/level5.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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 BaseInfo = function BaseInfo(props) {
  var id = props.id,
    photos = props.photos,
    info = props.info,
    fields = props.fields;
  var _useSettings = (0, _useSettings2["default"])(),
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var nowDate = (0, _moment["default"])().format('YYYY-MM-DD');
  var _useSetState = (0, _ahooks.useSetState)({
      standardCode: 'all',
      startDate: sDate || nowDate,
      endDate: eDate || nowDate,
      alarmTabs: [{
        key: 'all',
        label: '全部',
        value: 0
      }],
      alarmTabsValue: [{}],
      totalCount: 0,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      sort: '',
      order: ''
    }),
    _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,
    sort = state.sort,
    order = state.order;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  var _BaseService$useBaseI = _api.BaseService.useBaseInfo(id, nowDate, nowDate),
    situationRes = _BaseService$useBaseI.situationRes;
  var _BaseService$useBaseA = _api.BaseService.useBaseAlarmInfo(id, (0, _moment["default"])(nowDate).startOf('M').format('YYYY-MM-DD 00:00:00'), (0, _moment["default"])(nowDate).format('YYYY-MM-DD 23:59:59')),
    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,
        label: "".concat(ele.standardName, " (").concat(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: 'all',
      label: '全部',
      value: 0
    }]; // 报警明细标签
    if (alarmTs.length > 0) {
      var _formatAlarmType2 = formatAlarmType(alarmTs),
        list = _formatAlarmType2.list,
        _totalCount2 = _formatAlarmType2.totalCount;
      arr[0].label = "\u5168\u90E8 (".concat(_totalCount2, ")");
      arr[0].value = _totalCount2;
      setState({
        alarmTabs: arr.concat(list)
      });
    }
  }, [alarmTs]);
  var _BaseService$useAlarm = _api.BaseService.useAlarmDetails(id, standardCode === 'all' ? '' : standardCode, startDate, endDate, pagination.current, sort, order),
    detail = _BaseService$useAlarm.detail;
  var getLevel = function getLevel(text) {
    var src = '',
      color = '#1FEFA9',
      name = '';
    switch (text) {
      case 1:
        src = _level["default"];
        name = '一';
        color = '#FF6A65';
        break;
      case 2:
        src = _level2["default"];
        name = '二';
        color = '#FFBD1E';
        break;
      case 3:
        src = _level3["default"];
        name = '三';
        color = '#E86CFF';
        break;
      case 4:
        src = _level4["default"];
        name = '四';
        color = '#00A8FF';
        break;
      case 5:
        src = _level5["default"];
        name = '五';
        color = '#1FEFA9';
        break;
      default:
        src = _level["default"];
        name = '一';
        color = '#FF6A65';
        break;
    }
    return {
      src: src,
      name: "\u7B49\u7EA7".concat(name),
      color: color
    };
  };
  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',
    width: 80,
    render: function render(text) {
      var _getLevel = getLevel(text),
        src = _getLevel.src,
        name = _getLevel.name,
        color = _getLevel.color;
      return /*#__PURE__*/_react["default"].createElement("span", {
        className: "alarmLevel",
        style: {
          color: color
        }
      }, /*#__PURE__*/_react["default"].createElement("img", {
        src: src,
        style: {
          marginTop: '-2px'
        }
      }), name);
    }
  }, {
    title: '报警开始时间',
    dataIndex: 'startDate',
    key: 'startDate',
    width: 120,
    sorter: true
  }, {
    title: '报警结束时间',
    dataIndex: 'endDate',
    key: 'endDate',
    width: 120,
    sorter: true
  }, {
    title: '报警时长',
    dataIndex: 'dur',
    key: 'dur',
    width: 80,
    sorter: function sorter(a, b) {
      return (0, _moment["default"])(a.endDate).diff((0, _moment["default"])(a.startDate)) - (0, _moment["default"])(b.endDate).diff((0, _moment["default"])(b.startDate));
    },
    render: function render(_text, record) {
      return (record === null || record === void 0 ? void 0 : record.startDate) && (record === null || record === void 0 ? void 0 : record.endDate) && (0, _util.secondToFormatTime)((0, _moment["default"])(record.endDate).diff((0, _moment["default"])(record.startDate)) / 1000);
    }
  }];
  var handleTableChange = function handleTableChange(sorter) {
    sorter.columnKey !== 'dur' && setState({
      sort: sorter.columnKey,
      order: sorter.order === 'ascend' ? 'ASC' : 'DESC'
    });
  };
  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
    }),
    rowKey: 'id',
    height: 140,
    handleTableChange: handleTableChange,
    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(_antd.Row, {
    gutter: [10, 10]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 14,
    xl: 14,
    lg: 24,
    md: 24
  }, /*#__PURE__*/_react["default"].createElement(_BaseInner["default"], {
    photos: photos,
    data: (0, _util.getFieldRender)(fields, info)
  })), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 10,
    xl: 10,
    lg: 24,
    md: 24
  }, /*#__PURE__*/_react["default"].createElement(_AlarmType["default"], {
    data: alarmTabsValue,
    total: totalCount
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-bottom"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [10, 10]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 9,
    xl: 9,
    lg: 24,
    md: 24
  }, /*#__PURE__*/_react["default"].createElement(_Situation["default"], {
    situationRes: situationRes
  })), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 15,
    xl: 15,
    lg: 24,
    md: 24
  }, /*#__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"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabsLine, {
    items: alarmTabs,
    activeKey: standardCode,
    onChange: function onChange(key) {
      setState({
        standardCode: key
      });
    }
  })), /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns
  }, tableProps)))))));
};
var _default = exports["default"] = BaseInfo;
//# sourceMappingURL=index.js.map
