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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 { useAntdTable, useSetState } from 'ahooks';
import { Button } from 'antd';
import React, { useEffect } from 'react';
import { JzljGcxmContext } from "../..";
import { VmFactorList, VmFilter, VmTable, VmTag, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { collectionApis, useLdFields, useUnit } from "../../api";
import "./index.less";
import dayjs from 'dayjs';
import cc_dark from "../../imgs/overview_ctyl_pjrcc_dark.png";
import cc_light from "../../imgs/overview_ctyl_pjrcc_light.png";
import yl_dark from "../../imgs/overview_ctyl_pjryl_dark.png";
import yl_light from "../../imgs/overview_ctyl_pjryl_light.png";
import Chart from "./Chart";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
export default function Collection() {
  var _React$useContext = React.useContext(JzljGcxmContext),
    id = _React$useContext.id,
    theme = _React$useContext.theme,
    _React$useContext$inf = _React$useContext.info,
    info = _React$useContext$inf === void 0 ? {} : _React$useContext$inf,
    setIframeModalInfo = _React$useContext.setIframeModalInfo;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useSetState = useSetState({
      activeKey: 'chart',
      stepThreeOperateTimeLeft: dayjs().subtract(6, 'day'),
      stepThreeOperateTimeRight: dayjs(),
      disposalCertificateInfoCode: undefined,
      code: undefined,
      endingPointName: undefined,
      totalData: {},
      chartData: {}
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var activeKey = state.activeKey,
    stepThreeOperateTimeLeft = state.stepThreeOperateTimeLeft,
    stepThreeOperateTimeRight = state.stepThreeOperateTimeRight,
    disposalCertificateInfoCode = state.disposalCertificateInfoCode,
    code = state.code,
    endingPointName = state.endingPointName,
    totalData = state.totalData,
    chartData = state.chartData;
  var _useUnit = useUnit(),
    unitStr = _useUnit.unitStr;
  var _useLdFields = useLdFields(),
    visibleList = _useLdFields.visibleList;
  var columns = [].concat(_toConsumableArray(visibleList !== null && visibleList !== void 0 && visibleList.length ? visibleList.filter(function (item) {
    return item.dataShowKey !== 'startingPointName' && item.dataShowKey !== 'startingPointDivisionName';
  }).map(function (item) {
    return [item.displayName, item.dataShowKey, item.dataShowKey === 'jointOrderStatusName' ? {
      width: item.columnWidth || 120,
      render: function render(text, record) {
        var colorMap = {
          yqy: 'yellow',
          yyd: 'blue',
          yjs: 'green',
          yqr: 'green'
        };
        var color = colorMap[record.jointOrderStatusCode] || 'yellow';
        return /*#__PURE__*/_jsx(VmTag, {
          title: text,
          type: color
        });
      }
    } : {
      width: 120,
      ellipsis: true,
      align: item.dataShowKey === 'receivedWeight' ? 'right' : 'left'
    }];
  }) : [['联单编号', 'code', {
    width: 120,
    fixed: 'left',
    ellipsis: true
  }], ['核准编号', 'disposalCertificateInfoCode', {
    width: 120,
    ellipsis: true
  }], ['联单状态', 'jointOrderStatusName', {
    width: 120,
    render: function render(text, record) {
      var colorMap = {
        yqy: 'yellow',
        yyd: 'blue',
        yjs: 'green',
        yqr: 'green'
      };
      var color = colorMap[record.jointOrderStatusCode] || 'yellow';
      return /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: color
      });
    }
  }], ['起运时间', 'stepOneOperateTime', {
    width: 180
  }], ['运输单位', 'transportUnitName', {
    width: 120,
    ellipsis: true
  }], ['车牌号', 'carCode', {
    width: 120
  }], ['运输终点', 'endingPointName', {
    width: 120,
    ellipsis: true
  }], ['终点行政区划', 'endingPointDivisionName', {
    width: 120,
    ellipsis: true
  }], ['接收时间', 'stepThreeOperateTime', {
    width: 180
  }], ['建筑垃圾类别', 'garbageTypeName', {
    width: 120
  }], ["\u8FD0\u91CF(".concat(unitStr, ")"), 'receivedWeight', {
    width: 120,
    align: 'right'
  }]]), [['操作', 'action', {
    width: 60,
    fixed: 'right',
    render: function render(text, record) {
      return /*#__PURE__*/_jsx("a", {
        onClick: function onClick() {
          setIframeModalInfo({
            visible: true,
            title: '联单信息',
            src: "/jzlj/#/constructionJointOrder?id=".concat(record.id)
          });
        },
        children: "\u67E5\u770B"
      });
    }
  }]]).map(function (item) {
    return _objectSpread({
      title: item[0],
      dataIndex: item[1],
      key: item[1]
    }, item[2]);
  });
  var getTableData = function getTableData(_ref) {
    var current = _ref.current,
      pageSize = _ref.pageSize;
    var formData = {
      startingPointId: id,
      disposalCertificateInfoCode: disposalCertificateInfoCode,
      code: code,
      endingPointName: endingPointName,
      stepThreeOperateTimeLeft: stepThreeOperateTimeLeft.format('YYYY-MM-DD 00:00:00'),
      stepThreeOperateTimeRight: stepThreeOperateTimeRight.format('YYYY-MM-DD 23:59:59')
    };
    collectionApis.jcssOrderAnalyse({
      startingPointId: id,
      startDate: stepThreeOperateTimeLeft.format('YYYY-MM-DD'),
      endDate: stepThreeOperateTimeRight.format('YYYY-MM-DD')
    }).then(function (res) {
      setState({
        chartData: (res === null || res === void 0 ? void 0 : res.data) || {}
      });
    });
    collectionApis.total(_objectSpread({}, formData)).then(function (res) {
      setState({
        totalData: (res === null || res === void 0 ? void 0 : res.data) || {}
      });
    });
    return collectionApis.page(_objectSpread(_objectSpread({}, formData), {}, {
      page: current - 1,
      size: pageSize
    })).then(function (res) {
      var _res$data, _res$data2;
      return {
        total: (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.total) || 0,
        list: (res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.rows) || []
      };
    });
  };
  var _useAntdTable = useAntdTable(getTableData, {
      defaultPageSize: 10
    }),
    tableProps = _useAntdTable.tableProps,
    search = _useAntdTable.search;
  var submit = search.submit,
    reset = search.reset;
  var myReset = function myReset() {
    setState({
      disposalCertificateInfoCode: undefined,
      code: undefined,
      endingPointName: undefined
    });
    reset();
  };
  var myTableProps = _objectSpread(_objectSpread({}, tableProps), {}, {
    rowKey: 'id',
    columns: columns,
    indexFixed: true
  });
  var _totalData$totalCount = totalData.totalCount,
    totalCount = _totalData$totalCount === void 0 ? 0 : _totalData$totalCount,
    _totalData$totalWeigh = totalData.totalWeight,
    totalWeight = _totalData$totalWeigh === void 0 ? 0 : _totalData$totalWeigh;
  var totalList = [{
    name: '总运量',
    unit: unitStr,
    value: totalWeight,
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
    },
    img: isDark ? yl_dark : yl_light,
    fontType: 'blue'
  }, {
    name: '总车次',
    unit: '次',
    value: totalCount,
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
    },
    img: isDark ? cc_dark : cc_light,
    fontType: 'green'
  }];
  var searchList = [{
    title: '处置证编号',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMInput, {
      style: {
        width: 120
      },
      value: disposalCertificateInfoCode,
      onValChange: function onValChange(val) {
        setState({
          disposalCertificateInfoCode: val
        });
      }
    })
  }, {
    title: '联单编号',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMInput, {
      style: {
        width: 120
      },
      value: code,
      onValChange: function onValChange(val) {
        setState({
          code: val
        });
      }
    })
  }, {
    title: '运输终点',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMInput, {
      style: {
        width: 120
      },
      value: endingPointName,
      onValChange: function onValChange(val) {
        setState({
          endingPointName: val
        });
      }
    })
  }];
  useEffect(function () {
    submit();
  }, [stepThreeOperateTimeLeft, stepThreeOperateTimeRight]);
  return /*#__PURE__*/_jsx("div", {
    className: "collection",
    children: /*#__PURE__*/_jsx(VmWrapper, {
      title: "\u8054\u5355\u8FD0\u884C\u60C5\u51B5",
      needChange: true,
      activeKey: activeKey,
      onChange: function onChange(key) {
        return setState({
          activeKey: key
        });
      },
      filterType: "rangePicker",
      dateValue: [stepThreeOperateTimeLeft, stepThreeOperateTimeRight],
      filterChange: function filterChange(e) {
        setState({
          stepThreeOperateTimeLeft: e === null || e === void 0 ? void 0 : e[0],
          stepThreeOperateTimeRight: e === null || e === void 0 ? void 0 : e[1]
        });
      },
      contentStyle: {
        padding: 0
      },
      children: /*#__PURE__*/_jsx(_Fragment, {
        children: activeKey === 'chart' ? /*#__PURE__*/_jsx(Chart, {
          data: chartData,
          unitStr: unitStr
        }) : /*#__PURE__*/_jsxs("div", {
          className: "collection-myTable",
          children: [/*#__PURE__*/_jsxs("div", {
            className: "collection-myTable-search ".concat(isDark ? 'dark' : ''),
            children: [/*#__PURE__*/_jsx("div", {
              className: "collection-myTable-search-left",
              children: searchList.map(function (item) {
                return /*#__PURE__*/_jsxs("span", {
                  style: {
                    display: 'flex',
                    alignItems: 'center'
                  },
                  children: [/*#__PURE__*/_jsx("span", {
                    style: {
                      marginRight: 8
                    },
                    children: item.title
                  }), /*#__PURE__*/_jsx("span", {
                    children: item.dom
                  })]
                }, item.title);
              })
            }), /*#__PURE__*/_jsxs("div", {
              className: "collection-myTable-search-right",
              children: [/*#__PURE__*/_jsx(Button, {
                type: "primary",
                onClick: submit,
                children: "\u67E5\u8BE2"
              }), /*#__PURE__*/_jsx(Button, {
                onClick: myReset,
                children: "\u91CD\u7F6E"
              })]
            })]
          }), /*#__PURE__*/_jsx("div", {
            className: "collection-myTable-total",
            children: /*#__PURE__*/_jsx(VmFactorList, {
              list: totalList,
              style: {
                background: 'unset',
                height: '100%'
              }
            })
          }), /*#__PURE__*/_jsx("div", {
            className: "collection-myTable-main",
            children: /*#__PURE__*/_jsx(VmWrapper, {
              showTitle: false,
              style: {
                border: 'unset'
              },
              contentStyle: {
                padding: 0
              },
              children: /*#__PURE__*/_jsx(VmTable, _objectSpread({}, myTableProps))
            })
          })]
        })
      })
    })
  });
}