"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 _react = _interopRequireWildcard(require("react"));
var _moment = _interopRequireDefault(require("moment"));
var _sumBy = _interopRequireDefault(require("lodash/sumBy"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _api = require("../../api");
var _alarm = _interopRequireDefault(require("../../imgs/alarm.png"));
var _ahooks = require("ahooks");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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 Summary = function Summary(_ref) {
  var id = _ref.id;
  var _useSetState = (0, _ahooks.useSetState)({
      alarmTabsValue: [{
        name: '',
        value: 0
      }],
      totalCount: 0
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var alarmTabsValue = state.alarmTabsValue,
    totalCount = state.totalCount;
  var _AlarmService$useAlar = _api.AlarmService.useAlarmSummary(id, (0, _moment["default"])().format('YYYY-MM-DD')),
    alarmSummary = _AlarmService$useAlar.alarmSummary;
  var _BaseService$useBaseA = _api.BaseService.useBaseAlarmInfo(id, (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'), (0, _moment["default"])().format('YYYY-MM-DD')),
    alarmTypeRes = _BaseService$useBaseA.alarmTypeRes;
  (0, _react.useEffect)(function () {
    var list = [];
    var count = 0;
    if (alarmTypeRes.length > 0) {
      count = (0, _sumBy["default"])(alarmTypeRes, function (o) {
        return o.count;
      });
      alarmTypeRes.forEach(function (ele) {
        var obj = {
          key: ele.standardCode,
          name: ele.standardName,
          value: ele.count
        };
        list.push(obj);
      });
    }
    setState({
      totalCount: count,
      alarmTabsValue: list
    });
  }, [alarmTypeRes]);
  var color = ['#9270CA', '#6DC8EC', '#E8684A', '#F6BD16', '#5D7092', '#5AD8A6', '#5B8FF9', '#FF9D4D'];
  var option = {
    color: color,
    backgroundColor: 'transparent',
    tooltip: {
      show: true,
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: '40%',
      top: 'middle',
      align: 'left',
      itemGap: 8,
      itemWidth: 10,
      itemHeight: 10,
      formatter: function formatter(name) {
        var value = alarmTabsValue.find(function (item) {
          return item.name === name;
        });
        var rate = ((value === null || value === void 0 ? void 0 : value.value) || 0) / totalCount * 100;
        if (value) {
          return "\t\t".concat(name, "\t\t").concat(value.value, "\u6B21\t\t").concat(rate.toFixed(2), "%");
        } else {
          return '';
        }
      },
      textStyle: {
        fontSize: 14,
        color: '#fff'
      },
      pageIconColor: '#fff',
      pageIconInactiveColor: '#fff',
      pageTextStyle: {
        color: '#fff'
      }
    },
    series: [{
      type: 'pie',
      radius: ['55%', '75%'],
      center: ['20%', '50%'],
      hoverAnimation: true,
      z: 10,
      itemStyle: {
        normal: {
          borderWidth: 2,
          borderColor: '#003359'
        }
      },
      label: {
        show: false
      },
      data: alarmTabsValue,
      labelLine: {
        show: false
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u62A5\u8B66\u4FE1\u606F\u6C47\u603B"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _alarm["default"]
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time-name"
  }, "\u6708\u5EA6\u62A5\u8B66\u603B\u6B21\u6570"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time-value"
  }, /*#__PURE__*/_react["default"].createElement("span", null, (alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisYearCount) || 0), "\u6B21", /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time-value-compare"
  }, "\u6708\u540C\u6BD4 ".concat((alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisYearOnLastYearCount) || 0, "%"), (alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisYearOnLastYearCount) >= 100 ? /*#__PURE__*/_react["default"].createElement("div", {
    className: "triangle-up"
  }) : /*#__PURE__*/_react["default"].createElement("div", {
    className: "triangle-down"
  }))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-type-analysis"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u7C7B\u578B\u5206\u6790"
  }), /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '180px',
      width: '100%'
    }
  })));
};
var _default = Summary;
exports["default"] = _default;
//# sourceMappingURL=Summary.js.map
