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

var _ahooks = require("ahooks");

var _antd = require("antd");

var _moment = _interopRequireDefault(require("moment"));

var _vmFilter = require("../vm-filter");

var _vmStatCollection = _interopRequireDefault(require("../vm-stat-collection"));

var _vmTable = _interopRequireWildcard(require("../vm-table"));

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

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

var _projectDark = _interopRequireDefault(require("../../image/project-dark.png"));

var _project = _interopRequireDefault(require("../../image/project.png"));

var _realDark = _interopRequireDefault(require("../../image/real-dark.png"));

var _real = _interopRequireDefault(require("../../image/real.png"));

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

require("./style");

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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 ThrowContent = function ThrowContent(props) {
  var id = props.id;

  var _useSetState = (0, _ahooks.useSetState)({
    start: (0, _moment["default"])().subtract(1, 'y'),
    end: (0, _moment["default"])(),
    ids: []
  }),
      _useSetState2 = _slicedToArray(_useSetState, 2),
      state = _useSetState2[0],
      setState = _useSetState2[1];

  var _useRequest = (0, _ahooks.useRequest)(function (_ref) {
    var current = _ref.current,
        pageSize = _ref.pageSize;
    return _api.CollectData.collectDataList({
      page: current - 1,
      size: pageSize,
      id: id,
      start: state.start.format('YYYY-MM-DD 00:00:00'),
      end: state.end.format('YYYY-MM-DD 23:59:59')
    });
  }, {
    defaultPageSize: 10,
    paginated: true
  }),
      tableProps = _useRequest.tableProps;

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

  var statInfo = _api.CollectData.getSum(id, state.start, state.end);

  var statData = [{
    icon: isDark ? _projectDark["default"] : _project["default"],
    label: '收运次数',
    value: statInfo === null || statInfo === void 0 ? void 0 : statInfo.totalThrowCount,
    unit: '次'
  }, {
    icon: isDark ? _realDark["default"] : _real["default"],
    label: '收运重量',
    value: statInfo === null || statInfo === void 0 ? void 0 : statInfo.participateInHousehold,
    unit: '次'
  }];

  var handleDateChange = function handleDateChange(start, end) {
    setState({
      start: start,
      end: end
    });
  };

  var handleExport = function handleExport(type) {
    var _tableProps$dataSourc;

    var downloadAll = false;
    var ids = '';

    switch (type) {
      case 'all':
        downloadAll = true;
        break;

      case 'select-rows':
        ids = state.ids.join(',');
        break;

      case 'current-page':
        ids = tableProps === null || tableProps === void 0 ? void 0 : (_tableProps$dataSourc = tableProps.dataSource) === null || _tableProps$dataSourc === void 0 ? void 0 : _tableProps$dataSourc.map(function (i) {
          return i.id;
        }).join(',');
        break;

      default:
        break;
    }

    _api.CollectData.exportData({
      subjectId: id,
      startTime: state.start.format('YYYY-MM-DD hh:mm:ss'),
      endTime: state.end.format('YYYY-MM-DD hh:mm:ss'),
      downloadAll: downloadAll,
      ids: ids,
      columnJson: (0, _vmTable.renderColumnParam)(columns)
    });
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "community-throw-content"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "top-bar"
  }, /*#__PURE__*/_react["default"].createElement(_vmStatCollection["default"], {
    items: statData
  }), /*#__PURE__*/_react["default"].createElement(_antd.Space, {
    className: "right"
  }, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
    defaultValue: [state.start, state.end],
    onChange: function onChange(dates) {
      return dates && handleDateChange(dates[0], dates[1]);
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmTable.ExportBtn, {
    onClick: handleExport
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "table-container"
  }, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], _extends({
    columns: columns,
    rowSelection: {
      onChange: function onChange(rowKeys) {
        return setState({
          ids: rowKeys
        });
      }
    }
  }, tableProps))));
};

ThrowContent.propTypes = {
  id: _propTypes["default"].string
};
var columns = [{
  title: '收运单位',
  dataIndex: 'collectUnitName',
  key: 'collectUnitName'
}, {
  title: '收运车辆',
  dataIndex: 'carCode',
  key: 'carCode'
}, // {
//     title: '收运人员',
//     dataIndex: 'houseNumber',
//     key: 'houseNumber',
// },
{
  title: '垃圾类型',
  dataIndex: 'productTypeName',
  key: 'productTypeName'
}, {
  title: '收运重量（kg）',
  dataIndex: 'weight',
  key: 'weight'
}, {
  title: '收运时间',
  dataIndex: 'actualCollectTime',
  key: 'actualCollectTime'
}];
var _default = ThrowContent;
exports["default"] = _default;
//# sourceMappingURL=collect.js.map
