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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 { useSetState } from 'ahooks';
import { Col, Row } from 'antd';
import dayjs from 'dayjs';
import * as echarts from 'echarts';
import { useContext } from 'react';
import { VmBarCharts, VmFactor, VmLineCharts, VmProgress, VmTable, VmTag, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { JxhService } from "../../../api";
import { CarContext } from "../../../index";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var workTypeColors = ['blue', 'green', 'yellow', 'purple', 'orange'];
var WorkRecord = function WorkRecord() {
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark,
    chartFontColor = _useSettings.chartFontColor;
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    sDate = _useContext.startDate,
    eDate = _useContext.endDate,
    service = _useContext.service,
    info = _useContext.info;
  var _useSetState = useSetState({
      startDate: sDate ? sDate : dayjs().subtract(6, 'day'),
      endDate: eDate ? eDate : dayjs(),
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      order: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var pagination = state.pagination,
    order = state.order;
  var startDate = dayjs(state.startDate).format('YYYY-MM-DD');
  var endDate = dayjs(state.endDate).format('YYYY-MM-DD');
  var _JxhService$useWorkSu = JxhService.useWorkSummaryJxh(id, startDate, endDate, false),
    workSummaryJxhRes = _JxhService$useWorkSu.workSummaryJxhRes,
    loading = _JxhService$useWorkSu.loading;
  // 作业类型
  var _JxhService$useWorkTy = JxhService.useWorkTypeJxh(service),
    workTypeRes = _JxhService$useWorkTy.workTypeRes;
  var workTypeColorMap = (workTypeRes || []).reduce(function (pre, cur, index) {
    pre[cur.code] = workTypeColors[index % workTypeColors.length];
    return pre;
  }, {});
  // 有排班
  var _JxhService$useWorkAn = JxhService.useWorkAnaJxh(id, startDate, endDate, service),
    workAnaJxhRes = _JxhService$useWorkAn.workAnaJxhRes,
    workAnaLoading = _JxhService$useWorkAn.loading;
  var names = workAnaJxhRes.names,
    values = workAnaJxhRes.values,
    extraData = workAnaJxhRes.extraData;
  var _JxhService$useRecord = JxhService.useRecordJxh(id, '', startDate, endDate, pagination.current - 1, order, service),
    recordJxhRes = _JxhService$useRecord.recordJxhRes,
    recordLoading = _JxhService$useRecord.loading;
  var pageChange = function pageChange(page) {
    setState({
      pagination: _objectSpread(_objectSpread({}, pagination), {}, {
        current: page
      })
    });
  };
  var handleTableChange = function handleTableChange(sorter) {
    setState({
      order: "".concat(sorter.order === 'ascend' ? 'ASC' : 'DESC')
    });
  };
  var tableProps = {
    rowKey: 'ruleId',
    pagination: _objectSpread(_objectSpread({}, pagination), {}, {
      total: (recordJxhRes === null || recordJxhRes === void 0 ? void 0 : recordJxhRes.total) || 0,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    handleTableChange: handleTableChange,
    height: '100%',
    dataSource: (recordJxhRes === null || recordJxhRes === void 0 ? void 0 : recordJxhRes.rows) || [],
    loading: recordLoading
  };
  var columns = [{
    title: '作业日期',
    dataIndex: 'workDate',
    key: 'workDate',
    width: 100,
    sorter: true,
    fixed: 'left'
  }, {
    title: '作业开始时间',
    dataIndex: 'workStartTime',
    key: 'workStartTime',
    width: 150,
    sorter: true,
    fixed: 'left'
  }, {
    title: '作业结束时间',
    dataIndex: 'workEndTime',
    key: 'workEndTime',
    width: 150,
    sorter: true,
    fixed: 'left'
  }, {
    title: '作业类型',
    dataIndex: 'workTypeName',
    key: 'workTypeName',
    width: 100,
    fixed: 'left',
    render: function render(text, record) {
      return /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: workTypeColorMap[record.workTypeCode]
      });
    }
  }, {
    title: '作业路段',
    dataIndex: 'roadName',
    key: 'roadName',
    width: 150,
    fixed: 'left',
    ellipsis: true
  }];
  if (extraData !== null && extraData > 0) {
    columns = [].concat(_toConsumableArray(columns), [{
      title: '路段长度(km)',
      dataIndex: 'roadSpace',
      key: 'roadSpace',
      align: 'right',
      width: 110
    }, {
      title: '计划趟次(趟)',
      dataIndex: 'workCount',
      key: 'workCount',
      width: 110,
      align: 'right',
      render: function render(text, record) {
        return /*#__PURE__*/_jsx("span", {
          children: record.completePercent === null ? '-' : text
        });
      }
    }, {
      title: '核算作业里程(km)',
      dataIndex: 'workMileage',
      key: 'workMileage',
      width: 130,
      align: 'right'
    }, {
      title: '作业趟次(趟)',
      dataIndex: 'actualWorkCount',
      key: 'actualWorkCount',
      width: 110,
      align: 'right'
    }, {
      title: '作业均速(km/h)',
      dataIndex: 'workSpeed',
      key: 'workSpeed',
      align: 'right',
      width: 120,
      render: function render(text) {
        return /*#__PURE__*/_jsx("span", {
          children: text === null || text === void 0 ? void 0 : text.toFixed(2)
        });
      }
    }]);
  } else {
    columns = [].concat(_toConsumableArray(columns), [{
      title: '作业里程(km)',
      dataIndex: 'workMileage',
      key: 'workMileage',
      align: 'right',
      width: 120,
      render: function render(text) {
        return text === null || text === void 0 ? void 0 : text.toFixed(2);
      }
    }, {
      title: '路段长度(km)',
      dataIndex: 'roadSpace',
      key: 'roadSpace',
      align: 'right',
      width: 120
    }, {
      title: '作业均速(km/h)',
      dataIndex: 'workSpeed',
      key: 'workSpeed',
      align: 'right',
      width: 140,
      render: function render(text) {
        return /*#__PURE__*/_jsx("span", {
          children: text === null || text === void 0 ? void 0 : text.toFixed(2)
        });
      }
    }]);
  }
  return /*#__PURE__*/_jsxs(Row, {
    style: {
      padding: 16
    },
    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],
        disabledDate: function disabledDate(current) {
          return current && current > dayjs().endOf('day');
        },
        children: /*#__PURE__*/_jsxs(Row, {
          children: [/*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsxs(Row, {
              gutter: [34, 34],
              align: 'middle',
              justify: 'center',
              style: {
                width: '100%',
                height: '100%'
              },
              children: [/*#__PURE__*/_jsx(Col, {
                flex: '108px',
                children: /*#__PURE__*/_jsx(VmProgress.Circle, {
                  rate: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workRate) || 0,
                  name: '有效作业率',
                  strokeColor: isDark ? {
                    '0%': '#009DFF',
                    '100%': '#44FF98'
                  } : {
                    '0%': '#1677FF',
                    '100%': '#48A2FF'
                  }
                })
              }), /*#__PURE__*/_jsxs(Col, {
                children: [(info === null || info === void 0 ? void 0 : info.driveMode) === 'unmanned' ? /*#__PURE__*/_jsx(VmFactor, {
                  name: '计划作业里程',
                  unit: 'km',
                  type: 'sm',
                  value: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.planMileage) || 0,
                  fontType: 'blue',
                  img: isDark ? require("../../../imgs/track_dark.png") : require("../../../imgs/track.png")
                }) : /*#__PURE__*/_jsx(VmFactor, {
                  name: '行驶里程',
                  unit: 'km',
                  type: 'sm',
                  value: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.driveMileage) || 0,
                  fontType: 'blue',
                  img: isDark ? require("../../../imgs/calendar/dark_mileage.png") : require("../../../imgs/calendar/blue_mileage.png")
                }), /*#__PURE__*/_jsx(VmFactor, {
                  name: '核算作业里程',
                  unit: 'km',
                  type: 'sm',
                  fontType: 'green',
                  value: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workMileage) || 0,
                  img: isDark ? require("../../../imgs/calendar/dark_green_mileage.png") : require("../../../imgs/calendar/mileage.png")
                })]
              })]
            })
          }), /*#__PURE__*/_jsx(Col, {
            span: 12,
            children: extraData !== null && extraData > 0 || (info === null || info === void 0 ? void 0 : info.driveMode) === 'unmanned' ? /*#__PURE__*/_jsx(VmLineCharts, {
              xAxis: names,
              unit: "%",
              dataList: [{
                name: '有效完成率',
                data: (values === null || values === void 0 ? void 0 : values.length) > 1 ? values[1] : [],
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                    offset: 0,
                    color: 'rgba(32, 187, 112, 0.30)'
                  }, {
                    offset: 1,
                    color: 'rgba(32, 187, 112, 0.05)'
                  }])
                },
                lineStyle: {
                  color: '#20BB70'
                },
                itemStyle: {
                  color: '#20BB70'
                },
                markLine: {
                  data: [{
                    type: 'average',
                    name: '均值'
                  }],
                  label: {
                    show: true,
                    position: 'insideEndTop',
                    formatter: '{b}: {c}',
                    color: chartFontColor,
                    fontWeight: 'normal'
                  },
                  lineStyle: {
                    color: '#F69518'
                  }
                }
              }],
              loading: workAnaLoading,
              height: 190
            }) : /*#__PURE__*/_jsx(VmBarCharts, {
              xAxis: names,
              dataList: [{
                name: '核算作业里程',
                data: (values === null || values === void 0 ? void 0 : values.length) > 0 ? values[0] : []
              }],
              unit: 'km',
              loading: workAnaLoading,
              height: 190,
              yAxisList: [{
                key: '',
                name: '(km)',
                unit: 'km'
              }]
            })
          })]
        })
      })
    }), /*#__PURE__*/_jsx(Col, {
      span: 24,
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '作业明细',
        children: /*#__PURE__*/_jsx(VmTable, _objectSpread(_objectSpread({
          columns: columns
        }, tableProps), {}, {
          indexFixed: true
        }))
      })
    })]
  });
};
export default WorkRecord;