"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 _components = require("@vtx/components");

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

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

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

require("./style");

var _roadRuleTime = _interopRequireDefault(require("../../image/road-rule-time.png"));

var _roadRuleNum = _interopRequireDefault(require("../../image/road-rule-num.png"));

var _antd = require("antd");

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 Title = function Title(_ref) {
  var title = _ref.title;

  var _useSettings = (0, _useSettings3["default"])(),
      theme = _useSettings.theme;

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-title ".concat(theme)
  }, title);
}; // 基本信息


var BaseInfo = function BaseInfo(_ref2) {
  var _ref2$data = _ref2.data,
      data = _ref2$data === void 0 ? [] : _ref2$data;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "info-collection"
  }, data.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "info-line",
      key: item.key
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "label"
    }, item.label, "\uFF1A"), /*#__PURE__*/_react["default"].createElement("div", {
      className: "value"
    }, item.value || '--'));
  }));
}; // 总览


var AllView = function AllView(_ref3) {
  var _ref3$dataSource = _ref3.dataSource,
      dataSource = _ref3$dataSource === void 0 ? [] : _ref3$dataSource;
  var columns = [{
    dataIndex: 'work_type_name',
    title: '作业类型'
  }, {
    dataIndex: 'work_mileage',
    title: '作业公里(km)',
    render: function render(text) {
      return (0, _api.toFixd2)(text);
    }
  }, {
    dataIndex: 'work_times',
    title: '作业趟数(趟)',
    render: function render(text) {
      return (0, _api.toFixd2)(text);
    }
  }, {
    dataIndex: 'rate',
    title: '完成率(%)',
    render: function render(text) {
      return (0, _api.toFixd2)(text);
    }
  }];
  return /*#__PURE__*/_react["default"].createElement(_components.VtxDatagrid, {
    dataSource: dataSource,
    columns: columns,
    pagination: false,
    toolbar: false,
    size: "small"
  });
}; // 单条规则


var Rule = function Rule(_ref4) {
  var name = _ref4.name,
      time = _ref4.time,
      num = _ref4.num;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "work-rule"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "work-rule-name"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "dot"
  }), name), /*#__PURE__*/_react["default"].createElement("div", {
    className: "work-rule-time"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _roadRuleTime["default"]
  }), time), /*#__PURE__*/_react["default"].createElement("div", {
    className: "work-rule-num"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _roadRuleNum["default"]
  }), num, "\u8D9F"));
};

Rule.propTypes = {
  name: _propTypes["default"].string,
  time: _propTypes["default"].string,
  num: _propTypes["default"].string | _propTypes["default"].number
}; // 作业规则

var WorkRules = function WorkRules(_ref5) {
  var _ref5$data = _ref5.data,
      data = _ref5$data === void 0 ? [] : _ref5$data;
  return data !== null && data !== void 0 && data.length ? data.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(Rule, {
      key: item.work_type_name,
      name: item.work_type_name,
      time: "".concat(item.work_start_time, "~").concat(item.work_end_time),
      num: item.work_count
    });
  }) : /*#__PURE__*/_react["default"].createElement(_antd.Empty, {
    description: "\u6682\u65E0\u6570\u636E"
  });
}; // 作业车辆


var WorkCars = function WorkCars(_ref6) {
  var _ref6$dataSource = _ref6.dataSource,
      dataSource = _ref6$dataSource === void 0 ? [] : _ref6$dataSource;
  var columns = [{
    dataIndex: 'car_code',
    title: '车牌号',
    width: 80
  }, {
    dataIndex: 'car_type_name',
    title: '车辆类型'
  }, {
    dataIndex: '3',
    title: '作业时间',
    width: 150,
    render: function render(text, record) {
      return record.work_start_time && record.work_end_time ? "".concat((0, _moment["default"])(record.work_start_time).format('HH:mm:ss'), "~").concat((0, _moment["default"])(record.work_end_time).format('HH:mm:ss')) : '';
    }
  }, {
    dataIndex: 'work_mileage',
    title: '作业里程(km)',
    render: function render(text) {
      return (0, _api.toFixd2)(text);
    }
  }, {
    dataIndex: 'work_times',
    title: '作业趟数(趟)',
    render: function render(text) {
      return (0, _api.toFixd2)(text);
    }
  }];
  return /*#__PURE__*/_react["default"].createElement(_components.VtxDatagrid, {
    dataSource: dataSource,
    columns: columns,
    pagination: false,
    toolbar: false,
    size: "small"
  });
};

var BaseContent = function BaseContent(props) {
  var id = props.id,
      defaultDate = props.date;

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

  var _useState = (0, _react.useState)((0, _moment["default"])().format('YYYY-MM-DD')),
      _useState2 = _slicedToArray(_useState, 2),
      date = _useState2[0],
      setDate = _useState2[1];

  var _BaseData$useBaseInfo = _api.BaseData.useBaseInfo(id, date),
      info = _BaseData$useBaseInfo.info,
      workRule = _BaseData$useBaseInfo.workRule,
      workCar = _BaseData$useBaseInfo.workCar,
      roadSummary = _BaseData$useBaseInfo.roadSummary;

  (0, _react.useEffect)(function () {
    defaultDate && setDate(defaultDate);
  }, [defaultDate]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-content",
    style: {
      width: '100%',
      height: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-search"
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxDatePicker, {
    value: date,
    onChange: function onChange(_, dateString) {
      setDate(dateString);
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-data"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u57FA\u672C\u4FE1\u606F"
  }), /*#__PURE__*/_react["default"].createElement(BaseInfo, {
    data: info
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u603B\u89C8"
  }), /*#__PURE__*/_react["default"].createElement(AllView, {
    dataSource: roadSummary
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u4F5C\u4E1A\u89C4\u5219"
  }), /*#__PURE__*/_react["default"].createElement(WorkRules, {
    data: workRule
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "road-base-info"
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: "\u4F5C\u4E1A\u8F66\u8F86"
  }), /*#__PURE__*/_react["default"].createElement(WorkCars, {
    dataSource: workCar
  }))));
};

BaseContent.propTypes = {
  id: _propTypes["default"].string,
  seed: _propTypes["default"].string,
  date: _propTypes["default"].string
};
WorkCars.propTypes = {
  dataSource: _propTypes["default"].array
};
AllView.propTypes = {
  dataSource: _propTypes["default"].array
};
BaseInfo.propTypes = {
  data: _propTypes["default"].array
};
Title.propTypes = {
  title: _propTypes["default"].string
};
var _default = BaseContent;
exports["default"] = _default;
//# sourceMappingURL=base.js.map
