"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = YXFX;
var _react = _interopRequireDefault(require("react"));
var echarts = _interopRequireWildcard(require("echarts"));
var _api = require("../../api");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _moment = _interopRequireDefault(require("moment"));
var _lodash = require("lodash");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function YXFX(_ref) {
  var _ref$theme = _ref.theme,
    theme = _ref$theme === void 0 ? 'light' : _ref$theme,
    _ref$id = _ref.id,
    id = _ref$id === void 0 ? '' : _ref$id;
  var textColor = ['dark', 'blue'].includes(theme) ? '#fff' : '#000';
  var _BaseService$useYxfx = _api.BaseService.useYxfx(id, (0, _moment["default"])().subtract(6, 'days').format('YYYY-MM-DD'), (0, _moment["default"])().format('YYYY-MM-DD')),
    _BaseService$useYxfx$ = _BaseService$useYxfx.yxfxData,
    yxfxData = _BaseService$useYxfx$ === void 0 ? [] : _BaseService$useYxfx$;
  var xAxisData = yxfxData.map(function (item) {
    return item.date;
  });
  var ylData = yxfxData.map(function (item) {
    return item.weight;
  });
  var ylDataAvg = (ylData === null || ylData === void 0 ? void 0 : ylData.length) ? (0, _lodash.mean)(ylData).toFixed(2) : '0';
  var ccData = yxfxData.map(function (item) {
    return item.count;
  });
  var ccDataAvg = (ccData === null || ccData === void 0 ? void 0 : ccData.length) ? (0, _lodash.mean)(ccData).toFixed(2) : '0';
  var option = {
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        var _a;
        var str = "<div style=\"text-align:left\">".concat((_a = params === null || params === void 0 ? void 0 : params[0]) === null || _a === void 0 ? void 0 : _a.axisValue, "</div >");
        params.map(function (item) {
          str += '<div>';
          str += item.marker;
          str += "".concat(item.seriesName, "\uFF1A").concat(item.data).concat(item.seriesName === '车次' ? '次' : '吨');
          str += '</div>';
        });
        return str;
      }
    },
    grid: {
      left: '6%',
      right: '5%',
      bottom: 20
    },
    legend: [{
      align: 'left',
      itemHeight: 8,
      itemWidth: 8,
      icon: 'rect',
      itemStyle: {
        color: '#1C86F3'
      },
      textStyle: {
        color: textColor
      },
      data: ['运量'],
      left: '40%'
    }, {
      align: 'left',
      itemHeight: 2,
      itemWidth: 16,
      icon: 'rect',
      itemStyle: {
        color: '#1FB64D'
      },
      textStyle: {
        color: textColor
      },
      data: ['车次'],
      left: '60%'
    }],
    xAxis: [{
      type: 'category',
      data: xAxisData,
      axisPointer: {
        type: 'shadow'
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: textColor
      }
    }],
    yAxis: [{
      show: true,
      type: 'value',
      name: '车次(次)',
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }, {
      type: 'value',
      name: '运量(吨)',
      min: 0,
      interval: 100,
      nameTextStyle: {
        color: textColor
      },
      splitNumber: 5,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: textColor
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: [{
      name: '运量',
      type: 'bar',
      barWidth: 18,
      yAxisIndex: 1,
      data: ylData,
      itemStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: '#1C86F3'
        }, {
          offset: 1,
          color: 'rgba(28, 134, 243, 0)'
        }])
      }
    }, {
      name: '车次',
      type: 'line',
      yAxisIndex: 0,
      data: ccData,
      showSymbol: false,
      itemStyle: {
        color: '#1FB64D'
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "jzlj-card-title"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "jzlj-card-title-text"
  }, "\u8FD17\u5929\u8FD0\u884C\u5206\u6790")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "jzlj-card-content"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "yxfx-top"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "pjryl"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "name"
  }, "\u5E73\u5747\u65E5\u8FD0\u91CF"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "num"
  }, /*#__PURE__*/_react["default"].createElement("span", null, ylDataAvg), /*#__PURE__*/_react["default"].createElement("span", {
    className: "unit"
  }, "\u5428"))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "pjrcc"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "name"
  }, "\u5E73\u5747\u65E5\u8F66\u6B21"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "num",
    style: {
      color: '#20BB70'
    }
  }, /*#__PURE__*/_react["default"].createElement("span", null, ccDataAvg), /*#__PURE__*/_react["default"].createElement("span", {
    className: "unit"
  }, "\u6B21")))), /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: 'calc(100% - 58px - 24px)',
      width: '100%'
    }
  })));
}
//# sourceMappingURL=YXFX.js.map
