"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;
exports.getMinHundred = getMinHundred;
exports.getPercent = getPercent;
exports.getPieOption = void 0;
var _react = _interopRequireWildcard(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmButton = _interopRequireDefault(require("../../../vm-button"));
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _Trend = require("./Trend");
var _config = require("../../config");
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
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 getPieOption = exports.getPieOption = function getPieOption(_ref, serviceList) {
  var _ref$data = _ref.data,
    data = _ref$data === void 0 ? [] : _ref$data,
    center = _ref.center,
    radius = _ref.radius,
    _ref$legend = _ref.legend,
    legend = _ref$legend === void 0 ? {} : _ref$legend;
  var _data = (0, _config.getFilterEcharts)(data, serviceList) || [];
  return {
    tooltip: {
      trigger: 'item',
      formatter: function formatter(params) {
        var _a, _b;
        //tongjia
        var unit = '次';
        var str = '';
        if (Array.isArray(params)) {
          str = "<div  style=\"text-align:left\">".concat((_a = params === null || params === void 0 ? void 0 : params[0]) === null || _a === void 0 ? void 0 : _a.axisValue, "<?div>");
          var color = (_b = params === null || params === void 0 ? void 0 : params[0].color) === null || _b === void 0 ? void 0 : _b.colorStops; // 获取系列的颜色
          params.map(function (item, index) {
            var _a;
            str += "<div  style=\"text-align:left\"><span style=\"color:".concat(item.color && typeof item.color == 'string' ? item.color : (_a = color === null || color === void 0 ? void 0 : color[index]) === null || _a === void 0 ? void 0 : _a.color, "\">\u2022</span> ").concat(item.seriesName, " &nbsp;&nbsp;&nbsp;").concat(item.value).concat(unit, "</div>");
          });
        } else {
          var _color = params === null || params === void 0 ? void 0 : params.color; // 获取系列的颜色
          str += "<div style=\"display:flex;align-items:center\"><span style=\"color:".concat(_color, ";font-size:24px \">\u2022</span>&nbsp;").concat(params === null || params === void 0 ? void 0 : params.name, "&nbsp;&nbsp;").concat(params.value).concat(unit, "</div>");
        }
        return str; // 返回带点的字符串
      }
    },
    legend: Object.assign({
      top: 'center',
      left: '35%',
      type: 'scroll',
      orient: 'vertical',
      formatter: function formatter(name) {
        var _a;
        var obj = (_a = _data === null || _data === void 0 ? void 0 : _data.find) === null || _a === void 0 ? void 0 : _a.call(_data, function (item) {
          return item.alarmTypeName === name;
        });
        return "{a|".concat(name, "}{a|").concat((obj === null || obj === void 0 ? void 0 : obj.count) || 0, "\u6B21}{a|\u5747\u503C\uFF1A").concat((obj === null || obj === void 0 ? void 0 : obj.countAvg) || 0, "\u6B21}");
      },
      textStyle: {
        color: '#fff',
        rich: {
          a: {
            width: 70
          }
        }
      }
    }, legend),
    series: [{
      name: '事件类型分布',
      type: 'pie',
      radius: radius || ['50%', '80%'],
      center: center || ['15%', '50%'],
      avoidLabelOverlap: false,
      labelLine: {
        show: false
      },
      label: {
        show: false
      },
      data: _data.map(function (item) {
        return {
          name: item.alarmTypeName,
          value: item.count
        };
      })
    }]
  };
};
var PieCharType;
(function (PieCharType) {
  PieCharType["SJLX"] = "\u4E8B\u4EF6\u7C7B\u578B\u5206\u5E03";
  PieCharType["QS"] = "\u8FD1\u4E00\u5468\u8D8B\u52BF";
})(PieCharType || (PieCharType = {}));
function getMinHundred(num) {
  return Math.ceil(num / 100) * 100 || 100;
}
function getPercent() {
  var num = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  return num ? (num * 100).toFixed(2) : 0;
}
var RightBottom = function RightBottom(_ref2) {
  var classPrefix = _ref2.classPrefix,
    id = _ref2.id,
    serviceList = _ref2.serviceList;
  var _a;
  var _useState = (0, _react.useState)(PieCharType.SJLX),
    _useState2 = _slicedToArray(_useState, 2),
    pieChartType = _useState2[0],
    setPieChartType = _useState2[1];
  // 事件类型分布
  var alarmByTypeData = _api.overViewService.alarmSumByType({
    housingEstateId: id
  });
  // 近一周趋势
  var alarmByDateData = _api.overViewService.alarmSumByDate({
    housingEstateId: id
  });
  // 工单处理效率
  var efficiencyData = _api.overViewService.resolveEfficiency({
    housingEstateId: id
  });
  var lineData = ((0, _config.getFilterEcharts)(alarmByDateData, serviceList) || []).map(function (item) {
    return {
      name: item.alarmTypeName || '',
      count: item.count || 0,
      day: item.day || ''
    };
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom")
  }, serviceList.includes('THROW') ? (/*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "AI\u5DE5\u5355"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom--buttons")
  }, /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    onClick: function onClick() {
      return setPieChartType(PieCharType.SJLX);
    },
    name: "\u4E8B\u4EF6\u7C7B\u578B\u5206\u5E03",
    active: pieChartType === PieCharType.SJLX,
    style: {
      marginRight: 10
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    onClick: function onClick() {
      return setPieChartType(PieCharType.QS);
    },
    name: "\u8FD1\u4E00\u5468\u8D8B\u52BF",
    active: pieChartType === PieCharType.QS
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom--pie")
  }, pieChartType === PieCharType.SJLX && (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getPieOption({
      data: alarmByTypeData || []
    }, serviceList),
    style: {
      height: 150
    }
  })), pieChartType === PieCharType.QS && (/*#__PURE__*/_react["default"].createElement(_vmCharts.Line1, Object.assign({}, (0, _Trend.transferLineData)(lineData), {
    style: {
      height: 150
    }
  })))))) : (/*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom-echarts")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "content"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u4E8B\u4EF6\u7C7B\u578B\u5206\u5E03"
  }), alarmByTypeData ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getPieOption({
      data: alarmByTypeData || []
    }, serviceList),
    style: {
      height: 150
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: 150
    }
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "content"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u8FD1\u4E00\u5468\u8D8B\u52BF"
  }), alarmByTypeData ? (/*#__PURE__*/_react["default"].createElement(_vmCharts.Line1, Object.assign({}, (0, _Trend.transferLineData)(lineData), {
    style: {
      height: 150
    }
  }))) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: 150
    }
  }))))), ((_a = (0, _config.filterCode)(serviceList, ['CHUYU_QUALITY', 'LANDING', 'ON_LID', 'QITA_QUALITY'])) === null || _a === void 0 ? void 0 : _a.size) ? (/*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u5DE5\u5355\u5904\u7406\u6548\u7387"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom--gauges")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "gauges-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u5173\u95ED\u7387",
    unit: "%",
    min: 0,
    max: 100,
    num: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRate),
    average: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRateAverage)
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "gauges-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u5904\u7406\u65F6\u957F",
    unit: "\u5206",
    min: 0,
    max: getMinHundred(Math.max((efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinute) || 0, (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinuteAverage) || 0)),
    num: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinute) || 0,
    average: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinuteAverage) || 0
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "gauges-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u53CA\u65F6\u5173\u95ED\u7387",
    unit: "%",
    min: 0,
    max: 100,
    num: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRate),
    average: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRateAverage)
  }))))) : null);
};
var _default = exports["default"] = RightBottom;
//# sourceMappingURL=RightBottom.js.map
