"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _vmFilter = require("../../../vm-filter");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
require("./index.less");
var _api = require("../../api");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _lodash = require("lodash");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; } /**
 * 车辆-报警信息
 */
var Collection = function Collection(props) {
  var id = props.id;
  var _useSettings = (0, _useSettings2["default"])(),
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate,
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor;
  var carInfo = _api.BaseService.useCCCarInfo(id);
  var _useSetState = (0, _ahooks.useSetState)({
      startDate: sDate ? sDate : (0, _moment["default"])().subtract(30, 'day').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : (0, _moment["default"])().format('YYYY-MM-DD'),
      tabKey: '1',
      value: 'WORK'
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = state.startDate,
    endDate = state.endDate;
  var day = (0, _moment["default"])(endDate).diff(startDate, 'day');
  var dayList = [];
  for (var index = 0; index <= day; index++) {
    dayList.push((0, _moment["default"])(startDate).add(index, 'day').format('MM-DD'));
  }
  var _BaseService$useToday = _api.BaseService.useTodayWorkCC(id, (0, _moment["default"])(startDate).format('YYYY-MM-DD 00:00:00'), (0, _moment["default"])(endDate).format('YYYY-MM-DD 23:59:59'), carInfo.garbageType),
    rows = _BaseService$useToday.todayRunCCRes;
  var periodList = _api.CollectionService.getPeriodList({
    carId: id,
    startDay: (0, _moment["default"])(startDate).format('YYYY-MM-DD'),
    endDay: (0, _moment["default"])(endDate).format('YYYY-MM-DD')
  });
  var today = (0, _moment["default"])().format('YYYY-MM-DD');
  var lineOption = {
    color: chartColor,
    tooltip: {
      trigger: 'item',
      formatter: function formatter(val) {
        return val.value[3] + ': ' + val.value[2] + 'kg';
      }
    },
    legend: {
      top: '5%'
    },
    grid: {
      // top: 58,
      left: 24,
      bottom: 12,
      right: 40,
      containLabel: true
    },
    xAxis: {
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLine: {
        show: true
      },
      axisLabel: {
        color: chartFontColor,
        formatter: function formatter(val) {
          return (0, _moment["default"])(val).format('MM-DD');
        }
      },
      data: dayList
    },
    yAxis: [{
      min: new Date((0, _moment["default"])().startOf('date').valueOf()),
      max: new Date((0, _moment["default"])().endOf('date').valueOf()),
      type: 'time',
      nameTextStyle: {
        color: chartFontColor
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: chartFontColor,
        formatter: function formatter(val) {
          return (0, _moment["default"])(val).format('HH:mm');
        }
      },
      axisLine: {
        show: true
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: [{
      type: 'scatter',
      data: rows === null || rows === void 0 ? void 0 : rows.map(function (item) {
        return [(0, _moment["default"])(item.weighTime).format('MM-DD'), (0, _moment["default"])(item.weighTime).format("".concat(today, " HH:mm:ss")), carInfo.garbageType === 'fqyz' ? item.jzyYgWeight : item.netWeight, item.weighTime];
      }),
      symbolSize: 20
    }].concat(_toConsumableArray(carInfo.garbageType === 'fqyz' ? [] : periodList.map(function (item) {
      return {
        name: item.name,
        data: [],
        markArea: {
          data: [[{
            yAxis: (0, _moment["default"])(item.startTime, 'HH:mm:ss').format("".concat(today, " HH:mm:ss"))
          }, {
            yAxis: (0, _moment["default"])(item.endTime, 'HH:mm:ss').format("".concat(today, " HH:mm:ss"))
          }]],
          tooltip: {
            show: true,
            formatter: function formatter() {
              return item.name;
            }
          }
        },
        type: 'bar',
        tooltip: {
          show: false
        }
      };
    })))
  };
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-collection"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-main"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-head"
  }, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
    value: [(0, _moment["default"])(startDate), (0, _moment["default"])(endDate)],
    onChange: function onChange(dates) {
      return dates && handleDateChange((0, _moment["default"])(dates[0]).format('YYYY-MM-DD'), (0, _moment["default"])(dates[1]).format('YYYY-MM-DD'));
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1,
      minHeight: 0
    }
  }, (0, _lodash.isEmpty)(rows) && (0, _lodash.isEmpty)(periodList) ? (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: '200px',
      width: '400px'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: lineOption,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: 500,
      width: '100%'
    }
  })))));
};
var _default = exports["default"] = Collection;
//# sourceMappingURL=index.js.map
