"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _ahooks = require("ahooks");

var _icons = require("@ant-design/icons");

var _antd = require("antd");

var _moment = _interopRequireDefault(require("moment"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _useSettings3 = _interopRequireDefault(require("../vm-hooks/useSettings"));

var _vmFilter = require("../vm-filter");

var _vmStatCollection = _interopRequireDefault(require("../vm-stat-collection"));

var _vmTable = _interopRequireWildcard(require("../vm-table"));

var _vmChart = _interopRequireDefault(require("../vm-chart"));

var _vmSubTabs = _interopRequireWildcard(require("../vm-sub-tabs"));

var _api = require("./api");

require("./style");

var _projectDark = _interopRequireDefault(require("../../image/project-dark.png"));

var _project = _interopRequireDefault(require("../../image/project.png"));

var _realDark = _interopRequireDefault(require("../../image/real-dark.png"));

var _real = _interopRequireDefault(require("../../image/real.png"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var WeighContent = function WeighContent(props) {
  var id = props.id,
      code = props.code,
      seed = props.seed;

  var _useSetState = (0, _ahooks.useSetState)({
    startTime: (0, _moment["default"])().subtract(1, 'd'),
    endTime: (0, _moment["default"])(),
    ids: [],
    tabKey: 'base'
  }),
      _useSetState2 = _slicedToArray(_useSetState, 2),
      state = _useSetState2[0],
      setState = _useSetState2[1];

  (0, _react.useEffect)(function () {
    if (seed) setState({
      startTime: (0, _moment["default"])().subtract(1, 'd'),
      endTime: (0, _moment["default"])(),
      ids: [],
      tabKey: 'base'
    });
  }, [seed]);

  var _useRequest = (0, _ahooks.useRequest)(function (_ref) {
    var current = _ref.current,
        pageSize = _ref.pageSize;
    return _api.WeighData.useWeighList(id, state.startTime.format('YYYY-MM-DD 00:00:00'), state.endTime.format('YYYY-MM-DD 23:59:59'), current - 1, pageSize, code);
  }, {
    defaultPageSize: 10,
    paginated: true,
    refreshDeps: [state.startTime, state.endTime, id, code]
  }),
      tableProps = _useRequest.tableProps;

  var _useSettings = (0, _useSettings3["default"])(),
      isDark = _useSettings.isDark;

  var statInfo = _api.WeighData.useWeighStat(id, state.startTime.format('YYYY-MM-DD 00:00:00'), state.endTime.format('YYYY-MM-DD 23:59:59'), state.page, state.size, code);

  var statData = [{
    icon: isDark ? _projectDark["default"] : _project["default"],
    label: '出场车次',
    value: statInfo === null || statInfo === void 0 ? void 0 : statInfo.count,
    unit: '次'
  }, {
    icon: isDark ? _realDark["default"] : _real["default"],
    label: '出场量',
    value: statInfo === null || statInfo === void 0 ? void 0 : statInfo.netWeightTotal,
    unit: '吨'
  }];

  var handleDateChange = function handleDateChange(startTime, endTime) {
    setState({
      startTime: startTime,
      endTime: endTime
    });
  };

  var handleExport = function handleExport(type) {
    var _tableProps$dataSourc;

    var downloadAll = false;
    var ids = '';

    switch (type) {
      case 'all':
        downloadAll = true;
        break;

      case 'select-rows':
        ids = state.ids.join(',');
        break;

      case 'current-page':
        ids = tableProps === null || tableProps === void 0 ? void 0 : (_tableProps$dataSourc = tableProps.dataSource) === null || _tableProps$dataSourc === void 0 ? void 0 : _tableProps$dataSourc.map(function (i) {
          return i.id;
        }).join(',');
        break;

      default:
        break;
    }

    if (!downloadAll && ids.length === 0) {
      _antd.message.warning('当前没有选中行');

      return;
    }

    _api.WeighData.useWeighExport({
      startTime: state.startTime.format('YYYY-MM-DD 00:00:00'),
      endTime: state.endTime.format('YYYY-MM-DD 23:59:59'),
      downloadAll: downloadAll,
      downloadIds: ids,
      columnFields: 'id,carNo,icCode,productName,sourceUnit,area,areaZone,transportUnit,disposeUnitName,grossTimeStr,tareTimeStr,timeStr,grossWeight,tareWeight,netWeight,productToWhere',
      columnNames: '标识,车牌号,卡号,货物名称,发货单位,区域,街道,运输单位,处置单位,进厂时间,出厂时间,称重时间,毛重（吨）,皮重（吨）,净重（吨）,货物流向'
    });
  };

  var handleTabChange = function handleTabChange(tabKey) {
    setState({
      tabKey: tabKey
    });
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "muck-metering-content"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs["default"], {
    onTabClick: handleTabChange
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
    tab: /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_icons.UnorderedListOutlined, null), "\u5217\u8868"),
    key: "base"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "top-bar"
  }, /*#__PURE__*/_react["default"].createElement(_vmStatCollection["default"], {
    items: statData
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "time"
  }, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], _extends({
    columns: columns,
    rowSelection: {
      selectedRowKeys: state.ids,
      onChange: function onChange(rowKeys) {
        return setState({
          ids: rowKeys
        });
      }
    }
  }, tableProps)))), /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
    tab: /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_icons.ClockCircleOutlined, null), "\u56FE\u8868"),
    key: "prop"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "top-bar"
  }, /*#__PURE__*/_react["default"].createElement(_vmStatCollection["default"], {
    items: statData
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "chart-container"
  }, /*#__PURE__*/_react["default"].createElement(TrendChart, {
    startTime: state.startTime.format('YYYY-MM-DD 00:00:00'),
    endTime: state.endTime.format('YYYY-MM-DD 23:59:59'),
    code: true
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "right-top"
  }, /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
    value: [state.startTime, state.endTime],
    onChange: function onChange(dates) {
      return dates && handleDateChange(dates[0], dates[1]);
    },
    style: {
      marginRight: 10
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmTable.ExportBtn, {
    onClick: handleExport,
    items: [{
      label: '导出当前页',
      key: 'current-page'
    }, {
      label: '导出全部',
      key: 'all'
    }]
  })));
};

