"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _processor = require("../../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../../consts/urlConsts")), _outterUrlConsts = require("../../../consts/outterUrlConsts"), _QueryPanel = _interopRequireDefault(require("./QueryPanel")), _HistoryChartView = _interopRequireDefault(require("./HistoryChartView")), _DateUtil = require("./../common/date/DateUtil");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var s in e) if ("default" !== s && Object.prototype.hasOwnProperty.call(e, s)) {
    var n = i ? Object.getOwnPropertyDescriptor(e, s) : null;
    n && (n.get || n.set) ? Object.defineProperty(a, s, n) : a[s] = e[s];
  }
  return a.default = e, r && r.set(e, a), a;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, a = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } else r = a.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

require("./history.scss");

var ONEDAY_HOUR = 24, ONEHOUR_MINUTE = 60, ONEMINUTE_SECOND = 60, ONESECOND_MILL = 1e3, ONE_DAY = 24 * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL, HistoryPanel = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "componentDidMount", (function() {})), (0, 
    _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setDayHistoryChartViewProps", (function(e, t, r) {
      var i = a.searchParam, s = new Date;
      return s.setTime(s.getTime() - ONEDAY_HOUR * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL), 
      s = s.getTime(), {
        unit: r,
        interval: 2 * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL,
        min: void 0 === i.startTimeStr ? (new Date).getTime() - ONE_DAY : new Date(i.startTimeStr).getTime(),
        max: void 0 === i.endTimeStr ? (new Date).getTime() : new Date(i.endTimeStr).getTime(),
        axisLabelFormatter: _DateUtil.dateToNoYSWeek,
        data: e,
        legend: t
      };
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getChartContent", (function() {
      var e = a.state.historyData, t = [];
      return Object.keys(e).map((function(r) {
        var i = r.split("-")[1], s = r.split("-")[2], n = r.split("-")[3], l = (0, _defineProperty2.default)({}, s, e[r]), o = [ {
          name: s,
          icon: "circle",
          color: "#345FA6",
          fetchDateName: "exeTime",
          valueVarName: s
        } ];
        t.push(_react.default.createElement("div", {
          key: r,
          className: "history-single-chart"
        }, _react.default.createElement("div", {
          className: "history-single-chart-title"
        }, _react.default.createElement("label", null, i, "：", s)), _react.default.createElement(_HistoryChartView.default, (0, 
        _extends2.default)({}, a.setDayHistoryChartViewProps(l, o, n), a.props))));
      })), t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getHistoryData", (function() {
      if (void 0 !== a.searchParam.eqpId) {
        if (void 0 === a.searchParam.startTimeStr) {
          var e = new Date;
          e.setTime(e.getTime() - ONEDAY_HOUR * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL);
          var t = e.format("yyyy-MM-dd hh:mm:ss");
          a.searchParam.startTimeStr = t;
        }
        if (void 0 === a.searchParam.endTimeStr) {
          var r = (new Date).format("yyyy-MM-dd hh:mm:ss");
          a.searchParam.endTimeStr = r;
        }
        a.setState({
          loading: !0
        }), _processor.AmosFetch.post(_urlConsts.default.getHistoryData, {
          data: a.searchParam
        }).then((function(e) {
          if (e.ok) return e.json();
          throw a.setState({
            loading: !1
          }), new Error("从服务端获取数据失败！");
        })).then((function(e) {
          a.setState({
            loading: !1
          }), "SUCCESS" === e.result && a.setState({
            historyData: null === e.dataList ? {} : e.dataList
          });
        }));
      } else _amosFramework.message.danger("请选择要查询的设备");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setSearchDeviceParam", (function(e) {
      var t = a.searchParam;
      0 === parseInt(e) ? t.eqpId = void 0 : t.eqpId = e, a.searchParam = t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setSearchCapacityParam", (function(e) {
      var t = a.searchParam;
      0 === parseInt(e) ? t.cpblId = void 0 : t.cpblId = e, a.searchParam = t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setStartTimeParam", (function(e) {
      var t = a.searchParam;
      t.startTimeStr = e, a.searchParam = t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setEndTimeParam", (function(e) {
      var t = a.searchParam;
      t.endTimeStr = e, a.searchParam = t;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "setEmptyParam", (function() {
      var e = a.searchParam;
      e.cpblId = void 0, e.eqpId = void 0, a.searchParam = e, a.setState({
        historyData: {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleDataAnaysisClick", (function() {
      window.open((0, _outterUrlConsts.dataAnaysisUrl)(), "dataAnalysis");
    })), a.searchParam = {}, a.state = {
      historyData: {
        cpuData: []
      },
      loading: !1
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "render",
    value: function() {
      var e = this.state.historyData;
      return _react.default.createElement("div", {
        className: "history-root",
        style: {
          height: "100%"
        }
      }, _react.default.createElement(_amosAntd.Spin, {
        spinning: this.state.loading,
        delay: 500
      }, _react.default.createElement("div", {
        className: "history-select-area"
      }, _react.default.createElement("div", {
        className: "history-select-title"
      }), _react.default.createElement(_QueryPanel.default, {
        setSearchDeviceParam: this.setSearchDeviceParam,
        setSearchCapacityParam: this.setSearchCapacityParam,
        setEndTimeParam: this.setEndTimeParam,
        setStartTimeParam: this.setStartTimeParam,
        setEmptyParam: this.setEmptyParam,
        getHistoryData: this.getHistoryData
      }))), _react.default.createElement("div", {
        className: "history-chart-area"
      }, 0 === Object.keys(e).length ? _react.default.createElement("img", {
        src: require("./../../../assets/tip/empty.png"),
        style: {
          margin: "18% 43%"
        },
        alt: "empty"
      }) : this.getChartContent()));
    }
  } ]), r;
}(_react.Component);

HistoryPanel.displayName = "HistoryPanel", HistoryPanel.propTypes = {};

var _default = HistoryPanel;

exports.default = _default;