"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 _moment = _interopRequireDefault(require("moment"));

var echarts = _interopRequireWildcard(require("echarts"));

var _components = require("@vtx/components");

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

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

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

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

require("./style");

var _roadPlanMile = _interopRequireDefault(require("../../image/road-plan-mile.png"));

var _roadWorkMile = _interopRequireDefault(require("../../image/road-work-mile.png"));

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 _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 VtxRangePicker = _components.VtxDatePicker.VtxRangePicker;
var Option = _components.VtxSelect.Option;

var Title = function Title(_ref) {
  var title = _ref.title;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-title"
  }, title);
}; // 作业汇总统计


var NumItem = function NumItem(_ref2) {
  var label = _ref2.label,
      num = _ref2.num,
      imgSrc = _ref2.imgSrc;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "statistics-item"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("img", {
    src: imgSrc
  })), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      color: 'rgba(0,0,0,0.85)'
    }
  }, label), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("span", null, (0, _api.toFixd2)(num)), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      color: 'rgba(0,0,0,0.85)'
    }
  }, "\u516C\u91CC"))));
};

var WorkSummaryStatistics = function WorkSummaryStatistics(_ref3) {
  var _ref3$data = _ref3.data,
      data = _ref3$data === void 0 ? {} : _ref3$data;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "statistics-info"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "statistics-row"
  }, /*#__PURE__*/_react["default"].createElement(NumItem, {
    label: "\u8BA1\u5212\u4F5C\u4E1A\u91CC\u7A0B",
    num: data.plan_mileage,
    imgSrc: _roadPlanMile["default"]
  }), /*#__PURE__*/_react["default"].createElement(NumItem, {
    label: "\u5B9E\u9645\u4F5C\u4E1A\u91CC\u7A0B",
    num: data.work_mileage,
    imgSrc: _roadWorkMile["default"]
  })), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      marginTop: 32
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%',
      display: 'flex',
      justifyContent: 'space-between'
    }
  }, /*#__PURE__*/_react["default"].createElement("span", null, "\u6574\u4F53\u5B8C\u6210\u7387"), /*#__PURE__*/_react["default"].createElement("span", null, data.rate, "%")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "progress"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "active_progress",
    style: {
      width: "".concat(data.rate, "%")
    }
  }))));
}; // 作业汇总


var WorkSummary = function WorkSummary(_ref4) {
  var _ref4$data = _ref4.data,
      data = _ref4$data === void 0 ? [] : _ref4$data;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "statistics-work-summary"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 20
    }
  }, data.a), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 12
    }
  }, "\u5929"), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      marginLeft: 16
    }
  }, '完成率<50%')), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 20
    }
  }, data.b), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 12
    }
  }, "\u5929"), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      marginLeft: 16
    }
  }, '50%<=完成率<80%')), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 20
    }
  }, data.c), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 12
    }
  }, "\u5929"), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      marginLeft: 16
    }
  }, '80<=完成率<100%')), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 20
    }
  }, data.d), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      fontSize: 12
    }
  }, "\u5929"), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      marginLeft: 16
    }
  }, '完成率=100%')));
};

var defaultRange = [(0, _moment["default"])().subtract(7, 'd').format('YYYY-MM-DD'), (0, _moment["default"])().format('YYYY-MM-DD')];

var Statistics = function Statistics(props) {
  var id = props.id;

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

  var _useState = (0, _react.useState)(defaultRange),
      _useState2 = _slicedToArray(_useState, 2),
      range = _useState2[0],
      setRange = _useState2[1];

  var _useState3 = (0, _react.useState)('全部'),
      _useState4 = _slicedToArray(_useState3, 2),
      workType = _useState4[0],
      setWorkType = _useState4[1];

  var _BaseData$useStatisti = _api.BaseData.useStatistics(id, range[0], range[1], workType),
      workTotal = _BaseData$useStatisti.workTotal,
      workTypeData = _BaseData$useStatisti.workTypeData,
      workSummary = _BaseData$useStatisti.workSummary,
      workMile = _BaseData$useStatisti.workMile,
      workCompleteRate = _BaseData$useStatisti.workCompleteRate; // 作业里程分析


  var mileOption = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    color: ['#04A9F5', '#1DE9B6'],
    xAxis: {
      type: 'category',
      data: workMile.xAxis
    },
    yAxis: {
      name: '公里',
      type: 'value'
    },
    series: [{
      name: '计划里程',
      type: 'line',
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: '#16B2FB'
        }, {
          offset: 1,
          color: '#8BB9FF'
        }])
      },
      emphasis: {
        focus: 'series'
      },
      data: workMile.planMiles
    }, {
      name: '作业里程',
      type: 'line',
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: '#42FFD0'
        }, {
          offset: 1,
          color: '#CFEECF'
        }])
      },
      emphasis: {
        focus: 'series'
      },
      data: workMile.workMiles
    }]
  }; // 作业完成率

  var rateOption = {
    tooltip: {
      type: 'axis'
    },
    xAxis: {
      type: 'category',
      data: workCompleteRate.xAxis
    },
    yAxis: {
      name: '%',
      type: 'value'
    },
    series: [{
      data: workCompleteRate.rates,
      type: 'bar',
      barWidth: 10,
      itemStyle: {
        normal: {
          color: '#0091FF'
        }
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-content",
    style: {
      width: '100%',
      height: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-search"
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxSelect, {
    value: workType,
    onChange: function onChange(value) {
      return setWorkType(value);
    },
    style: {
      width: 200,
      marginRight: 16
    }
  }, workTypeData.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: item.parmName
    }, item.parmName);
  })), /*#__PURE__*/_react["default"].createElement(VtxRangePicker, {
    value: range,
    onChange: function onChange(_, dateString) {
      setRange(dateString);
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-data"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u4F5C\u4E1A\u6C47\u603B\u7EDF\u8BA1"
  }), /*#__PURE__*/_react["default"].createElement(WorkSummaryStatistics, {
    data: workTotal
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u4F5C\u4E1A\u6C47\u603B"
  }), /*#__PURE__*/_react["default"].createElement(WorkSummary, {
    data: workSummary
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u4F5C\u4E1A\u91CC\u7A0B\u5206\u6790"
  }), /*#__PURE__*/_react["default"].createElement(_vmChart["default"], {
    option: mileOption,
    height: "100%",
    width: "100%"
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-statistics-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u4F5C\u4E1A\u5B8C\u6210\u7387"
  }), /*#__PURE__*/_react["default"].createElement(_vmChart["default"], {
    option: rateOption,
    height: "100%",
    width: "100%"
  }))));
};

Statistics.propTypes = {
  id: _propTypes["default"].string,
  seed: _propTypes["default"].string
};
WorkSummaryStatistics.propTypes = {
  data: _propTypes["default"].object
};
var _default = Statistics;
exports["default"] = _default;
//# sourceMappingURL=statistics.js.map