var columns = [{
  title: '车牌号',
  dataIndex: 'carNo',
  key: 'carNo'
}, {
  title: '运输单位',
  dataIndex: 'transportUnit',
  key: 'transportUnit'
}, {
  title: '行政区划',
  dataIndex: 'divisionName',
  key: 'divisionName'
}, {
  title: '垃圾类型',
  dataIndex: 'productName',
  key: 'productName'
}, {
  title: '货物流向',
  dataIndex: 'productToWhere',
  key: 'productToWhere'
}, {
  title: '毛重（吨）',
  dataIndex: 'grossWeight',
  key: 'grossWeight'
}, {
  title: '皮重（吨）',
  dataIndex: 'tareWeight',
  key: 'tareWeight'
}, {
  title: '净重（吨）',
  dataIndex: 'netWeight',
  key: 'netWeight'
}];

var TrendChart = function TrendChart(props) {
  var id = props.id,
      code = props.code;
  var startTime = props.startTime,
      endTime = props.endTime;

  var _useSettings2 = (0, _useSettings3["default"])(),
      isDark = _useSettings2.isDark;

  var data = _api.WeighData.useEchartsList(id, startTime, endTime, code) || [];
  var option = {
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['出场车次', '出场量'],
      textStyle: {
        fontSize: 12,
        color: isDark ? 'white' : '#666'
      }
    },
    xAxis: {
      type: 'category',
      data: data === null || data === void 0 ? void 0 : data.map(function (item) {
        return item === null || item === void 0 ? void 0 : item.dateValue;
      }),
      axisLabel: {
        fontFamily: 'PingFangSC-Regular',
        color: isDark ? '#fff8' : 'rgba(0, 0, 0, 0.5)'
      },
      axisLine: {
        lineStyle: {
          type: 'dashed',
          color: isDark ? '#fff8' : 'rgba(0, 0, 0, 0.5)'
        }
      }
    },
    yAxis: [{
      type: 'value',
      nameTextStyle: {
        fontFamily: 'PingFangSC-Regular',
        color: isDark ? '#fff8' : '#0008'
      },
      axisLabel: {
        fontFamily: 'PingFangSC-Regular',
        color: isDark ? '#fff8' : '#0008'
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: isDark ? '#fff4' : '#0004'
        }
      }
    }, {
      type: 'value',
      nameTextStyle: {
        fontFamily: 'PingFangSC-Regular',
        color: isDark ? '#fff8' : '#0008'
      },
      axisLabel: {
        fontFamily: 'PingFangSC-Regular',
        color: isDark ? '#fff8' : '#0008'
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: isDark ? '#fff4' : '#0004'
        }
      }
    }],
    series: [{
      name: '出场车次',
      type: 'line',
      yAxisIndex: 1,
      tooltip: {
        valueFormatter: function valueFormatter(value) {
          return value + ' 次';
        }
      },
      markLine: {
        data: [{
          type: 'average',
          name: 'Avg'
        }]
      },
      data: data === null || data === void 0 ? void 0 : data.map(function (item) {
        return item === null || item === void 0 ? void 0 : item.carNum;
      }),
      itemStyle: {
        normal: {
          color: '#00B689',
          //改变折线点的颜色
          lineStyle: {
            color: '#00B689' //改变折线颜色

          }
        }
      }
    }, {
      name: '出场量',
      type: 'bar',
      barWidth: '10%',
      tooltip: {
        valueFormatter: function valueFormatter(value) {
          return value + ' 吨';
        }
      },
      markLine: {
        data: [{
          type: 'average',
          name: 'Avg'
        }]
      },
      data: data === null || data === void 0 ? void 0 : data.map(function (item) {
        return item === null || item === void 0 ? void 0 : item.netWeight;
      }),
      itemStyle: {
        // 使用方法二的写法
        color: {
          type: 'linear',
          x: 0,
          //右
          y: 0,
          //下
          x2: 0,
          //左
          y2: 1,
          //上
          colorStops: [{
            offset: 0,
            color: '#00FFE7' // 0% 处的颜色

          }, {
            offset: 1,
            color: '#489AF2' // 100% 处的颜色

          }]
        }
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement(_vmChart["default"], {
    option: option,
    height: 500,
    width: "100%",
    defaultOption: false
  });
};

WeighContent.propTypes = {
  id: _propTypes["default"].string,
  code: _propTypes["default"].string,
  seed: _propTypes["default"].string,
  startTime: _propTypes["default"].string,
  endTime: _propTypes["default"].string
};
TrendChart.propTypes = {
  id: _propTypes["default"].string,
  code: _propTypes["default"].string,
  startTime: _propTypes["default"].string,
  endTime: _propTypes["default"].string,
  deviceId: _propTypes["default"].string,
  monitorTypeCodes: _propTypes["default"].string
};
var _default = WeighContent;
exports["default"] = _default;
//# sourceMappingURL=weigh.js.map
