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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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(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(arr) { if (Array.isArray(arr)) return arr; }
/**
 * 收集点-收运信息
 */
import { useSetState } from 'ahooks';
import { Space } from 'antd';
import dayjs from 'dayjs';
import { useEffect, useState } from 'react';
import { VmExtraTab, VmFactor, VmFilter, VmTable, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BaseService, SyService } from "../../api";
import "./index.less";
import Ljcsl from "./Ljcsl";
import jhsj from "../../imgs/jhsj.png";
import sjl from "../../imgs/sjl.png";
import sjsj from "../../imgs/sjsj.png";
import sjts from "../../imgs/sjts.png";
import sjzl from "../../imgs/sjzl.png";
import jhsjLight from "../../imgs/jhsj_light.png";
import sjlLight from "../../imgs/sjl_light.png";
import sjsjLight from "../../imgs/sjsj_light.png";
import sjtsLight from "../../imgs/sjts_light.png";
import sjzlLight from "../../imgs/sjzl_light.png";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var summaryData = {
  planCollectNums: 0,
  collectNums: 0,
  rate: 0,
  bucketNum: 0,
  showWeight: false,
  weight: 0
};
var SyInfo = function SyInfo(props) {
  var _paramConfigsList$SHO, _paramConfigsList$SHO2, _paramConfigsList$SHO3, _paramConfigsList$SHO4;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var id = props.id;
  var _useState = useState('chart'),
    _useState2 = _slicedToArray(_useState, 2),
    type = _useState2[0],
    setType = _useState2[1];
  var _useSetState = useSetState({
      filterKey: 'all',
      summary: summaryData,
      startDate: sDate ? sDate : dayjs().startOf('M').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : dayjs().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 = BaseService.useConfig(),
    paramConfigsList = _BaseService$useConfi.paramConfigsList;
  var _SyService$useBaseInf = SyService.useBaseInfo(id, startDate, endDate),
    baseInfo = _SyService$useBaseInf.baseInfo,
    collectWeight = _SyService$useBaseInf.collectWeight;
  var _SyService$useRecordI = SyService.useRecordInfo(id, filterKey === 'all' ? '' : filterKey, startDate, endDate, pagination.current - 1, sort),
    records = _SyService$useRecordI.records;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  useEffect(function () {
    if (baseInfo.length > 0) {
      setState({
        filterKey: baseInfo[0].productTypeId
      });
    }
  }, [JSON.stringify(baseInfo)]);
  useEffect(function () {
    if (baseInfo.length > 0) {
      var data = baseInfo.find(function (ele) {
        return filterKey === 'all' || ele.productTypeId === filterKey;
      });
      setState({
        summary: data
      });
    }
  }, [JSON.stringify(baseInfo), filterKey]);
  var columns = [{
    title: '收集日期',
    dataIndex: 'collectDay',
    key: 'collectDay',
    sorter: true,
    width: 80
  }, {
    title: '计划收集频次',
    dataIndex: 'planCollectNums',
    key: 'planCollectNums',
    width: 110,
    align: 'right'
  }, {
    title: '实际频次',
    dataIndex: 'collectNums',
    key: 'collectNums',
    width: 80,
    align: 'right'
  }, {
    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 (((_paramConfigsList$SHO = paramConfigsList['SHOW_COLLECTING_BUCKETS']) === null || _paramConfigsList$SHO === void 0 ? void 0 : _paramConfigsList$SHO.value) === 'true') {
    newColumns.splice(bucketIdx, 0, {
      title: '收集桶数(桶)',
      dataIndex: 'bucketNum',
      key: 'bucketNum',
      width: 110,
      align: 'right'
    });
    weightIdx = bucketIdx + 1;
  }
  if (((_paramConfigsList$SHO2 = paramConfigsList['SHOW_WEIGHTING']) === null || _paramConfigsList$SHO2 === void 0 ? void 0 : _paramConfigsList$SHO2.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,
      sjsj: sjsj,
      sjl: sjl,
      sjts: sjts,
      sjzl: sjzl
    };
    var obj2 = {
      jhsj: jhsjLight,
      sjsj: sjsjLight,
      sjl: sjlLight,
      sjts: sjtsLight,
      sjzl: sjzlLight
    };
    if (isDark) {
      return obj[code];
    }
    return obj2[code];
  };
  var pageChange = function pageChange(page) {
    setState({
      pagination: _objectSpread(_objectSpread({}, 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: _objectSpread(_objectSpread({}, pagination), {}, {
      total: records.total,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    handleTableChange: handleTableChange,
    height: 190,
    dataSource: records.rows || []
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "cp-syinfo",
    children: [/*#__PURE__*/_jsx(VmWrapper, {
      needChange: true,
      showContent: false,
      headerStyle: {
        borderBottom: 'unset'
      },
      title: /*#__PURE__*/_jsxs(Space, {
        size: 26,
        children: [/*#__PURE__*/_jsx(VmExtraTab, {
          value: filterKey,
          itemStyle: {
            width: 'fit-content'
          },
          data: (baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.map(function (ele) {
            return {
              key: (ele === null || ele === void 0 ? void 0 : ele.productTypeId) || '',
              title: ele.productTypeName
            };
          })) || [],
          onChange: function onChange(key) {
            setState({
              filterKey: key
            });
          }
        }), /*#__PURE__*/_jsxs("div", {
          children: ["\u7EDF\u8BA1\u8303\u56F4\xA0\xA0", /*#__PURE__*/_jsx(VmFilter.VMRangePicker, {
            value: [dayjs(startDate), dayjs(endDate)],
            onChange: function onChange(dates) {
              return dates && handleDateChange(dayjs(dates[0]).format('YYYY-MM-DD'), dayjs(dates[1]).format('YYYY-MM-DD'));
            }
          })]
        })]
      }),
      onChange: setType
    }), /*#__PURE__*/_jsx("div", {
      className: "cp-syinfo-base",
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: "\u6C47\u603B\u5206\u6790",
        children: /*#__PURE__*/_jsx("div", {
          className: "cp-syinfo-base-summary",
          children: [{
            name: '计划收集',
            unit: '次',
            value: planCollectNums,
            img: getSrc('jhsj'),
            fontType: 'blue'
          }, {
            name: '实际收集',
            unit: '次',
            value: collectNums,
            img: getSrc('sjsj'),
            fontType: 'green'
          }, {
            name: '收集率',
            unit: '%',
            value: rate,
            img: getSrc('sjl'),
            fontType: 'cyan'
          }, ((_paramConfigsList$SHO3 = paramConfigsList['SHOW_COLLECTING_BUCKETS']) === null || _paramConfigsList$SHO3 === void 0 ? void 0 : _paramConfigsList$SHO3.value) === 'true' && {
            name: '收集桶数',
            unit: '个',
            value: bucketNum,
            img: getSrc('sjts'),
            fontType: 'yellow'
          }, showWeight && ((_paramConfigsList$SHO4 = paramConfigsList['SHOW_WEIGHTING']) === null || _paramConfigsList$SHO4 === void 0 ? void 0 : _paramConfigsList$SHO4.value) === 'true' && {
            name: '收集重量',
            unit: 'kg',
            value: weight,
            img: getSrc('sjzl'),
            fontType: 'purple'
          }].filter(Boolean).map(function (ele, index) {
            return /*#__PURE__*/_jsx(VmFactor, _objectSpread(_objectSpread({}, ele), {}, {
              unitStyle: {
                fontSize: 14
              }
            }), index);
          })
        })
      })
    }), type === 'chart' && /*#__PURE__*/_jsx(VmWrapper, {
      title: "\u5783\u573E\u4EA7\u751F\u91CF",
      children: /*#__PURE__*/_jsx(Ljcsl, {
        data: collectWeight
      })
    }), type === 'list' && /*#__PURE__*/_jsx("div", {
      className: "cp-syinfo-table",
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: "\u6536\u8FD0\u8BB0\u5F55",
        children: /*#__PURE__*/_jsx(VmTable, _objectSpread({
          columns: newColumns
        }, tableProps))
      })
    })]
  });
};
export default SyInfo;