"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _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 _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

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

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

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r, a = arguments[t];
      for (r in a) Object.prototype.hasOwnProperty.call(a, r) && (e[r] = a[r])
    }
    return e
  }).apply(this, arguments)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

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

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
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() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var c;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(c = t.call(this, e)), "componentDidMount", function() {}), _defineProperty(_assertThisInitialized(c), "setDayHistoryChartViewProps", function(e, t, r) {
        var a = c.searchParam,
          i = new Date;
        return i.setTime(i.getTime() - ONEDAY_HOUR * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL), i = i.getTime(), {
          unit: r,
          interval: 2 * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL,
          min: void 0 === a.startTimeStr ? (new Date).getTime() - ONE_DAY : new Date(a.startTimeStr).getTime(),
          max: (void 0 === a.endTimeStr ? new Date : new Date(a.endTimeStr)).getTime(),
          axisLabelFormatter: _DateUtil.dateToNoYSWeek,
          data: e,
          legend: t
        }
      }), _defineProperty(_assertThisInitialized(c), "getChartContent", function() {
        var o = c.state.historyData,
          s = [];
        return Object.keys(o).map(function(e) {
          var t = e.split("-")[1],
            r = e.split("-")[2],
            a = e.split("-")[3],
            i = _defineProperty({}, r, o[e]),
            n = [{
              name: r,
              icon: "circle",
              color: "#345FA6",
              fetchDateName: "exeTime",
              valueVarName: r
            }];
          s.push(_react.default.createElement("div", {
            key: e,
            className: "history-single-chart"
          }, _react.default.createElement("div", {
            className: "history-single-chart-title"
          }, _react.default.createElement("label", null, t, "：", r)), _react.default.createElement(_HistoryChartView.default, _extends({}, c.setDayHistoryChartViewProps(i, n, a), c.props))))
        }), s
      }), _defineProperty(_assertThisInitialized(c), "getHistoryData", function() {
        var e;
        void 0 !== c.searchParam.eqpId ? (void 0 === c.searchParam.startTimeStr && ((e = new Date).setTime(e.getTime() - ONEDAY_HOUR * ONEHOUR_MINUTE * ONEMINUTE_SECOND * ONESECOND_MILL), e = e.format("yyyy-MM-dd hh:mm:ss"), c.searchParam.startTimeStr = e), void 0 === c.searchParam.endTimeStr && (e = (new Date).format("yyyy-MM-dd hh:mm:ss"), c.searchParam.endTimeStr = e), c.setState({
          loading: !0
        }), _processor.AmosFetch.post(_urlConsts.default.getHistoryData, {
          data: c.searchParam
        }).then(function(e) {
          if (e.ok) return e.json();
          throw c.setState({
            loading: !1
          }), new Error("从服务端获取数据失败！")
        }).then(function(e) {
          c.setState({
            loading: !1
          }), "SUCCESS" === e.result && c.setState({
            historyData: null === e.dataList ? {} : e.dataList
          })
        })) : _amosFramework.message.danger("请选择要查询的设备")
      }), _defineProperty(_assertThisInitialized(c), "setSearchDeviceParam", function(e) {
        var t = c.searchParam;
        0 === parseInt(e) ? t.eqpId = void 0 : t.eqpId = e, c.searchParam = t
      }), _defineProperty(_assertThisInitialized(c), "setSearchCapacityParam", function(e) {
        var t = c.searchParam;
        0 === parseInt(e) ? t.cpblId = void 0 : t.cpblId = e, c.searchParam = t
      }), _defineProperty(_assertThisInitialized(c), "setStartTimeParam", function(e) {
        var t = c.searchParam;
        t.startTimeStr = e, c.searchParam = t
      }), _defineProperty(_assertThisInitialized(c), "setEndTimeParam", function(e) {
        var t = c.searchParam;
        t.endTimeStr = e, c.searchParam = t
      }), _defineProperty(_assertThisInitialized(c), "setEmptyParam", function() {
        var e = c.searchParam;
        e.cpblId = void 0, e.eqpId = void 0, c.searchParam = e, c.setState({
          historyData: {}
        })
      }), _defineProperty(_assertThisInitialized(c), "handleDataAnaysisClick", function() {
        window.open((0, _outterUrlConsts.dataAnaysisUrl)(), "dataAnalysis")
      }), c.searchParam = {}, c.state = {
        historyData: {
          cpuData: []
        },
        loading: !1
      }, c
    }
    return _createClass(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
  }();
HistoryPanel.displayName = "HistoryPanel", HistoryPanel.propTypes = {};
var _default = HistoryPanel;
exports.default = HistoryPanel, module.exports = exports.default;
