"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _ahooks = require("ahooks");

var _moment = _interopRequireDefault(require("moment"));

var _config = require("../../config");

var _vmFilter = require("../vm-filter");

var _vmInfoCollection = _interopRequireDefault(require("../vm-info-collection"));

var _vmChart = _interopRequireWildcard(require("../vm-chart"));

var _useSettings4 = _interopRequireDefault(require("../vm-hooks/useSettings"));

var _vmStatCollection = _interopRequireDefault(require("../vm-stat-collection"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _vmSubTabs = _interopRequireWildcard(require("../vm-sub-tabs"));

var _antd = require("antd");

var _api = require("./api");

require("./style");

var _vehicleAlarmSecondDark = _interopRequireDefault(require("../../image/vehicle-alarm-second-dark.png"));

var _vehicleAlarmSecond = _interopRequireDefault(require("../../image/vehicle-alarm-second.png"));

var _vehicleAlarmTimesDark = _interopRequireDefault(require("../../image/vehicle-alarm-times-dark.png"));

var _vehicleAlarmTimes = _interopRequireDefault(require("../../image/vehicle-alarm-times.png"));

var _vehicleAlarmDayDark = _interopRequireDefault(require("../../image/vehicle-alarm-day-dark.png"));

var _vehicleAlarmDay = _interopRequireDefault(require("../../image/vehicle-alarm-day.png"));

var _vehicleWorkMiles = _interopRequireDefault(require("../../image/vehicle-work-miles.png"));

var _vehicleDriveMiles = _interopRequireDefault(require("../../image/vehicle-drive-miles.png"));

var _vehicleWorkOverspeed = _interopRequireDefault(require("../../image/vehicle-work-overspeed.png"));

var _vehicleWorkOverspeedTime = _interopRequireDefault(require("../../image/vehicle-work-overspeedTime.png"));

var _vehicleWorkRate = _interopRequireDefault(require("../../image/vehicle-work-rate.png"));

var _vehicleWorkTime = _interopRequireDefault(require("../../image/vehicle-work-time.png"));

var _vehicleWorkMilesDark = _interopRequireDefault(require("../../image/vehicle-work-miles-dark.png"));

var _vehicleDriveMilesDark = _interopRequireDefault(require("../../image/vehicle-drive-miles-dark.png"));

var _vehicleWorkOverspeedDark = _interopRequireDefault(require("../../image/vehicle-work-overspeed-dark.png"));

var _vehicleWorkOverspeedTimeDark = _interopRequireDefault(require("../../image/vehicle-work-overspeedTime-dark.png"));

var _vehicleWorkRateDark = _interopRequireDefault(require("../../image/vehicle-work-rate-dark.png"));

var _vehicleWorkTimeDark = _interopRequireDefault(require("../../image/vehicle-work-time-dark.png"));

var _element = require("./element");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }

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(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var BaseContent = function BaseContent(props) {
  var _workSummary$duration, _workSummary$duration2, _workSummary$duration3;

  var id = props.id,
      seed = props.seed,
      carType = props.carType;

  var _useSettings = (0, _useSettings4["default"])(),
      isDark = _useSettings.isDark;

  var _useSetState = (0, _ahooks.useSetState)({
    start: (0, _moment["default"])().subtract(7, 'd'),
    end: (0, _moment["default"])()
  }),
      _useSetState2 = _slicedToArray(_useSetState, 2),
      state = _useSetState2[0],
      setState = _useSetState2[1];

  var _BaseData$useBaseInfo = _api.BaseData.useBaseInfo(id, state.start, state.end),
      info = _BaseData$useBaseInfo.info,
      jxhInfo = _BaseData$useBaseInfo.jxhInfo,
      realTimeInfo = _BaseData$useBaseInfo.realTimeInfo,
      permissionInfo = _BaseData$useBaseInfo.permissionInfo,
      workSummary = _BaseData$useBaseInfo.workSummary,
      workChart = _BaseData$useBaseInfo.workChart;

  var _BaseData$useAlarmSta = _api.BaseData.useAlarmStat(id, state.start, state.end),
      statInfo = _BaseData$useAlarmSta.statInfo,
      statChartInfo = _BaseData$useAlarmSta.statChartInfo;

  var workMileage = _api.BaseData.getTodayWorkMile(id);

  (0, _react.useEffect)(function () {
    if (seed) setState({
      start: (0, _moment["default"])().subtract(7, 'd'),
      end: (0, _moment["default"])()
    });
  }, [id, seed]);
  var statData = [{
    icon: isDark ? _vehicleAlarmTimesDark["default"] : _vehicleAlarmTimes["default"],
    label: '违规次数',
    value: statInfo === null || statInfo === void 0 ? void 0 : statInfo.times,
    unit: '次'
  }, {
    icon: isDark ? _vehicleAlarmDayDark["default"] : _vehicleAlarmDay["default"],
    label: '累计违规天数',
    value: statInfo === null || statInfo === void 0 ? void 0 : statInfo.days,
    unit: '天'
  }, {
    icon: isDark ? _vehicleAlarmSecondDark["default"] : _vehicleAlarmSecond["default"],
    label: '累计违规时长',
    value: [statInfo === null || statInfo === void 0 ? void 0 : statInfo.hour, statInfo.minute, statInfo.second],
    unit: ['时', '分', '秒']
  }]; // 机械化车辆统计信息

  var jxhStatData = [{
    icon: isDark ? _vehicleDriveMilesDark["default"] : _vehicleDriveMiles["default"],
    label: '行驶里程',
    value: workSummary === null || workSummary === void 0 ? void 0 : workSummary.total_mileage,
    unit: 'km'
  }, {
    icon: isDark ? _vehicleWorkMilesDark["default"] : _vehicleWorkMiles["default"],
    label: '作业里程',
    value: workSummary === null || workSummary === void 0 ? void 0 : workSummary.work_mileage,
    unit: 'km'
  }, {
    icon: isDark ? _vehicleWorkRateDark["default"] : _vehicleWorkRate["default"],
    label: '作业率',
    value: workSummary === null || workSummary === void 0 ? void 0 : workSummary.rate,
    unit: '%'
  }, {
    icon: isDark ? _vehicleWorkTimeDark["default"] : _vehicleWorkTime["default"],
    label: '作业时长',
    value: [((_workSummary$duration = workSummary.duration) === null || _workSummary$duration === void 0 ? void 0 : _workSummary$duration.hour) || 0, ((_workSummary$duration2 = workSummary.duration) === null || _workSummary$duration2 === void 0 ? void 0 : _workSummary$duration2.minute) || 0, (workSummary === null || workSummary === void 0 ? void 0 : (_workSummary$duration3 = workSummary.duration) === null || _workSummary$duration3 === void 0 ? void 0 : _workSummary$duration3.seconds) || 0],
    unit: ['时', '分', '秒']
  } // {
  //     icon: isDark ? workOverSpeedDarkImg : workOverSpeedImg,
  //     label: '作业超速',
  //     value: 0,
  //     unit: '%',
  // },
  // {
  //     icon: isDark ? workOverSpeedTimeDarkImg : workOverSpeedTimeImg,
  //     label: '作业超速时长',
  //     value: 0,
  //     unit: ['时', '分', '秒'],
  // },
  ];

  var handleDateChange = function handleDateChange(start, end) {
    setState({
      start: start,
      end: end
    });
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "vehicle-base-content",
    style: {
      width: '100%',
      height: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "left"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "info-container"
  }, /*#__PURE__*/_react["default"].createElement(_element.TimeInfo, {
    value: realTimeInfo.time
  }), /*#__PURE__*/_react["default"].createElement(_element.LocationInfo, {
    value: realTimeInfo.location
  })), /*#__PURE__*/_react["default"].createElement(_element.StatusInfo, {
    value: realTimeInfo.status
  }), /*#__PURE__*/_react["default"].createElement(_element.VehicleRing, null), /*#__PURE__*/_react["default"].createElement(_element.VehicleSpeed, {
    value: realTimeInfo.speed
  }), /*#__PURE__*/_react["default"].createElement(_element.VehicleDrive, {
    percent: realTimeInfo.percent,
    drive: realTimeInfo.mile,
    showWork: carType === 'jxh',
    work: workMileage
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "right"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "top"
  }, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
    value: [state.start, state.end],
    onChange: function onChange(dates) {
      return dates && handleDateChange(dates[0], dates[1]);
    },
    style: {
      position: 'absolute',
      top: 24,
      right: 32
    }
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "info"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs["default"], {
    defaultActiveKey: "base"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
    tab: "\u57FA\u7840\u4FE1\u606F",
    key: "base"
  }, /*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
    data: info
  })), carType === 'jxh' ? /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
    tab: "\u5C5E\u6027\u4FE1\u606F",
    key: "info",
    style: {
      height: 200,
      overflow: 'auto'
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
    data: jxhInfo
  })) : /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
    tab: "\u9053\u8DEF\u8BB8\u53EF\u8BC1",
    key: "permission"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Carousel, null, permissionInfo.map(function (info) {
    return /*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
      key: info.code,
      data: info
    });
  }))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "stat"
  }, /*#__PURE__*/_react["default"].createElement(_vmChart.ChartTitle, {
    title: "\u7EDF\u8BA1\u4FE1\u606F"
  }), /*#__PURE__*/_react["default"].createElement(_vmStatCollection["default"], {
    items: carType === 'jxh' ? jxhStatData : statData
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "hr"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "chart-container"
  }, /*#__PURE__*/_react["default"].createElement(_vmChart.ChartTitle, {
    title: carType === 'jxh' ? '作业分析' : '违规分析'
  }), carType === 'jxh' ? /*#__PURE__*/_react["default"].createElement(WorkChart, {
    data: workChart || []
  }) : /*#__PURE__*/_react["default"].createElement(StatChart, {
    data: statChartInfo || []
  }))));
};

BaseContent.propTypes = {
  id: _propTypes["default"].string,
  seed: _propTypes["default"].string,
  carType: _propTypes["default"].string
};

var StatChart = function StatChart(props) {
  var data = props.data;

  var _useSettings2 = (0, _useSettings4["default"])(),
      isDark = _useSettings2.isDark;

  var total = (0, _react.useMemo)(function () {
    var result = 0;

    var _iterator = _createForOfIteratorHelper(data),
        _step;

    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var item = _step.value;
        result += item.count;
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }

    return result;
  }, [data]);
  var chartData = data.map(function (item, index) {
    return {
      value: item.count,
      name: item.alarmTypeName,
      itemStyle: {
        color: item.color ? _config.ECHARTS_COLOR[item.color] : _config.COLOR_COLLECTION[index]
      }
    };
  });
  var option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      icon: 'circle',
      orient: 'vertical',
      top: '35%',
      left: '65%',
      itemHeight: 8,
      itemWidth: 8,
      itemGap: 14,
      textStyle: {
        fontSize: 14,
        fontFamily: 'PingFangSC-Regular',
        rich: {
          a: {
            color: isDark ? 'white' : '#666'
          },
          b: {
            color: isDark ? 'white' : '#222'
          }
        }
      },
      formatter: function formatter(name) {
        var _data$find;

        var num = ((_data$find = data.find(function (i) {
          return i.alarmTypeName === name;
        })) === null || _data$find === void 0 ? void 0 : _data$find.count) || 0;
        return "{a|".concat(name, "}      {b|").concat(num, "\u6B21(").concat(total === 0 ? 0 : Math.round(num * 100 / total), "%)}");
      }
    },
    graphic: [{
      type: 'group',
      left: '40%',
      top: '50%',
      bounding: 'raw',
      children: [{
        type: 'text',
        style: {
          text: '违规次数',
          fontFamily: 'PingFangSC-Regular',
          fontSize: 14,
          fill: '#858A91',
          align: 'center',
          y: -20
        }
      }, {
        type: 'text',
        style: {
          text: total,
          fontWeight: 'bold',
          fontSize: 20,
          fill: isDark ? 'white' : '#222',
          fontFamily: 'DIN-Regular',
          align: 'center',
          y: 10
        }
      }]
    }],
    series: [{
      name: '',
      type: 'pie',
      radius: ['45%', '70%'],
      center: ['40%', '50%'],
      label: {
        show: false
      },
      labelLine: {
        show: false
      },
      data: chartData
    }]
  };
  return /*#__PURE__*/_react["default"].createElement(_vmChart["default"], {
    option: option,
    height: 260,
    width: "100%"
  });
};

