"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 _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _vmSubTabs = require("../../../vm-sub-tabs");
var _api = require("../../api");
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 List = function List(props) {
  var id = props.id,
    carCode = props.carCode,
    startDate = props.startDate,
    endDate = props.endDate,
    source = props.source;
  var _useSetState = (0, _ahooks.useSetState)({
      alarmStrategyName: 'all',
      alarmTabs: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      data: {
        total: 0,
        rows: []
      }
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var alarmTabs = state.alarmTabs,
    alarmStrategyName = state.alarmStrategyName,
    pagination = state.pagination,
    data = state.data;
  var _AlarmService$useAlar = _api.AlarmService.useAlarmType(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59"), source),
    alarmTypes = _AlarmService$useAlar.alarmTypes;
  var _AlarmService$useAlar2 = _api.AlarmService.useAlarmTypeWork(id, startDate, endDate, source),
    alarmTypesWork = _AlarmService$useAlar2.alarmTypesWork;
  var _AlarmService$useAlar3 = _api.AlarmService.useAlarmList(carCode, alarmStrategyName === 'all' ? '' : alarmStrategyName, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59"), pagination.current),
    alarmRecord = _AlarmService$useAlar3.alarmRecord;
  var _AlarmService$useAlar4 = _api.AlarmService.useAlarmListWork(id, alarmStrategyName === 'all' ? '' : alarmStrategyName, startDate, endDate, pagination.current - 1),
    alarmRecordWork = _AlarmService$useAlar4.alarmRecordWork;
  (0, _react.useEffect)(function () {
    var _a;
    if (Array.isArray(alarmTypes === null || alarmTypes === void 0 ? void 0 : alarmTypes.summary) && source === 'GPS') {
      var _alarmTabs = [{
        key: 'all',
        label: "\u5168\u90E8(".concat((alarmTypes === null || alarmTypes === void 0 ? void 0 : alarmTypes.totalCount) || 0, ")")
      }];
      (_a = alarmTypes === null || alarmTypes === void 0 ? void 0 : alarmTypes.summary) === null || _a === void 0 ? void 0 : _a.forEach(function (ele) {
        _alarmTabs.push({
          key: ele.alarmType,
          label: "".concat(ele.alarmTypeName, "(").concat(ele.totalCount, ")")
        });
      });
      setState({
        alarmTabs: _alarmTabs
      });
    }
  }, [alarmTypes, source]);
  (0, _react.useEffect)(function () {
    if (alarmTypesWork && source === 'WORK') {
      setState({
        alarmTabs: [{
          key: 'all',
          label: "\u5168\u90E8(".concat((alarmTypesWork === null || alarmTypesWork === void 0 ? void 0 : alarmTypesWork.total) || 0, ")")
        }, {
          key: 'ALARM_SYLD',
          label: "\u5B8C\u6210\u7387\u4F4E\u62A5\u8B66(".concat((alarmTypesWork === null || alarmTypesWork === void 0 ? void 0 : alarmTypesWork.low) || 0, ")")
        }, {
          key: 'ALARM_WSJ',
          label: "\u672A\u4F5C\u4E1A\u62A5\u8B66(".concat((alarmTypesWork === null || alarmTypesWork === void 0 ? void 0 : alarmTypesWork.miss) || 0, ")")
        }]
      });
    }
  }, [JSON.stringify(alarmTypesWork), source]);
  (0, _react.useEffect)(function () {
    if (source === 'GPS') {
      setState({
        data: alarmRecord
      });
    } else {
      setState({
        data: alarmRecordWork
      });
    }
  }, [source, JSON.stringify(alarmRecord), JSON.stringify(alarmRecordWork)]);
  var columns = source === 'GPS' ? [{
    title: '报警类型',
    dataIndex: 'alarmTypeName',
    key: 'alarmTypeName',
    width: 80
  }, {
    title: '报警等级',
    dataIndex: 'alarmLevelName',
    key: 'alarmLevelName',
    width: 60
  }, {
    title: '报警开始时间',
    dataIndex: 'alarmBeginTime',
    key: 'alarmBeginTime',
    width: 150
  }, {
    title: '报警结束时间',
    dataIndex: 'alarmEndTime',
    key: 'alarmEndTime',
    width: 150
  }, {
    title: '报警时长',
    dataIndex: 'beginDuration',
    key: 'beginDuration',
    width: 120
  }, {
    title: '当前速度(km/h)',
    dataIndex: 'positionSpeed',
    key: 'positionSpeed',
    width: 100
  }, {
    title: '报警地址',
    dataIndex: 'alarmAddress',
    key: 'alarmAddress',
    width: 200,
    ellipsis: true
  }] : [{
    title: '报警类型',
    dataIndex: 'alarmTypeName',
    key: 'alarmTypeName'
  }, {
    title: '报警日期',
    dataIndex: 'taskDay',
    key: 'taskDay'
  }, {
    title: '报警阈值',
    dataIndex: 'thresholdWithSign',
    key: 'thresholdWithSign'
  }, {
    title: '实际完成率',
    dataIndex: 'rateWithSign',
    key: 'rateWithSign'
  }];
  var pageChange = function pageChange(page) {
    setState({
      pagination: Object.assign(Object.assign({}, pagination), {
        current: page
      })
    });
  };
  var tableProps = {
    pagination: Object.assign(Object.assign({}, pagination), {
      total: data.total || 0,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    height: 440,
    dataSource: data.rows || []
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-main-list"
  }, (alarmTabs === null || alarmTabs === void 0 ? void 0 : alarmTabs.length) > 0 && (/*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabsLine, {
    items: alarmTabs,
    activeKey: alarmStrategyName,
    onChange: function onChange(key) {
      setState({
        alarmStrategyName: key
      });
    }
  })), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns,
    rowKey: "id"
  }, tableProps))));
};
var _default = exports["default"] = List;
//# sourceMappingURL=List.js.map
