"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmFilter = require("../../../vm-filter");
var _vmImageText = _interopRequireDefault(require("../../../vm-image-text"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
require("./index.less");
var _ccts = _interopRequireDefault(require("../../imgs/ccts.png"));
var _zsh = _interopRequireDefault(require("../../imgs/zsh.png"));
var _ccts_light = _interopRequireDefault(require("../../imgs/ccts_light.png"));
var _zsh_light = _interopRequireDefault(require("../../imgs/zsh_light.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; } /**
 * 水耗信息
 */
var WaterConsumption = function WaterConsumption(props) {
  var _useSettings = (0, _useSettings2["default"])(),
    isDark = _useSettings.isDark,
    sDate = _useSettings.startDate,
    eDate = _useSettings.endDate;
  var id = props.id;
  var nowDate = (0, _moment["default"])().format('YYYY-MM-DD');
  var _useSetState = (0, _ahooks.useSetState)({
      startDate: sDate ? sDate : (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'),
      endDate: eDate ? eDate : nowDate,
      order: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var startDate = state.startDate,
    endDate = state.endDate,
    order = state.order;
  var _WaterService$useSumm = _api.WaterService.useSummary(id, startDate, endDate),
    summaryRes = _WaterService$useSumm.summaryRes;
  var _WaterService$useReco = _api.WaterService.useRecord(id, startDate, endDate, order),
    recordRes = _WaterService$useReco.recordRes;
  var handleDateChange = function handleDateChange(start, end) {
    setState({
      startDate: start,
      endDate: end
    });
  };
  var columns = [{
    title: '日期',
    dataIndex: 'day',
    key: 'day',
    sorter: true
  }, {
    title: '总水耗(L)',
    dataIndex: 'useValue',
    key: 'useValue'
  }];
  var handleTableChange = function handleTableChange(sorter) {
    setState({
      order: sorter.order === 'ascend' ? 'ASC' : 'DESC'
    });
  };
  var tableProps = {
    pagination: {
      total: (recordRes === null || recordRes === void 0 ? void 0 : recordRes.total) || 0,
      defaultPageSize: 10
    },
    height: 360,
    handleTableChange: handleTableChange,
    dataSource: (recordRes === null || recordRes === void 0 ? void 0 : recordRes.rows) || []
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "water-consumption"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "water-consumption-head"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "water-consumption-head-filter"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u6C47\u603B\u7EDF\u8BA1",
    extra: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
      value: [(0, _moment["default"])(startDate), (0, _moment["default"])(endDate)],
      onChange: function onChange(dates) {
        return dates && handleDateChange((0, _moment["default"])(dates[0]).format('YYYY-MM-DD'), (0, _moment["default"])(dates[1]).format('YYYY-MM-DD'));
      }
    })
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "water-consumption-head-main"
  }, /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: isDark ? _ccts["default"] : _ccts_light["default"],
    name: "\u51FA\u8F66\u5929\u6570",
    value: (summaryRes === null || summaryRes === void 0 ? void 0 : summaryRes.daysOfCarOut) || 0,
    unit: "\u5929"
  }), /*#__PURE__*/_react["default"].createElement(_vmImageText["default"], {
    src: isDark ? _zsh["default"] : _zsh_light["default"],
    name: "\u603B\u6C34\u8017",
    value: (summaryRes === null || summaryRes === void 0 ? void 0 : summaryRes.totalWater) || 0,
    unit: "L"
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "water-consumption-main"
  }, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns,
    rowKey: "id"
  }, tableProps))));
};
var _default = exports["default"] = WaterConsumption;
//# sourceMappingURL=index.js.map
