"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 _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _moment = _interopRequireDefault(require("moment"));
var _vmFilter = require("../../../vm-filter");
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _Hot = require("../OverView/Hot");
var _RightBottom = require("../OverView/RightBottom");
var _Trend = require("../OverView/Trend");
var _FLZL = require("./FLZL");
var _antd = require("antd");
var _index = require("./index");
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 LDB = function LDB(_ref) {
  var _ref$classPrefix = _ref.classPrefix,
    classPrefix = _ref$classPrefix === void 0 ? '' : _ref$classPrefix,
    _ref$id = _ref.id,
    id = _ref$id === void 0 ? '' : _ref$id;
  // 工单处理效率日期
  var _useState = (0, _react.useState)((0, _moment["default"])()),
    _useState2 = _slicedToArray(_useState, 2),
    efficiencyDate = _useState2[0],
    setEfficiencyDate = _useState2[1];
  // 发生时段日期
  var _useState3 = (0, _react.useState)((0, _moment["default"])()),
    _useState4 = _slicedToArray(_useState3, 2),
    alarmDate = _useState4[0],
    setAlarmDate = _useState4[1];
  // 落地包发生次数一周趋势日期范围
  var _useState5 = (0, _react.useState)([(0, _moment["default"])().subtract(7, 'day'), (0, _moment["default"])().subtract(1, 'day')]),
    _useState6 = _slicedToArray(_useState5, 2),
    trendTimes = _useState6[0],
    setTrendTimes = _useState6[1];
  // 落地包发生次数一周分布日期范围
  var _useState7 = (0, _react.useState)([(0, _moment["default"])().subtract(7, 'day'), (0, _moment["default"])().subtract(1, 'day')]),
    _useState8 = _slicedToArray(_useState7, 2),
    disTimes = _useState8[0],
    setDisTimes = _useState8[1];
  // 事件类型分布
  var alarmByTypeData = _api.overViewService.alarmSumByType({
    housingEstateId: id,
    businessPackage: 'LANDING',
    beginTime: alarmDate.format('YYYY-MM-DD 00:00:00'),
    endTime: alarmDate.format('YYYY-MM-DD 23:59:59')
  });
  // 工单处理效率
  var efficiencyData = _api.overViewService.resolveEfficiency({
    housingEstateId: id,
    businessPackage: 'LANDING',
    beginTime: efficiencyDate.format('YYYY-MM-DD 00:00:00'),
    endTime: efficiencyDate.format('YYYY-MM-DD 23:59:59')
  });
  // 近一周趋势
  var alarmByDateData = _api.overViewService.alarmSumByDate({
    housingEstateId: id,
    businessPackage: 'LANDING',
    beginTime: trendTimes[0].format('YYYY-MM-DD 00:00:00'),
    endTime: trendTimes[1].format('YYYY-MM-DD 23:59:59')
  });
  // 一周分布
  var sumByHour = _api.alarmService.aiAlarmGroupByTypeAndHourOneWeek({
    housingEstateId: id,
    beginTime: disTimes[0].format('YYYY-MM-DD 00:00:00'),
    endTime: disTimes[1].format('YYYY-MM-DD 23:59:59'),
    businessPackage: 'LANDING'
  });
  var lineData = (alarmByDateData || []).map(function (item) {
    return {
      name: item.alarmTypeName || '',
      count: item.count || 0,
      day: item.day || ''
    };
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u5DE5\u5355\u5904\u7406\u6548\u7387",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
      value: efficiencyDate,
      onChange: function onChange(date) {
        setEfficiencyDate(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1,
      display: 'flex'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u5173\u95ED\u7387",
    unit: "%",
    min: 0,
    max: 100,
    num: (0, _RightBottom.getPercent)(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRate),
    average: (0, _RightBottom.getPercent)(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRateAverage)
  })), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u5904\u7406\u65F6\u957F",
    unit: "\u5206",
    min: 0,
    max: (0, _RightBottom.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", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u53CA\u65F6\u5173\u95ED\u7387",
    unit: "%",
    min: 0,
    max: 100,
    num: (0, _RightBottom.getPercent)(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRate),
    average: (0, _RightBottom.getPercent)(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRateAverage)
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u843D\u5730\u5305\u53D1\u751F\u65F6\u6BB5\u5BF9\u6BD4",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
      value: alarmDate,
      onChange: function onChange(date) {
        setAlarmDate(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, !(alarmByTypeData === null || alarmByTypeData === void 0 ? void 0 : alarmByTypeData.length) ? (/*#__PURE__*/_react["default"].createElement(_index.Empty, null)) : (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: (0, _FLZL.getPieOption)({
      data: (alarmByTypeData || []).map(function (item) {
        return {
          name: item.alarmTypeName,
          count: item.count
        };
      }),
      center: ['30%', '50%'],
      legend: {
        left: '50%'
      }
    })
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u843D\u5730\u5305\u53D1\u751F\u6B21\u6570\u4E00\u5468\u5206\u5E03",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      value: disTimes,
      onChange: function onChange(date) {
        if (date[1].diff(date[0], 'd') > 7) {
          _antd.message.warning('时间跨度不能超过7天');
          return;
        }
        setDisTimes(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, !(sumByHour === null || sumByHour === void 0 ? void 0 : sumByHour.length) ? (/*#__PURE__*/_react["default"].createElement(_index.Empty, null)) : (/*#__PURE__*/_react["default"].createElement(_vmCharts.Distribute1, {
    data: (0, _Hot.getDistributeChartData)(sumByHour || [])
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u843D\u5730\u5305\u53D1\u751F\u6B21\u6570\u4E00\u5468\u8D8B\u52BF",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      value: trendTimes,
      onChange: function onChange(date) {
        if (date[1].diff(date[0], 'd') > 7) {
          _antd.message.warning('时间跨度不能超过7天');
          return;
        }
        setTrendTimes(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, !lineData ? /*#__PURE__*/_react["default"].createElement(_index.Empty, null) : /*#__PURE__*/_react["default"].createElement(_vmCharts.Line1, Object.assign({}, (0, _Trend.transferLineData)(lineData))))));
};
var _default = exports["default"] = LDB;
//# sourceMappingURL=LDB.js.map
