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 { useContext } from 'react';
import { VmFilter, VmTable, VmTag, VmWrapper } from "../../../../_components";
import { JzljService } from "../../../api";
import { CarContext } from "../../../index";
import "./index.less";
import Pies from "./Pies";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function Dispose() {
  var _useContext = useContext(CarContext),
    id = _useContext.id,
    info = _useContext.info,
    setIframeModalInfo = _useContext.setIframeModalInfo;
  var _useSetState = useSetState({
      activeKey: 'chart',
      code: undefined,
      endingPointName: undefined,
      startingPointName: undefined,
      effectiveStatusCode: 'sxz',
      pieData: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var activeKey = state.activeKey,
    code = state.code,
    endingPointName = state.endingPointName,
    startingPointName = state.startingPointName,
    effectiveStatusCode = state.effectiveStatusCode,
    pieData = state.pieData;
  var _JzljService$useCzzFi = JzljService.useCzzFields(),
    visibleList = _JzljService$useCzzFi.visibleList;
  var effectiveStatusList = JzljService.fetchJzljEnum('EffectiveStatusEnum');
  var fieldConfigData = JzljService.fieldConfig();
  var transportWeightField = fieldConfigData.find(function (item) {
    return item.dataKey === 'transportWeight';
  }) || {};
  var columns = [].concat(_toConsumableArray(visibleList !== null && visibleList !== void 0 && visibleList.length ? visibleList.map(function (item) {
    return [item.displayName, item.dataShowKey, item.dataShowKey === '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
        });
      }
    } : {
      width: item.columnWidth || 120,
      ellipsis: true,
      align: item.dataShowKey === 'transportWeight' ? 'right' : 'left'
    }];
  }) : [['处置证编号', 'code', {
    width: 160,
    ellipsis: true
  }], ['运输单位', 'transportUnitName', {
    width: 160,
    ellipsis: true
  }], ['运输起点', 'startingPointName', {
    width: 160,
    ellipsis: true
  }], ['运输终点', 'endingPointName', {
    width: 160,
    ellipsis: true
  }], ['运输垃圾类型', 'garbageTypeName', {
    width: 100
  }], [(transportWeightField === null || transportWeightField === void 0 ? void 0 : transportWeightField.displayName) || '运输量(吨)', 'transportWeight', {
    width: 100,
    align: 'right'
  }], ['申报有效期', 'effectiveDate', {
    width: 180
  }], ['生效状态', '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 = {
      code: code,
      endingPointName: endingPointName,
      startingPointName: startingPointName,
      effectiveStatusCode: effectiveStatusCode
    };
    JzljService.czzPie(_objectSpread({
      id: id
    }, formData)).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
        setState({
          pieData: (res === null || res === void 0 ? void 0 : res.data) || []
        });
      }
    });
    return JzljService.czzPage(_objectSpread(_objectSpread({}, formData), {}, {
      carCode: info === null || info === void 0 ? void 0 : info.carCode,
      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({
      code: undefined,
      endingPointName: undefined,
      startingPointName: undefined,
      effectiveStatusCode: undefined
    });
    reset();
  };
  var myTableProps = _objectSpread(_objectSpread({}, tableProps), {}, {
    rowKey: 'id',
    columns: columns
  });
  var searchList = [{
    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: startingPointName,
      onValChange: function onValChange(val) {
        setState({
          startingPointName: 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
        });
      }
    })
  }];
  return /*#__PURE__*/_jsxs("div", {
    className: "jzlj-car-dispose",
    children: [/*#__PURE__*/_jsx("div", {
      style: {
        height: '56px'
      },
      children: /*#__PURE__*/_jsx(VmWrapper, {
        title: "\u5904\u7F6E\u6838\u51C6\u4FE1\u606F",
        showContent: false,
        needChange: true,
        headerStyle: {
          borderBottom: 'unset'
        },
        activeKey: activeKey,
        onChange: function onChange(key) {
          return setState({
            activeKey: key
          });
        }
      })
    }), /*#__PURE__*/_jsxs("div", {
      className: "jzlj-car-dispose-myTable",
      children: [/*#__PURE__*/_jsx("div", {
        className: "jzlj-car-dispose-myTable-search",
        children: /*#__PURE__*/_jsx(VmWrapper, {
          showTitle: false,
          children: /*#__PURE__*/_jsxs("div", {
            className: "jzlj-car-dispose-myTable-search-main",
            children: [/*#__PURE__*/_jsx("div", {
              className: "jzlj-car-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: "jzlj-car-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: "jzlj-car-dispose-myTable-main",
        children: /*#__PURE__*/_jsxs(VmWrapper, {
          showTitle: false,
          children: [activeKey === 'list' && /*#__PURE__*/_jsx(VmTable, _objectSpread({}, myTableProps)), activeKey === 'chart' && /*#__PURE__*/_jsx(Pies, {
            pieData: pieData
          })]
        })
      })]
    })]
  });
}