"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.getPieOption = exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _moment = _interopRequireDefault(require("moment"));
var _antd = require("antd");
var _vmFilter = require("../../../vm-filter");
var _vmButton = _interopRequireDefault(require("../../../vm-button"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _RightBottom = require("../OverView/RightBottom");
var _Trend = require("../OverView/Trend");
var _index = require("./index");
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 getPieOption = exports.getPieOption = function getPieOption(_ref) {
  var data = _ref.data,
    center = _ref.center,
    radius = _ref.radius,
    _ref$legend = _ref.legend,
    legend = _ref$legend === void 0 ? {} : _ref$legend;
  var total = (data || []).reduce(function (pre, cur) {
    return pre + cur.count;
  }, 0);
  return {
    tooltip: {
      trigger: 'item'
    },
    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.name === name;
        });
        var percent = total && (obj === null || obj === void 0 ? void 0 : obj.count) ? (obj.count / total * 100).toFixed(2) : 0;
        return "{a|".concat(name, "}{a|").concat((obj === null || obj === void 0 ? void 0 : obj.count) || 0, "\u6B21}{a|").concat(percent, "%}");
      },
      textStyle: {
        color: '#fff',
        rich: {
          a: {
            width: 70
          }
        }
      }
    }, legend),
    series: [{
      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.name,
          value: item.count
        };
      })
    }]
  };
};
var symbols = {
  'PLASTIC-BAG': require('../../imgs/PLASTIC_BAG.png'),
  NAPKIN: require('../../imgs/NAPKIN.png'),
  BOTTLE: require('../../imgs/BOTTLE.png'),
  CAN: require('../../imgs/CAN.png'),
  KRAFT_PAPER_BOX: require('../../imgs/KRAFT_PAPER_BOX.png'),
  DEFAULT: require('../../imgs/garbage_default.png')
};
var getPictorialBarOption = function getPictorialBarOption(_ref2) {
  var _ref2$title = _ref2.title,
    title = _ref2$title === void 0 ? '本周' : _ref2$title,
    _ref2$data = _ref2.data,
    data = _ref2$data === void 0 ? [] : _ref2$data;
  return {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    grid: {
      containLabel: true,
      left: 20
    },
    yAxis: {
      data: data.map(function (item) {
        return item.name;
      }),
      inverse: true,
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        margin: 30,
        fontSize: 14
      },
      axisPointer: {
        label: {
          show: true,
          margin: 30
        }
      }
    },
    xAxis: {
      splitLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      }
    },
    animationDurationUpdate: 500,
    series: [{
      name: title,
      id: 'bar1',
      type: 'pictorialBar',
      label: {
        show: true,
        position: 'right',
        offset: [10, 0],
        fontSize: 16,
        color: '#fff'
      },
      symbolRepeat: true,
      symbolSize: ['80%', '60%'],
      barCategoryGap: '40%',
      // universalTransition: {
      //     enabled: true,
      //     delay: function (idx, total) {
      //         return (idx / total) * 1000;
      //     }
      // },
      data: data.map(function (item) {
        return {
          value: item.count,
          symbol: "image://".concat(item.symbol)
        };
      })
    }]
  };
};
var FLZL = function FLZL(_ref3) {
  var _ref3$classPrefix = _ref3.classPrefix,
    classPrefix = _ref3$classPrefix === void 0 ? '' : _ref3$classPrefix,
    _ref3$id = _ref3.id,
    id = _ref3$id === void 0 ? '' : _ref3$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),
    chuyuDate = _useState4[0],
    setChuyuDate = _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),
    rankTimes = _useState8[0],
    setRankTimes = _useState8[1];
  // 混投垃圾排行
  var _useState9 = (0, _react.useState)(true),
    _useState10 = _slicedToArray(_useState9, 2),
    thisWeek = _useState10[0],
    setThisWeek = _useState10[1];
  // 工单处理效率
  var efficiencyData = _api.overViewService.resolveEfficiency({
    throwPointId: id,
    businessPackage: 'THROW',
    beginTime: efficiencyDate.format('YYYY-MM-DD 00:00:00'),
    endTime: efficiencyDate.format('YYYY-MM-DD 23:59:59')
  });
  // 近一周趋势
  var alarmByDateData = _api.overViewService.alarmSumByDate({
    throwPointId: id,
    businessPackage: 'THROW',
    beginTime: trendTimes[0].format('YYYY-MM-DD 00:00:00'),
    endTime: trendTimes[1].format('YYYY-MM-DD 23:59:59')
  });
  // 厨余未破袋，混合投放占比
  var throwPercent = _api.alarmService.chuyuFail({
    throwPointId: id,
    beginTime: chuyuDate.format('YYYY-MM-DD 00:00:00'),
    endTime: chuyuDate.format('YYYY-MM-DD 23:59:59')
  });
  // 混投垃圾排行
  var mixRank = _api.alarmService.mixSumRank({
    throwPointId: id,
    beginTime: thisWeek ? rankTimes[0].format('YYYY-MM-DD 00:00:00') : rankTimes[0].subtract(8, 'd').format('YYYY-MM-DD 00:00:00'),
    endTime: thisWeek ? rankTimes[1].format('YYYY-MM-DD 23:59:59') : rankTimes[1].subtract(8, 'd').format('YYYY-MM-DD 23:59:59')
  });
  var barData = (mixRank || []).map(function (item) {
    return {
      name: item.garbageTypeName,
      count: thisWeek ? item.thisWeekCount : item.lastWeekCount,
      // @ts-ignore
      symbol: symbols[item.garbageTypeCode] || symbols.DEFAULT
    };
  });
  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: "\u53A8\u4F59\u5783\u573E\u6295\u653E\u5206\u6790",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
      value: chuyuDate,
      onChange: function onChange(date) {
        setChuyuDate(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getPieOption({
      data: [{
        name: '未破袋投放',
        count: (throwPercent === null || throwPercent === void 0 ? void 0 : throwPercent.trashBagCount) || 0
      }, {
        name: '混合投放',
        count: (throwPercent === null || throwPercent === void 0 ? void 0 : throwPercent.mixedThrowCount) || 0
      }],
      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: "\u6DF7\u6295\u5783\u573E\u6392\u884C",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      value: rankTimes,
      onChange: function onChange(date) {
        if (date[1].diff(date[0], 'd') > 7) {
          _antd.message.warning('时间跨度不能超过7天');
          return;
        }
        setRankTimes(date);
      }
    })
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'center',
      gap: 10
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    name: "\u672C\u5468",
    active: thisWeek,
    onClick: function onClick() {
      return setThisWeek(true);
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    name: "\u4E0A\u5468",
    active: !thisWeek,
    onClick: function onClick() {
      return setThisWeek(false);
    }
  })), !(barData === null || barData === void 0 ? void 0 : barData.length) ? (/*#__PURE__*/_react["default"].createElement(_index.Empty, null)) : (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getPictorialBarOption({
      title: thisWeek ? '本周' : '上周',
      data: barData
    })
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-ldb-item")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\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.length ? /*#__PURE__*/_react["default"].createElement(_index.Empty, null) : /*#__PURE__*/_react["default"].createElement(_vmCharts.Line1, Object.assign({}, (0, _Trend.transferLineData)(lineData))))));
};
var _default = exports["default"] = FLZL;
//# sourceMappingURL=FLZL.js.map
