"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"] = WorkJxh;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _progress = _interopRequireDefault(require("antd/es/progress"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _vmSubTabs = require("../../../vm-sub-tabs");
var _vmFilter = require("../../../vm-filter");
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _vmImageText = _interopRequireDefault(require("../../../vm-image-text"));
var _Wcl = _interopRequireDefault(require("./Wcl"));
var _api = require("../../api");
var _zld = _interopRequireDefault(require("../../imgs/zld.png"));
var _zlc = _interopRequireDefault(require("../../imgs/zlc.png"));
var _pjwcl = _interopRequireDefault(require("../../imgs/pjwcl.png"));
var _zld_light = _interopRequireDefault(require("../../imgs/zld_light.png"));
var _zlc_light = _interopRequireDefault(require("../../imgs/zlc_light.png"));
var _pjwcl_light = _interopRequireDefault(require("../../imgs/pjwcl_light.png"));
var _zld_blue = _interopRequireDefault(require("../../imgs/zld_blue.png"));
var _zlc_blue = _interopRequireDefault(require("../../imgs/zlc_blue.png"));
var _Zylc = _interopRequireDefault(require("./Zylc"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _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; }
function WorkJxh(_ref) {
  var id = _ref.id,
    service = _ref.service;
  var _useSettings = (0, _useSettings2["default"])(),
    theme = _useSettings.theme,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var getSrc = function getSrc(code) {
    var obj = {};
    if (theme === 'dark') {
      obj = {
        zld: _zld["default"],
        zlc: _zlc["default"],
        pjwcl: _pjwcl["default"]
      };
    } else if (theme === 'blue') {
      obj = {
        zld: _zld_blue["default"],
        zlc: _zlc_blue["default"]
      };
    } else {
      obj = {
        zld: _zld_light["default"],
        zlc: _zlc_light["default"],
        pjwcl: _pjwcl_light["default"]
      };
    }
    return obj[code];
  };
  var _useSetState = (0, _ahooks.useSetState)({
      workTypeCodes: 'all',
      tabItems: [{
        key: 'all',
        label: '全部'
      }],
      startDate: sDate ? sDate : (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : (0, _moment["default"])().format('YYYY-MM-DD'),
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      order: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var workTypeCodes = state.workTypeCodes,
    startDate = state.startDate,
    endDate = state.endDate,
    pagination = state.pagination,
    tabItems = state.tabItems,
    order = state.order;
  // 作业类型
  var _WorkServicve$useWork = _api.WorkServicve.useWorkTypeJxh(service),
    workTypeRes = _WorkServicve$useWork.workTypeRes;
  // 无排班
  var _BaseService$useWorkS = _api.BaseService.useWorkSummaryJxh(id, startDate, endDate, service),
    workSummaryJxhRes = _BaseService$useWorkS.workSummaryJxhRes;
  // 有排班
  var _BaseService$useWorkA = _api.BaseService.useWorkAnaJxh(id, startDate, endDate, service),
    workAnaJxhRes = _BaseService$useWorkA.workAnaJxhRes;
  var names = workAnaJxhRes.names,
    values = workAnaJxhRes.values,
    extraData = workAnaJxhRes.extraData;
  var _WorkServicve$useReco = _api.WorkServicve.useRecordJxh(id, workTypeCodes === 'all' ? '' : workTypeCodes, startDate, endDate, pagination.current - 1, order, service),
    recordJxhRes = _WorkServicve$useReco.recordJxhRes;
  (0, _react.useEffect)(function () {
    var tabItemList = [{
      key: 'all',
      label: '全部'
    }];
    if ((workTypeRes === null || workTypeRes === void 0 ? void 0 : workTypeRes.length) > 0) {
      workTypeRes.forEach(function (ele) {
        tabItemList.push({
          key: ele.code,
          label: ele.name
        });
      });
      setState({
        tabItems: tabItemList
      });
    }
  }, [workTypeRes]);
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      }
    });
  };
  // const getColor = (code: string) => {
  //     let color = '';
  //     switch (code) {
  //         case '机扫':
  //             color = '#FFEF41';
  //             break;
  //         case '洗地':
  //             color = '#52c41a';
  //             break;
  //         case '洒水':
  //             color = '#35EAFF';
  //             break;
  //         default:
  //             break;
  //     }
  //     return color;
  // };
  var columns = [{
    title: '作业日期',
    dataIndex: 'workDate',
    key: 'workDate',
    width: 100,
    sorter: true
  }, {
    title: '作业开始时间',
    dataIndex: 'workStartTime',
    key: 'workStartTime',
    width: 150
  }, {
    title: '作业结束时间',
    dataIndex: 'workEndTime',
    key: 'workEndTime',
    width: 150
  }, {
    title: '作业类型',
    dataIndex: 'workTypeName',
    key: 'workTypeName',
    width: 100
    // render: (text: string) => {
    //     return <span style={{ color: getColor(text) }}>{text}</span>;
    // },
  }, {
    title: '作业路段',
    dataIndex: 'roadName',
    key: 'roadName',
    width: 150,
    ellipsis: true
  }];
  if (extraData !== null && extraData > 0) {
    // 有排班
    columns = [].concat(_toConsumableArray(columns), [{
      title: '核算作业里程/路段长度(km)',
      dataIndex: 'roadSpace',
      key: 'roadSpace',
      width: 180,
      render: function render(text, record) {
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            width: 80,
            display: 'inline-block',
            marginRight: '6px'
          }
        }, /*#__PURE__*/_react["default"].createElement(_progress["default"], {
          size: "small",
          strokeLinecap: "butt",
          percent: record.completePercent === null ? 100 : record.completePercent,
          strokeColor: theme === 'dark' ? {
            '0%': '#0090FF',
            '100%': '#1BF7FC'
          } : '#1890ff',
          trailColor: theme === 'dark' ? '#444B59' : '#D1D5D9',
          strokeWidth: 4,
          showInfo: false
        })), "".concat(record === null || record === void 0 ? void 0 : record.workMileage, "/").concat(text));
      }
    }, {
      title: '作业/计划趟数',
      dataIndex: 'workCount',
      key: 'workCount',
      width: 120,
      render: function render(text, record) {
        return /*#__PURE__*/_react["default"].createElement("span", null, "".concat(record === null || record === void 0 ? void 0 : record.actualWorkCount, "/").concat(record.completePercent === null ? '-' : text));
      }
    }, {
      title: '作业均速(km/h)',
      dataIndex: 'workSpeed',
      key: 'workSpeed',
      align: 'right',
      width: 140,
      render: function render(text) {
        return /*#__PURE__*/_react["default"].createElement("span", null, text === null || text === void 0 ? void 0 : text.toFixed(2));
      }
    }]);
  } else {
    columns = [].concat(_toConsumableArray(columns), [{
      title: '作业里程(km)',
      dataIndex: 'workMileage',
      key: 'workMileage',
      align: 'right',
      width: 120,
      render: function render(text) {
        return text === null || text === void 0 ? void 0 : text.toFixed(2);
      }
    }, {
      title: '路段长度(km)',
      dataIndex: 'roadSpace',
      key: 'roadSpace',
      align: 'right',
      width: 120
    }, {
      title: '作业均速(km/h)',
      dataIndex: 'workSpeed',
      key: 'workSpeed',
      align: 'right',
      width: 140,
      render: function render(text) {
        return /*#__PURE__*/_react["default"].createElement("span", null, text === null || text === void 0 ? void 0 : text.toFixed(2));
      }
    }]);
  }
  var pageChange = function pageChange(page) {
    setState({
      pagination: Object.assign(Object.assign({}, pagination), {
        current: page
      })
    });
  };
  var handleTableChange = function handleTableChange(sorter) {
    setState({
      order: "".concat(sorter.order === 'ascend' ? 'ASC' : 'DESC')
    });
  };
  var tableProps = {
    rowKey: 'index',
    pagination: Object.assign(Object.assign({}, pagination), {
      total: (recordJxhRes === null || recordJxhRes === void 0 ? void 0 : recordJxhRes.total) || 0,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    handleTableChange: handleTableChange,
    height: 240,
    dataSource: (recordJxhRes === null || recordJxhRes === void 0 ? void 0 : recordJxhRes.rows) || []
  };
  return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-head"
  }, /*#__PURE__*/_react["default"].createElement("div", null), /*#__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", {
    className: "car-work-content"
  }, extraData !== null && extraData > 0 ? (/*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-pb"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-pb-item"
  }, /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('zlc'),
    name: "\u6838\u7B97\u4F5C\u4E1A\u603B\u91CC\u7A0B",
    value: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workMileage) || 0,
    unit: "\u516C\u91CC"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('pjwcl'),
    name: "\u5E73\u5747\u5B8C\u6210\u7387",
    value: extraData,
    tooltip: "\u53EA\u7EDF\u8BA1\u6392\u73ED\u8DEF\u6BB5\u5B8C\u6210\u7387",
    unit: "%"
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-pb-item"
  }, /*#__PURE__*/_react["default"].createElement(_Wcl["default"], {
    names: names,
    values: (values === null || values === void 0 ? void 0 : values.length) > 1 ? values[1] : []
  })))) : (/*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-pb"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-pb-item"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-nopb"
  }, /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('zlc'),
    name: "\u6838\u7B97\u4F5C\u4E1A\u603B\u91CC\u7A0B",
    value: (workSummaryJxhRes === null || workSummaryJxhRes === void 0 ? void 0 : workSummaryJxhRes.workMileage) || 0,
    unit: "\u516C\u91CC"
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-summary-pb-item"
  }, /*#__PURE__*/_react["default"].createElement(_Zylc["default"], {
    names: names,
    values: (values === null || values === void 0 ? void 0 : values.length) > 0 ? values[0] : []
  }))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-work-table"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabsLine, {
    items: tabItems,
    activeKey: workTypeCodes,
    onChange: function onChange(key) {
      setState({
        workTypeCodes: key
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns
  }, tableProps))));
}
//# sourceMappingURL=WorkJxh.js.map
