"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 _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmSubTabs = require("../../../vm-sub-tabs");
var _vmFilter = require("../../../vm-filter");
var _vmImageText = _interopRequireDefault(require("../../../vm-image-text"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _Ljcsl = _interopRequireDefault(require("./Ljcsl"));
var _api = require("../../api");
require("./index.less");
var _all_rate = _interopRequireDefault(require("../../imgs/all_rate.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 = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var summaryData = {
  planNum: 0,
  collectNum: 0,
  rate: 0,
  bucketNum: 0,
  showWeight: false,
  weight: 0
};
var SyInfo = function SyInfo(props) {
  var id = props.id;
  var _useSetState = (0, _ahooks.useSetState)({
      filterKey: '',
      summary: summaryData,
      startDate: (0, _moment["default"])().format('YYYY-MM-DD'),
      endDate: (0, _moment["default"])().format('YYYY-MM-DD'),
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      }
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var summary = state.summary,
    filterKey = state.filterKey,
    startDate = state.startDate,
    endDate = state.endDate,
    pagination = state.pagination;
  var planNum = summary.planNum,
    collectNum = summary.collectNum,
    rate = summary.rate,
    bucketNum = summary.bucketNum,
    showWeight = summary.showWeight,
    weight = summary.weight;
  var _SyService$useBaseInf = _api.SyService.useBaseInfo(id, startDate, endDate),
    baseInfo = _SyService$useBaseInf.baseInfo,
    collectWeight = _SyService$useBaseInf.collectWeight;
  var _SyService$useRecordI = _api.SyService.useRecordInfo(id, startDate, endDate, pagination.current - 1),
    records = _SyService$useRecordI.records;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  (0, _react.useEffect)(function () {
    if (baseInfo.length > 0) {
      var data = baseInfo.find(function (ele) {
        return ele.productTypeId === (filterKey || null);
      });
      setState({
        summary: data
      });
    }
  }, [baseInfo, filterKey]);
  var columns = [{
    title: '收集日期',
    dataIndex: 'collectDay',
    key: 'collectDay'
  }, {
    title: '计划收集频次',
    dataIndex: 'planCollectNums',
    key: 'planCollectNums'
  }, {
    title: '实际频次',
    dataIndex: 'collectNums',
    key: 'collectNums'
  }, {
    title: '收集状态',
    dataIndex: 'collectStatusStr',
    key: 'collectStatusStr'
  }, {
    title: '收集桶数(个)',
    dataIndex: 'bucketNum',
    key: 'bucketNum'
  }, {
    title: '收集重量(kg)',
    dataIndex: 'weight',
    key: 'weight'
  }];
  var newColumns = columns;
  if (showWeight) {
    newColumns.splice(1, 0, {
      title: '垃圾类型',
      dataIndex: 'productTypeName',
      key: 'productTypeName'
    });
  }
  var pageChange = function pageChange(page) {
    setState({
      pagination: Object.assign(Object.assign({}, pagination), {
        current: page
      })
    });
  };
  var tableProps = {
    pagination: Object.assign(Object.assign({}, pagination), {
      total: records.total,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    height: 280,
    dataSource: records.rows
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-head"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabsLine, {
    items: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.map(function (ele) {
      return {
        key: (ele === null || ele === void 0 ? void 0 : ele.productTypeId) || '',
        label: ele.productTypeName
      };
    }),
    activeKey: filterKey,
    onChange: function onChange(key) {
      setState({
        filterKey: key
      });
    }
  }), /*#__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'));
    }
  })), showWeight ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-base"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-base-weight"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6C47\u603B\u4FE1\u606F"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-base-weight-item"
  }, /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u8BA1\u5212\u6536\u96C6",
    value: planNum,
    unit: "\u6B21",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u5B9E\u9645\u6536\u96C6",
    value: collectNum,
    unit: "\u6B21",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u6536\u96C6\u7387",
    value: rate,
    unit: "%",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u6536\u96C6\u6876\u6570",
    value: bucketNum,
    unit: "\u4E2A",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u6536\u96C6\u91CD\u91CF",
    value: weight,
    unit: "kg",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-base-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u5783\u573E\u4EA7\u751F\u91CF"
  }), /*#__PURE__*/_react["default"].createElement(_Ljcsl["default"], {
    data: collectWeight
  })))) : /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-base"
  }, /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u8BA1\u5212\u6536\u96C6",
    value: planNum,
    unit: "\u6B21",
    color: "active"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u5B9E\u9645\u6536\u96C6",
    value: collectNum,
    unit: "\u6B21",
    color: "active"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u6536\u96C6\u7387",
    value: rate,
    unit: "%",
    color: "active"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: _all_rate["default"],
    name: "\u6536\u96C6\u6876\u6570",
    value: bucketNum,
    unit: "\u4E2A",
    color: "active"
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-table"
  }, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: newColumns
  }, tableProps))));
};
var _default = SyInfo;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
