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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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(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(arr) { if (Array.isArray(arr)) return arr; }
import { Col, Row } from 'antd';
import dayjs from 'dayjs';
import * as echarts from 'echarts';
import { useContext, useState } from 'react';
import { VmBarCharts, VmFactor, VmLineCharts, VmProgress, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { transformRgb } from "../../../../_util";
import { LjsyService } from "../../../api";
import Info from "../../../components/Info";
import darkTrashIcon from "../../../imgs/factor/dark_trash.png";
import darkWeightIcon from "../../../imgs/factor/dark_weight.png";
import darkPointIcon from "../../../imgs/factor/dark_ys_point.png";
import trashIcon from "../../../imgs/factor/trash.png";
import weightIcon from "../../../imgs/factor/weight.png";
import pointIcon from "../../../imgs/factor/ys_point.png";
import { CarContext } from "../../../index";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var legendColorMap = {
  计划收集点位: 'geekblue',
  计划内已收: 'green',
  已收点位: 'green',
  计划外已收: 'blue',
  任务完成率: ''
};
var BaseInfo = function BaseInfo() {
  var _paramConfigsList$SHO, _paramConfigsList$SHO2;
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    startDate = _useContext.startDate,
    info = _useContext.info;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState(dayjs(startDate)),
    _useState2 = _slicedToArray(_useState, 2),
    date = _useState2[0],
    setDate = _useState2[1];
  var _LjsyService$useGetWo = LjsyService.useGetWorkInfo({
      carId: id,
      startDate: dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'),
      endDate: dayjs(date).format('YYYY-MM-DD')
    }),
    taskDaySummary = _LjsyService$useGetWo.taskDaySummary;
  var _LjsyService$useGetWo2 = LjsyService.useGetWorkInfoAnalysis({
      carId: id,
      startDate: dayjs(date).subtract(6, 'day').format('YYYY-MM-DD'),
      endDate: dayjs(date).format('YYYY-MM-DD')
    }),
    workInfoAnalysis = _LjsyService$useGetWo2.workInfoAnalysis,
    loading = _LjsyService$useGetWo2.loading;
  var paramConfigsList = LjsyService.useConfig();
  var _LjsyService$useSYCar = LjsyService.useSYCarInfo(id, date.format('YYYY-MM-DD')),
    syInfo = _LjsyService$useSYCar.syInfo;
  var isTask = (syInfo === null || syInfo === void 0 ? void 0 : syInfo.planCollectPoints) > 0; // 是否有任务
  var per = ((syInfo === null || syInfo === void 0 ? void 0 : syInfo.taskCollectPoints) / ((syInfo === null || syInfo === void 0 ? void 0 : syInfo.planCollectPoints) || 1) * 100).toFixed(2);
  var xAxis = _.map(taskDaySummary, 'date');
  var data = [{
    name: '计划收集点位',
    unit: '个',
    value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.planCollectPoints,
    img: isDark ? require("../../../imgs/dark_point.png") : require("../../../imgs/point.png"),
    fontType: 'blue'
  }, {
    name: '计划内已收',
    unit: '个',
    value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.taskCollectPoints,
    img: isDark ? require("../../../imgs/dark_ys_point.png") : require("../../../imgs/ys_point.png"),
    fontType: 'green'
  }, {
    name: '计划内未收',
    unit: '个',
    value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.taskNoCollectPoints,
    img: isDark ? require("../../../imgs/dark_ws_point.png") : require("../../../imgs/ws_point.png"),
    fontType: 'yellow'
  }, {
    name: '计划外已收',
    unit: '个',
    value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.noneTaskCollectPoints,
    img: isDark ? require("../../../imgs/dark_unplanned_point.png") : require("../../../imgs/unplanned_point.png"),
    fontType: 'cyan'
  }];
  if (((_paramConfigsList$SHO = paramConfigsList['SHOW_COLLECTING_BUCKETS']) === null || _paramConfigsList$SHO === void 0 ? void 0 : _paramConfigsList$SHO.value) === 'true') {
    data.push({
      name: '收集桶数',
      unit: '桶',
      value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.bucketNum,
      img: isDark ? require("../../../imgs/dark_trash.png") : require("../../../imgs/trash.png"),
      fontType: 'blue'
    });
  }
  if (((_paramConfigsList$SHO2 = paramConfigsList['SHOW_WEIGHTING']) === null || _paramConfigsList$SHO2 === void 0 ? void 0 : _paramConfigsList$SHO2.value) === 'true') {
    data.push({
      name: '收集重量',
      unit: 'kg',
      value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.weight,
      img: isDark ? require("../../../imgs/dark_weight.png") : require("../../../imgs/weight.png"),
      fontType: 'blue'
    });
  }
  var blueColor = '#1677FF';
  var greenColor = '#0FB964';
  var yellowColor = '#ffaa00';
  var colorOpacity = 0.2;
  if (isDark) {
    blueColor = '#0095FF';
    greenColor = '#36AB78';
    colorOpacity = 0.6;
  }
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    style: {
      height: '100%'
    },
    children: [/*#__PURE__*/_jsx(Info, {}), /*#__PURE__*/_jsx(Col, {
      flex: '1',
      style: {
        minWidth: 0,
        height: '100%'
      },
      children: /*#__PURE__*/_jsxs("div", {
        className: 'vtx-car-info-right-wrap',
        children: [/*#__PURE__*/_jsx("div", {
          style: {
            height: 243
          },
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '运行信息',
            filterType: "datePicker",
            dateValue: date,
            filterChange: setDate,
            disabledDate: function disabledDate(current) {
              return current && current > dayjs().endOf('day');
            },
            children: isTask ? /*#__PURE__*/_jsxs(Row, {
              gutter: [47, 47],
              align: 'middle',
              style: {
                height: '100%',
                marginLeft: 30
              },
              children: [/*#__PURE__*/_jsx(Col, {
                flex: '112px',
                children: /*#__PURE__*/_jsx(VmProgress.Circle, {
                  rate: per || 0,
                  name: '完成率'
                })
              }), /*#__PURE__*/_jsx(Col, {
                flex: '1',
                children: /*#__PURE__*/_jsx(Row, {
                  gutter: [0, 27],
                  children: data.map(function (item) {
                    return /*#__PURE__*/_jsx(Col, {
                      span: 8,
                      children: /*#__PURE__*/_jsx(VmFactor, _objectSpread(_objectSpread({}, item), {}, {
                        type: 'sm'
                      }))
                    }, item.name);
                  })
                })
              })]
            }) : /*#__PURE__*/_jsxs(Row, {
              gutter: [40, 40],
              children: [/*#__PURE__*/_jsxs(Col, {
                flex: '1',
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '已收点位',
                  unit: '个',
                  fontType: 'green',
                  img: isDark ? darkPointIcon : pointIcon,
                  value: (syInfo === null || syInfo === void 0 ? void 0 : syInfo.collectPoints) || 0
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    dataList: [{
                      name: '已收点位',
                      data: _.map(taskDaySummary, 'collectPointNum'),
                      color: transformRgb(greenColor, colorOpacity),
                      smooth: true,
                      symbol: 'none',
                      areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                          offset: 0,
                          color: transformRgb(greenColor, colorOpacity)
                        },
                        // 半透明
                        {
                          offset: 1,
                          color: transformRgb(greenColor, 0)
                        } // 更透明
                        ])
                      }
                    }],
                    xAxis: xAxis,
                    gridOption: {
                      top: 0,
                      left: 0,
                      right: 0,
                      bottom: -10
                    },
                    xAxisOption: {
                      show: false,
                      boundaryGap: false
                    },
                    yAxisOption: {
                      show: false
                    },
                    unit: '个'
                  })
                })]
              }), /*#__PURE__*/_jsxs(Col, {
                flex: '1',
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '收集桶数',
                  unit: '桶',
                  fontType: 'blue',
                  value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.bucketNum,
                  img: isDark ? darkTrashIcon : trashIcon
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    dataList: [{
                      name: '收集桶数',
                      data: _.map(taskDaySummary, 'bucketNum'),
                      color: transformRgb(blueColor, colorOpacity),
                      smooth: true,
                      symbol: 'none',
                      areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                          offset: 0,
                          color: transformRgb(blueColor, colorOpacity)
                        },
                        // 半透明
                        {
                          offset: 1,
                          color: transformRgb(blueColor, 0)
                        } // 更透明
                        ])
                      }
                    }],
                    xAxis: xAxis,
                    gridOption: {
                      top: 0,
                      left: 0,
                      right: 0,
                      bottom: -10
                    },
                    xAxisOption: {
                      show: false,
                      boundaryGap: false
                    },
                    yAxisOption: {
                      show: false
                    },
                    unit: '桶'
                  })
                })]
              }), /*#__PURE__*/_jsxs(Col, {
                flex: '1',
                children: [/*#__PURE__*/_jsx(VmFactor, {
                  name: '收集重量',
                  unit: 'kg',
                  fontType: 'yellow',
                  value: syInfo === null || syInfo === void 0 ? void 0 : syInfo.weight,
                  img: isDark ? darkWeightIcon : weightIcon
                }), /*#__PURE__*/_jsx("div", {
                  style: {
                    height: 45,
                    marginTop: 15
                  },
                  children: /*#__PURE__*/_jsx(VmLineCharts, {
                    showLegend: false,
                    unit: 'kg',
                    dataList: [{
                      name: '收集重量',
                      data: _.map(taskDaySummary, 'weight'),
                      color: transformRgb(yellowColor, colorOpacity),
                      smooth: true,
                      symbol: 'none',
                      areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                          offset: 0,
                          color: transformRgb(yellowColor, colorOpacity)
                        },
                        // 半透明
                        {
                          offset: 1,
                          color: transformRgb(yellowColor, 0)
                        } // 更透明
                        ])
                      }
                    }],
                    xAxis: xAxis,
                    gridOption: {
                      top: 0,
                      left: 0,
                      right: 0,
                      bottom: -10
                    },
                    xAxisOption: {
                      show: false,
                      boundaryGap: false
                    },
                    yAxisOption: {
                      show: false
                    }
                  })
                })]
              })]
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: 'vtx-car-info-right-wrap-bottom',
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '近7天运行分析',
            children: /*#__PURE__*/_jsx(VmBarCharts, {
              dataList: (workInfoAnalysis.legends || []).filter(function (legend) {
                return legend !== '任务完成率' && legend !== '日均收集点位';
              }).map(function (legend, index) {
                return {
                  name: legend,
                  data: workInfoAnalysis.values[index],
                  color: legendColorMap[legend] || ''
                };
              }),
              xAxis: workInfoAnalysis.names,
              yAxisList: [{
                key: '',
                unit: '个',
                name: '(个)'
              }, {
                key: "\u2000",
                unit: '%',
                name: '(%)'
              }],
              unit: '个',
              lineList: [{
                name: _.last(workInfoAnalysis.legends || []),
                data: _.map(_.last(workInfoAnalysis.values || []), function (value) {
                  return "\u2000".concat(value);
                }),
                color: isDark ? '#13F97A' : '#0FB964',
                yAxisIndex: 1
              }],
              loading: loading
            })
          })
        })]
      })
    })]
  });
};
export default BaseInfo;