var WorkChart = function WorkChart(_ref) {
  var _ref$data = _ref.data,
      data = _ref$data === void 0 ? [] : _ref$data;

  var _useSettings3 = (0, _useSettings4["default"])(),
      isDark = _useSettings3.isDark;

  var rateData = data.map(function (item) {
    return item.rate ? item.rate.toFixed(2) : 0;
  });
  var mileData = data.map(function (item) {
    return item.work_mileage ? item.work_mileage.toFixed(2) : 0;
  });
  var xAxis = data.map(function (item) {
    return item.work_date || 0;
  });
  var option = {
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      icon: 'circle',
      itemHeight: 8,
      itemWidth: 8,
      itemGap: 14,
      textStyle: {
        fontSize: 14,
        fontFamily: 'PingFangSC-Regular',
        rich: {
          a: {
            color: isDark ? 'white' : '#666'
          },
          b: {
            color: isDark ? 'white' : '#222'
          }
        }
      }
    },
    xAxis: [{
      type: 'category',
      data: xAxis
    }],
    yAxis: [{
      type: 'value',
      name: 'km',
      min: 0
    }, {
      type: 'value',
      min: 0,
      max: 100,
      axisLabel: {
        formatter: '{value} %'
      }
    }],
    series: [{
      name: '作业里程',
      type: 'bar',
      data: mileData
    }, {
      name: '作业率',
      type: 'line',
      data: rateData,
      yAxisIndex: 1
    }]
  };
  return /*#__PURE__*/_react["default"].createElement(_vmChart["default"], {
    option: option,
    height: 260,
    width: "100%"
  });
};

StatChart.propTypes = {
  data: _propTypes["default"].array
};
WorkChart.propTypes = {
  data: _propTypes["default"].array
};
var _default = BaseContent;
exports["default"] = _default;
//# sourceMappingURL=base.js.map
