"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"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _antd = require("antd");
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 _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
require("./index.less");
var _jhsj = _interopRequireDefault(require("../../imgs/jhsj.png"));
var _sjsj = _interopRequireDefault(require("../../imgs/sjsj.png"));
var _sjl = _interopRequireDefault(require("../../imgs/sjl.png"));
var _sjts = _interopRequireDefault(require("../../imgs/sjts.png"));
var _sjzl = _interopRequireDefault(require("../../imgs/sjzl.png"));
var _jhsj_light = _interopRequireDefault(require("../../imgs/jhsj_light.png"));
var _sjsj_light = _interopRequireDefault(require("../../imgs/sjsj_light.png"));
var _sjl_light = _interopRequireDefault(require("../../imgs/sjl_light.png"));
var _sjts_light = _interopRequireDefault(require("../../imgs/sjts_light.png"));
var _sjzl_light = _interopRequireDefault(require("../../imgs/sjzl_light.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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; } /**
 * 收集点-收运信息
 */
var summaryData = {
  planCollectNums: 0,
  collectNums: 0,
  rate: 0,
  bucketNum: 0,
  showWeight: false,
  weight: 0
};
var SyInfo = function SyInfo(props) {
  var _a, _b, _c, _d, _e;
  var _useSettings = (0, _useSettings2["default"])(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var id = props.id;
  var _useSetState = (0, _ahooks.useSetState)({
      filterKey: '',
      summary: summaryData,
      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
      },
      sort: ''
    }),
    _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,
    sort = state.sort;
  var planCollectNums = summary.planCollectNums,
    collectNums = summary.collectNums,
    rate = summary.rate,
    bucketNum = summary.bucketNum,
    showWeight = summary.showWeight,
    weight = summary.weight;
  var _BaseService$useConfi = _api.BaseService.useConfig(),
    paramConfigsList = _BaseService$useConfi.paramConfigsList;
  var _SyService$useBaseInf = _api.SyService.useBaseInfo(id, startDate, endDate),
    baseInfo = _SyService$useBaseInf.baseInfo,
    collectWeight = _SyService$useBaseInf.collectWeight;
  var _SyService$useRecordI = _api.SyService.useRecordInfo(id, filterKey, startDate, endDate, pagination.current - 1, sort),
    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',
    sorter: true,
    width: 80
  }, {
    title: '计划收集频次',
    dataIndex: 'planCollectNums',
    key: 'planCollectNums',
    width: 110
  }, {
    title: '实际频次',
    dataIndex: 'collectNums',
    key: 'collectNums',
    width: 80
  }, {
    title: '收集状态',
    dataIndex: 'collectStatusStr',
    key: 'collectStatusStr',
    width: 80
  }];
  var bucketIdx = 3,
    weightIdx = 3;
  var newColumns = columns;
  if (showWeight) {
    newColumns.splice(1, 0, {
      title: '垃圾类型',
      dataIndex: 'productTypeName',
      key: 'productTypeName',
      width: 160,
      ellipsis: true
    });
    bucketIdx = 4;
    weightIdx = 4;
  }
  if (((_a = paramConfigsList['SHOW_COLLECTING_BUCKETS']) === null || _a === void 0 ? void 0 : _a.value) === 'true') {
    newColumns.splice(bucketIdx, 0, {
      title: '收集桶数(桶)',
      dataIndex: 'bucketNum',
      key: 'bucketNum',
      width: 110,
      align: 'right'
    });
    weightIdx = bucketIdx + 1;
  }
  if (((_b = paramConfigsList['SHOW_WEIGHTING']) === null || _b === void 0 ? void 0 : _b.value) === 'true') {
    newColumns.splice(weightIdx, 0, {
      title: '收集重量(kg)',
      dataIndex: 'weight',
      key: 'weight',
      width: 110,
      align: 'right'
    });
  }
  var getSrc = function getSrc(code) {
    var obj = {
      jhsj: _jhsj["default"],
      sjsj: _sjsj["default"],
      sjl: _sjl["default"],
      sjts: _sjts["default"],
      sjzl: _sjzl["default"]
    };
    var obj2 = {
      jhsj: _jhsj_light["default"],
      sjsj: _sjsj_light["default"],
      sjl: _sjl_light["default"],
      sjts: _sjts_light["default"],
      sjzl: _sjzl_light["default"]
    };
    if (isDark) {
      return obj[code];
    }
    return obj2[code];
  };
  var pageChange = function pageChange(page) {
    setState({
      pagination: Object.assign(Object.assign({}, pagination), {
        current: page
      })
    });
  };
  var handleTableChange = function handleTableChange(sorter) {
    (sorter === null || sorter === void 0 ? void 0 : sorter.columnKey) && setState({
      sort: "".concat(sorter.columnKey, ",").concat(sorter.order === 'ascend' ? 'ASC' : 'DESC')
    });
  };
  var tableProps = {
    rowKey: 'id',
    pagination: Object.assign(Object.assign({}, pagination), {
      total: records.total,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    handleTableChange: handleTableChange,
    height: 200,
    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(_antd.Row, {
    gutter: 10
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    flex: 'auto'
  }, /*#__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(_antd.Col, {
    flex: '230px'
  }, /*#__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("div", {
    className: "cp-syinfo-base"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: 10
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 12,
    xl: 12,
    lg: 24,
    md: 24
  }, /*#__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: getSrc('jhsj'),
    name: "\u8BA1\u5212\u6536\u96C6",
    value: planCollectNums,
    unit: "\u6B21",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjsj'),
    name: "\u5B9E\u9645\u6536\u96C6",
    value: collectNums,
    unit: "\u6B21",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjl'),
    name: "\u6536\u96C6\u7387",
    value: rate,
    unit: "%",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), ((_c = paramConfigsList['SHOW_COLLECTING_BUCKETS']) === null || _c === void 0 ? void 0 : _c.value) === 'true' && /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjts'),
    name: "\u6536\u96C6\u6876\u6570",
    value: bucketNum,
    unit: "\u4E2A",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  }), ((_d = paramConfigsList['SHOW_WEIGHTING']) === null || _d === void 0 ? void 0 : _d.value) === 'true' && /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjzl'),
    name: "\u6536\u96C6\u91CD\u91CF",
    value: weight,
    unit: "kg",
    color: "active",
    style: {
      marginRight: '0',
      width: '150px',
      marginBottom: '24px'
    }
  })))), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    xxl: 12,
    xl: 12,
    lg: 24,
    md: 24
  }, /*#__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-noweight"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, null, /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('jhsj'),
    name: "\u8BA1\u5212\u6536\u96C6",
    value: planCollectNums,
    unit: "\u6B21",
    color: "active"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjsj'),
    name: "\u5B9E\u9645\u6536\u96C6",
    value: collectNums,
    unit: "\u6B21",
    color: "active"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjl'),
    name: "\u6536\u96C6\u7387",
    value: rate,
    unit: "%",
    color: "active"
  }), ((_e = paramConfigsList['SHOW_COLLECTING_BUCKETS']) === null || _e === void 0 ? void 0 : _e.value) === 'true' && /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: getSrc('sjts'),
    name: "\u6536\u96C6\u6876\u6570",
    value: bucketNum,
    unit: "\u4E2A",
    color: "active"
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "cp-syinfo-table"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6536\u8FD0\u8BB0\u5F55"
  }), /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: newColumns
  }, tableProps))));
};
var _default = exports["default"] = SyInfo;
//# sourceMappingURL=index.js.map
