"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 _groupBy = _interopRequireDefault(require("lodash/groupBy"));
var _antd = require("antd");
var _vmFilter = require("../../../vm-filter");
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _RightBottom = require("../OverView/RightBottom");
var _FLZL = require("./FLZL");
var _Trend = require("../OverView/Trend");
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 _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; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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 transferData(data) {
  var chartData = [];
  var xAxis = [];
  var dataGroupByDate = (0, _groupBy["default"])(data, 'garbageTypeName');
  var count = 0;
  for (var key in dataGroupByDate) {
    dataGroupByDate[key].forEach(function (item, index) {
      var x = "".concat(item.periodBegin, "-").concat(item.periodEnd);
      if (!xAxis.includes(x)) {
        xAxis.push(x);
      }
      chartData.push([index, count, item.count]);
    });
    count++;
  }
  return {
    xAxis: xAxis,
    yAxis: Object.keys(dataGroupByDate),
    chartData: chartData
  };
}
var getDistributionChart = function getDistributionChart(data) {
  var _transferData = transferData(data),
    xAxis = _transferData.xAxis,
    yAxis = _transferData.yAxis,
    chartData = _transferData.chartData;
  var max = Math.max.apply(Math, _toConsumableArray(chartData.map(function (item) {
    return item[2];
  })));
  if (!(chartData === null || chartData === void 0 ? void 0 : chartData.length)) return {};
  return {
    tooltip: {
      position: 'top',
      formatter: function formatter(params) {
        var value = params.value,
          marker = params.marker,
          name = params.name;
        var garbageType = yAxis[value[1]];
        return "<div>".concat(garbageType, " ").concat(name, "</div><div>").concat(marker, " \u91CD\u91CF\uFF1A").concat(value[2], "kg</div>");
      }
    },
    grid: {
      top: 50,
      bottom: 0,
      right: 0,
      left: 0,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: xAxis,
      splitArea: {
        show: true
      },
      axisLabel: {
        color: '#fff'
      },
      axisTick: {
        show: false
      }
    },
    yAxis: {
      type: 'category',
      data: yAxis,
      splitArea: {
        show: true
      },
      axisLabel: {
        color: '#fff'
      },
      axisTick: {
        show: false
      }
    },
    visualMap: {
      min: 0,
      max: max,
      calculable: true,
      orient: 'horizontal',
      left: 'center',
      top: 0,
      inRange: {
        color: ['#364357', '#00759C', '#29A8F0', '#F5B829', '#E7473F']
      },
      textStyle: {
        color: '#fff'
      }
    },
    series: [{
      name: '满溢时段分布',
      type: 'heatmap',
      data: chartData,
      label: {
        show: true
      },
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }]
  };
};
var MY = function MY(_ref) {
  var _ref$classPrefix = _ref.classPrefix,
    classPrefix = _ref$classPrefix === void 0 ? '' : _ref$classPrefix,
    id = _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),
    throwDate = _useState4[0],
    setThrowDate = _useState4[1];
  // 时段分布日期
  var _useState5 = (0, _react.useState)((0, _moment["default"])()),
    _useState6 = _slicedToArray(_useState5, 2),
    disDate = _useState6[0],
    setDisDate = _useState6[1];
  // 发生次数一周趋势日期范围
  var _useState7 = (0, _react.useState)([(0, _moment["default"])().subtract(7, 'day'), (0, _moment["default"])().subtract(1, 'day')]),
    _useState8 = _slicedToArray(_useState7, 2),
    trendTimes = _useState8[0],
    setTrendTimes = _useState8[1];
  // 工单处理效率
  var myEfficiency = _api.alarmService.myEfficiency({
    housingEstateId: id,
    beginTime: efficiencyDate.format('YYYY-MM-DD 00:00:00'),
    endTime: efficiencyDate.format('YYYY-MM-DD 23:59:59')
  });
  // 满意垃圾类型占比
  var mySumByGarbageType = _api.alarmService.mySumByGarbageType({
    housingEstateId: id,
    beginTime: throwDate.format('YYYY-MM-DD 00:00:00'),
    endTime: throwDate.format('YYYY-MM-DD 23:59:59')
  });
  // 满溢一周趋势分布
  var mySumByGarbageTypeAndDay = _api.alarmService.mySumByGarbageTypeAndDay({
    housingEstateId: id,
    beginTime: trendTimes[0].format('YYYY-MM-DD 00:00:00'),
    endTime: trendTimes[1].format('YYYY-MM-DD 23:59:59')
  });
  // 满溢时段分布
  var mySumByGarbageTypeAndPeriod = _api.alarmService.mySumByGarbageTypeAndPeriod({
    housingEstateId: id,
    beginTime: disDate.format('YYYY-MM-DD 00:00:00'),
    endTime: disDate.format('YYYY-MM-DD 23:59:59')
  });
  var lineData = (mySumByGarbageTypeAndDay || []).map(function (item) {
    return {
      name: item.garbageTypeName,
      count: item.count,
      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: "\u6EE1\u6EA2\u5904\u7406\u65F6\u957F",
    unit: "\u5206",
    min: 0,
    max: (0, _RightBottom.getMinHundred)((myEfficiency === null || myEfficiency === void 0 ? void 0 : myEfficiency.resolveMinute) || 0),
    num: (myEfficiency === null || myEfficiency === void 0 ? void 0 : myEfficiency.resolveMinute) || 0,
    average: false
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6EE1\u6EA2\u5783\u573E\u7C7B\u578B\u5360\u6BD4",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
      value: throwDate,
      onChange: function onChange(date) {
        setThrowDate(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, !(mySumByGarbageType === null || mySumByGarbageType === void 0 ? void 0 : mySumByGarbageType.length) ? (/*#__PURE__*/_react["default"].createElement(_index.Empty, null)) : (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: (0, _FLZL.getPieOption)({
      data: (mySumByGarbageType || []).map(function (item) {
        return {
          name: item.garbageTypeName,
          count: item.count
        };
      }),
      center: ['30%', '50%'],
      legend: {
        left: '55%'
      }
    }),
    style: {
      width: '100%',
      height: '100%'
    }
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6EE1\u6EA2\u65F6\u6BB5\u5206\u5E03",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
      value: disDate,
      onChange: function onChange(date) {
        setDisDate(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, !(mySumByGarbageTypeAndPeriod === null || mySumByGarbageTypeAndPeriod === void 0 ? void 0 : mySumByGarbageTypeAndPeriod.length) ? (/*#__PURE__*/_react["default"].createElement(_index.Empty, null)) : (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getDistributionChart(mySumByGarbageTypeAndPeriod || [])
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6EE1\u6EA2\u4E00\u5468\u53D8\u5316\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 === null || lineData === void 0 ? void 0 : lineData.length) ? /*#__PURE__*/_react["default"].createElement(_index.Empty, null) : /*#__PURE__*/_react["default"].createElement(_vmCharts.Line1, Object.assign({}, (0, _Trend.transferLineData)(lineData))))));
};
var _default = exports["default"] = MY;
//# sourceMappingURL=MY.js.map
