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 from 'react';
import { JzljGcxmContext } from "../..";
import { VmFactorList, VmFilter, VmTable, VmTag, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { disposeApis, fetchJzljEnum, getByParamTypeCode, overviewApis, useCzzFields, useUnit } from "../../api";
import FlowMap from "./FlowMap";
import "./index.less";
import dispose_czz_dark from "../../imgs/dispose_czz_dark.png";
import dispose_czz_light from "../../imgs/dispose_czz_light.png";
import dispose_syl_dark from "../../imgs/dispose_syl_dark.png";
import dispose_syl_light from "../../imgs/dispose_syl_light.png";
import dispose_zsbl_dark from "../../imgs/dispose_zsbl_dark.png";
import dispose_zsbl_light from "../../imgs/dispose_zsbl_light.png";
import dispose_zyyl_dark from "../../imgs/dispose_zyyl_dark.png";
import dispose_zyyl_light from "../../imgs/dispose_zyyl_light.png";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
export default function Dispose() {
  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',
      transportUnitName: undefined,
      endingPointName: undefined,
      effectiveStatusCode: undefined,
      garbageTypeCode: undefined,
      flowData: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var activeKey = state.activeKey,
    transportUnitName = state.transportUnitName,
    endingPointName = state.endingPointName,
    effectiveStatusCode = state.effectiveStatusCode,
    garbageTypeCode = state.garbageTypeCode,
    flowData = state.flowData;
  var _useUnit = useUnit(),
    unitStr = _useUnit.unitStr;
  var _useCzzFields = useCzzFields(),
    visibleList = _useCzzFields.visibleList;
  var effectiveStatusList = fetchJzljEnum('EffectiveStatusEnum');
  var garbageTypeList = getByParamTypeCode('param_jzlj_disposal_garbage_type');
  var columns = [].concat(_toConsumableArray(visibleList !== null && visibleList !== void 0 && visibleList.length ? visibleList.filter(function (item) {
    return item.dataShowKey !== 'startingPointName';
  }).map(function (item) {
    return [item.displayName, item.dataShowKey, item.dataShowKey === 'effectiveStatusName' ? {
      width: item.columnWidth || 120,
      render: function render(text, record) {
        var colorMap = {
          wsx: 'yellow',
          sxz: 'green',
          ysx: 'red',
          yzz: 'gray'
        };
        var color = colorMap[record.effectiveStatusCode] || 'yellow';
        return /*#__PURE__*/_jsx(VmTag, {
          title: text,
          type: color
        });
      }
    } : {
      width: 100,
      ellipsis: true,
      align: item.dataShowKey === 'transportWeight' ? 'right' : 'left'
    }];
  }) : [['运输单位', 'transportUnitName', {
    width: 160,
    ellipsis: true
  }], ['运输终点', 'endingPointName', {
    width: 160,
    ellipsis: true
  }], ['运输垃圾类型', 'garbageTypeName', {
    width: 100
  }], ["\u8FD0\u8F93\u91CF(".concat(unitStr, ")"), 'transportWeight', {
    width: 80,
    align: 'right'
  }], ['申报有效期', 'effectiveDate', {
    width: 150
  }], ['运输车辆(辆)', 'effectiveCarCount', {
    width: 100,
    align: 'right'
  }], ['生效状态', 'effectiveStatusName', {
    width: 100,
    render: function render(text, record) {
      var colorMap = {
        wsx: 'yellow',
        sxz: 'green',
        ysx: 'red',
        yzz: 'gray'
      };
      var color = colorMap[record.effectiveStatusCode] || 'yellow';
      return /*#__PURE__*/_jsx(VmTag, {
        title: text,
        type: color
      });
    }
  }]]), [['操作', 'action', {
    width: 60,
    render: function render(_, record) {
      return /*#__PURE__*/_jsx("a", {
        onClick: function onClick() {
          setIframeModalInfo({
            visible: true,
            title: '处置证信息',
            src: "/jzlj/#/disposalApprovalFill?id=".concat(record.id, "&effectiveStatusCode=").concat(record.effectiveStatusCode)
          });
        },
        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 = {
      transportUnitName: transportUnitName,
      endingPointName: endingPointName,
      effectiveStatusCode: effectiveStatusCode,
      garbageTypeCode: garbageTypeCode
    };
    disposeApis.list(_objectSpread(_objectSpread({}, formData), {}, {
      startingPointId: id
    })).then(function (res) {
      setState({
        flowData: (res === null || res === void 0 ? void 0 : res.data) || []
      });
    });
    return disposeApis.page(_objectSpread(_objectSpread({}, formData), {}, {
      startingPointId: id,
      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({
      transportUnitName: undefined,
      endingPointName: undefined,
      effectiveStatusCode: undefined,
      garbageTypeCode: undefined
    });
    reset();
  };
  var myTableProps = _objectSpread(_objectSpread({}, tableProps), {}, {
    rowKey: 'id',
    columns: columns
  });
  var _overviewApis$useCzz = overviewApis.useCzz(id),
    _overviewApis$useCzz$ = _overviewApis$useCzz.data,
    totalData = _overviewApis$useCzz$ === void 0 ? {} : _overviewApis$useCzz$;
  var _overviewApis$useCtl = overviewApis.useCtl(id),
    _overviewApis$useCtl$ = _overviewApis$useCtl.data,
    ctlData = _overviewApis$useCtl$ === void 0 ? {} : _overviewApis$useCtl$;
  var _totalData$totalCzzCo = totalData.totalCzzCount,
    totalCzzCount = _totalData$totalCzzCo === void 0 ? 0 : _totalData$totalCzzCo,
    _totalData$yysWeight = totalData.yysWeight,
    yysWeight = _totalData$yysWeight === void 0 ? 0 : _totalData$yysWeight,
    _totalData$syWeight = totalData.syWeight,
    syWeight = _totalData$syWeight === void 0 ? 0 : _totalData$syWeight;
  var _ctlData$totalWeight = ctlData.totalWeight,
    totalWeight = _ctlData$totalWeight === void 0 ? 0 : _ctlData$totalWeight;
  var totalList = [{
    name: '处置证数量',
    unit: '张',
    value: totalCzzCount,
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
    },
    img: isDark ? dispose_czz_dark : dispose_czz_light,
    fontType: 'blue'
  }, {
    name: '总申报量',
    unit: unitStr,
    value: totalWeight,
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
    },
    img: isDark ? dispose_zsbl_dark : dispose_zsbl_light,
    fontType: 'green'
  }, {
    name: '总已运量',
    unit: unitStr,
    value: yysWeight,
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
    },
    img: isDark ? dispose_zyyl_dark : dispose_zyyl_light,
    fontType: 'purple'
  }, {
    name: '剩余量',
    unit: unitStr,
    value: syWeight,
    unitStyle: {
      fontSize: 14
    },
    style: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
    },
    img: isDark ? dispose_syl_dark : dispose_syl_light,
    fontType: 'yellow'
  }];
  var searchList = [{
    title: '运输单位',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMInput, {
      style: {
        width: 120
      },
      value: transportUnitName,
      onValChange: function onValChange(val) {
        setState({
          transportUnitName: val
        });
      }
    })
  }, {
    title: '运输终点',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMInput, {
      style: {
        width: 120
      },
      value: endingPointName,
      onValChange: function onValChange(val) {
        setState({
          endingPointName: val
        });
      }
    })
  }, {
    title: '生效状态',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMSelect, {
      options: effectiveStatusList.map(function (item) {
        return {
          value: item.value,
          label: item.text
        };
      }),
      style: {
        width: 120
      },
      placeholder: "\u8BF7\u9009\u62E9",
      value: effectiveStatusCode,
      allowClear: true,
      onChange: function onChange(val) {
        setState({
          effectiveStatusCode: val
        });
      }
    })
  }, {
    title: '运输垃圾类型',
    weight: 1,
    dom: /*#__PURE__*/_jsx(VmFilter.VMSelect, {
      options: garbageTypeList.map(function (item) {
        return {
          value: item.parmCode,
          label: item.parmName
        };
      }),
      style: {
        width: 120
      },
      placeholder: "\u8BF7\u9009\u62E9",
      value: garbageTypeCode,
      onChange: function onChange(val) {
        setState({
          garbageTypeCode: val
        });
      }
    })
  }];
  return /*#__PURE__*/_jsxs("div", {
    className: "dispose",
    children: [/*#__PURE__*/_jsx("div", {
      children: /*#__PURE__*/_jsx(VmWrapper, {
        showContent: false,
        needChange: true,
        headerStyle: {
          height: '56px',
          padding: 0,
          borderBottom: 'unset'
        },
        extraStyle: {
          left: '16px',
          right: 'unset',
          top: '50%',
          transform: 'translateY(-50%)'
        },
        activeKey: activeKey,
        onChange: function onChange(key) {
          return setState({
            activeKey: key
          });
        }
      })
    }), /*#__PURE__*/_jsx(_Fragment, {
      children: activeKey === 'chart' ? /*#__PURE__*/_jsx(FlowMap, {
        flowData: flowData,
        info: info
      }) : /*#__PURE__*/_jsxs("div", {
        className: "dispose-myTable",
        children: [/*#__PURE__*/_jsx("div", {
          className: "dispose-myTable-total",
          children: /*#__PURE__*/_jsx(VmWrapper, {
            showTitle: false,
            contentStyle: {
              padding: 0
            },
            children: /*#__PURE__*/_jsx(VmFactorList, {
              list: totalList,
              style: {
                background: 'unset',
                height: '100%'
              }
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: "dispose-myTable-search",
          children: /*#__PURE__*/_jsx(VmWrapper, {
            showTitle: false,
            children: /*#__PURE__*/_jsxs("div", {
              className: "dispose-myTable-search-main",
              children: [/*#__PURE__*/_jsx("div", {
                className: "dispose-myTable-search-main-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: "dispose-myTable-search-main-right",
                children: [/*#__PURE__*/_jsx(Button, {
                  type: "primary",
                  onClick: submit,
                  children: "\u67E5\u8BE2"
                }), /*#__PURE__*/_jsx(Button, {
                  onClick: myReset,
                  children: "\u91CD\u7F6E"
                })]
              })]
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          className: "dispose-myTable-main",
          children: /*#__PURE__*/_jsx(VmWrapper, {
            showTitle: false,
            children: /*#__PURE__*/_jsx(VmTable, _objectSpread({}, myTableProps))
          })
        })]
      })
    })]
  });
}