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 { useSetState } from 'ahooks';
import { Col, Row, Space } from 'antd';
import dayjs from 'dayjs';
import * as echarts from 'echarts';
import { useContext } from 'react';
import { VmFactor, VmLineCharts, VmProgress, VmTable, VmTag, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { Hw2Service, 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 Hw2WorkRecord = function Hw2WorkRecord() {
  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;
  var _useSetState = useSetState({
      startDate: sDate ? sDate : dayjs().subtract(6, 'day'),
      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 _Hw2Service$useWorkRe = Hw2Service.useWorkRecord(id, startDate, endDate),
    workRecord = _Hw2Service$useWorkRe.workRecord,
    loading = _Hw2Service$useWorkRe.loading;
  var _workRecord$totalWork = workRecord.totalWorkInfo,
    totalWorkInfo = _workRecord$totalWork === void 0 ? {} : _workRecord$totalWork,
    _workRecord$workInfo = workRecord.workInfo,
    workInfo = _workRecord$workInfo === void 0 ? [] : _workRecord$workInfo,
    _workRecord$details = workRecord.details,
    details = _workRecord$details === void 0 ? [] : _workRecord$details;
  // 作业类型
  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 tableProps = {
    rowKey: 'ruleId',
    pagination: false,
    dataSource: details || [],
    loading: loading
  };
  var columns = [_defineProperty(_defineProperty({
    title: '排班日期',
    dataIndex: 'workDate',
    key: 'workDate',
    width: 100,
    sorter: true
  }, "sorter", function sorter(a, b) {
    return a.workDate > b.workDate ? 1 : -1;
  }), "fixed", 'left'), {
    title: '排班班次',
    dataIndex: 'shiftInfoName',
    key: 'shiftInfoName',
    width: 150
  }, {
    title: '排班司机',
    dataIndex: 'driverName',
    key: 'driverName',
    width: 120
  }, {
    title: '排班路段',
    dataIndex: 'roadName',
    key: 'roadName',
    width: 150
  }, {
    title: '车道类型',
    dataIndex: 'facilityTypeName',
    key: 'facilityTypeName',
    width: 120
  }, {
    title: '作业类型',
    dataIndex: 'workTypeName',
    key: 'workTypeName',
    width: 100,
    render: function render(text, record) {
      return /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: workTypeColorMap[record.workTypeCode]
      });
    }
  }, {
    title: '排班趟数',
    dataIndex: 'workCount',
    key: 'workCount',
    width: 100,
    ellipsis: true,
    align: 'right'
  }, {
    title: '排班里程(km)',
    dataIndex: 'planMileage',
    key: 'planMileage',
    width: 120,
    ellipsis: true,
    align: 'right'
  }, {
    title: '作业里程(km)',
    dataIndex: 'workMileage',
    key: 'workMileage',
    width: 120,
    ellipsis: true,
    align: 'right'
  }, {
    title: '任务完成率',
    dataIndex: 'completeRate',
    key: 'completeRate',
    width: 120,
    align: 'right',
    render: function render(text) {
      return "".concat(text, "%");
    }
  }, {
    title: '作业质量',
    dataIndex: 'workQuality',
    key: 'workQuality',
    width: 100,
    render: function render(text) {
      var colorMap = {
        优: 'green',
        良: 'yellow',
        差: 'red'
      };
      return text ? /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: colorMap[text]
      }) : '-';
    }
  }];
  return /*#__PURE__*/_jsxs(Row, {
    style: {
      padding: 16,
      height: '100%'
    },
    gutter: [16, 16],
    children: [/*#__PURE__*/_jsx(Col, {
      span: 24,
      style: {
        height: 273
      },
      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: (totalWorkInfo === null || totalWorkInfo === void 0 ? void 0 : totalWorkInfo.completeRate) || 0,
                  name: '完成率',
                  strokeColor: isDark ? {
                    '0%': '#009DFF',
                    '100%': '#44FF98'
                  } : {
                    '0%': '#1677FF',
                    '100%': '#48A2FF'
                  }
                })
              }), /*#__PURE__*/_jsxs(Col, {
                children: [/*#__PURE__*/_jsxs(Space, {
                  size: 30,
                  children: [/*#__PURE__*/_jsx(VmFactor, {
                    name: '排班里程',
                    unit: 'km',
                    type: 'sm',
                    value: (totalWorkInfo === null || totalWorkInfo === void 0 ? void 0 : totalWorkInfo.planMileage) || 0,
                    fontType: 'green',
                    img: isDark ? require("../../../imgs/calendar/dark_green_mileage.png") : require("../../../imgs/calendar/green_mileage.png")
                  }), /*#__PURE__*/_jsx(VmFactor, {
                    name: '行驶里程',
                    unit: 'km',
                    type: 'sm',
                    value: (totalWorkInfo === null || totalWorkInfo === void 0 ? void 0 : totalWorkInfo.driverMileage) || 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: 'blue',
                  value: (totalWorkInfo === null || totalWorkInfo === void 0 ? void 0 : totalWorkInfo.workMileage) || 0,
                  img: isDark ? require("../../../imgs/calendar/dark_mileage.png") : require("../../../imgs/calendar/mileage.png")
                })]
              })]
            })
          }), /*#__PURE__*/_jsx(Col, {
            span: 12,
            children: /*#__PURE__*/_jsx(VmLineCharts, {
              xAxis: _.map(workInfo, 'date'),
              unit: "%",
              dataList: [{
                name: '完成率',
                data: _.map(workInfo, 'completeRate'),
                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: loading,
              height: 190
            })
          })]
        })
      })
    }), /*#__PURE__*/_jsx(Col, {
      span: 24,
      style: {
        height: 'calc(100% - 273px)'
      },
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: '作业明细',
        style: {
          height: '100%'
        },
        children: /*#__PURE__*/_jsx(VmTable, _objectSpread(_objectSpread({
          columns: columns
        }, tableProps), {}, {
          indexFixed: true
        }))
      })
    })]
  });
};
export default Hw2WorkRecord;