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 { useSetState } from 'ahooks';
import { Col, Row } from 'antd';
import classnames from 'classnames';
import dayjs from 'dayjs';
import * as echarts from 'echarts';
import _ from 'lodash';
import { VmBarCharts, VmFactor, VmLineCharts, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BaseService } from "../../api";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Statistical = function Statistical(_ref) {
  var id = _ref.id;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var _useSetState = useSetState({
      startDate: sDate ? sDate : dayjs().startOf('M'),
      endDate: eDate ? eDate : dayjs()
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = dayjs(state.startDate).format('YYYY-MM-DD');
  var endDate = dayjs(state.endDate).format('YYYY-MM-DD');
  var _BaseService$useSumma = BaseService.useSummaryInfo(id, startDate, endDate),
    summaryInfo = _BaseService$useSumma.summaryInfo,
    completionRate = _BaseService$useSumma.completionRate,
    mileAnalysis = _BaseService$useSumma.mileAnalysis;
  var overRate = summaryInfo !== null && summaryInfo !== void 0 && summaryInfo.planMileage ? (summaryInfo.validMileage / (summaryInfo === null || summaryInfo === void 0 ? void 0 : summaryInfo.planMileage) * 100).toFixed(2) : 0;
  var xAxis = mileAnalysis.map(function (item) {
    return item.workDate;
  });
  return /*#__PURE__*/_jsxs(Row, {
    gutter: [16, 16],
    children: [/*#__PURE__*/_jsx(Col, {
      span: 24,
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '作业汇总分析',
        filterType: 'rangePicker',
        filterChange: function filterChange(date) {
          setState({
            startDate: date[0],
            endDate: date[1]
          });
        },
        dateValue: [state.startDate, state.endDate],
        children: /*#__PURE__*/_jsxs(Row, {
          align: 'middle',
          justify: 'center',
          children: [/*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsxs(Row, {
              gutter: [26, 26],
              align: 'middle',
              justify: 'center',
              children: [/*#__PURE__*/_jsx(Col, {
                children: /*#__PURE__*/_jsx(VmFactor, {
                  name: '计划作业里程',
                  unit: '公里',
                  fontType: 'blue',
                  value: (summaryInfo === null || summaryInfo === void 0 ? void 0 : summaryInfo.planMileage) || 0,
                  img: isDark ? require("../../imgs/factor/dark_plan_mileage.png") : require("../../imgs/factor/plan_mileage.png")
                })
              }), /*#__PURE__*/_jsx(Col, {
                children: /*#__PURE__*/_jsx(VmFactor, {
                  name: '核算作业里程',
                  unit: '公里',
                  fontType: 'green',
                  value: (summaryInfo === null || summaryInfo === void 0 ? void 0 : summaryInfo.validMileage) || 0,
                  img: isDark ? require("../../imgs/factor/dark_valid_mileage.png") : require("../../imgs/factor/valid_mileage.png")
                })
              }), /*#__PURE__*/_jsx(Col, {
                children: /*#__PURE__*/_jsx(VmFactor, {
                  name: '整体完成率',
                  unit: '%',
                  fontType: 'cyan',
                  value: overRate,
                  img: isDark ? require("../../imgs/factor/dark_over_rate.png") : require("../../imgs/factor/over_rate.png")
                })
              })]
            })
          }), /*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsxs("div", {
              className: classnames('road-statistic-summary-main-rate', {
                'road-statistic-summary-main-rate-dark': isDark
              }),
              children: [/*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--yellow-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '<50%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_yellow: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completionRate === null || completionRate === void 0 ? void 0 : completionRate.dayNum1) || 0
                  }), "\u5929"]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: '#36A1FF'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '50%≤完成率<80%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_blue: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completionRate === null || completionRate === void 0 ? void 0 : completionRate.dayNum2) || 0
                  }), "\u5929"]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--green-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '80%≤完成率<100%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_green: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completionRate === null || completionRate === void 0 ? void 0 : completionRate.dayNum3) || 0
                  }), "\u5929"]
                })]
              }), /*#__PURE__*/_jsxs("div", {
                className: "road-statistic-summary-main-rate--item",
                children: [/*#__PURE__*/_jsxs("div", {
                  className: "road-statistic-summary-main-rate--label",
                  children: [/*#__PURE__*/_jsx("div", {
                    className: "road-statistic-summary-main-rate--block",
                    style: {
                      background: 'var(--blue-color)'
                    }
                  }), /*#__PURE__*/_jsx("span", {
                    children: '=100%'
                  })]
                }), /*#__PURE__*/_jsxs("div", {
                  className: classnames('road-statistic-summary-main-rate--value', {
                    white_blue: isDark
                  }),
                  children: [/*#__PURE__*/_jsx("span", {
                    children: (completionRate === null || completionRate === void 0 ? void 0 : completionRate.dayNum4) || 0
                  }), "\u5929"]
                })]
              })]
            })
          })]
        })
      })
    }), /*#__PURE__*/_jsx(Col, {
      span: 24,
      flex: 'auto',
      children: /*#__PURE__*/_jsxs(Row, {
        gutter: [16, 16],
        children: [/*#__PURE__*/_jsx(Col, {
          span: 12,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '作业里程分析',
            children: /*#__PURE__*/_jsx(VmBarCharts, {
              height: 299,
              dataList: [{
                name: '计划里程',
                data: _.map(mileAnalysis, 'planMileage'),
                color: 'geekblue'
              }, {
                name: '核算作业里程',
                data: _.map(mileAnalysis, 'workMileage'),
                color: 'green'
              }],
              xAxis: xAxis,
              yAxisList: [{
                key: '',
                unit: 'km',
                name: '(km)'
              }]
            })
          })
        }), /*#__PURE__*/_jsx(Col, {
          span: 12,
          children: /*#__PURE__*/_jsx(VmWrapper, {
            title: '作业完成率分析',
            children: /*#__PURE__*/_jsx(VmLineCharts, {
              dataList: [{
                name: '作业完成率',
                data: _.map(mileAnalysis, 'rate'),
                color: '#009DFF',
                smooth: true,
                symbol: 'none',
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(0, 157, 255, 0.30)'
                  },
                  // 半透明
                  {
                    offset: 1,
                    color: 'rgba(0, 157, 255, 0)'
                  } // 更透明
                  ])
                }
              }],
              xAxis: xAxis,
              unit: '%',
              height: 299,
              showLegend: false
            })
          })
        })]
      })
    })]
  });
};
export default Statistical;