"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _amosAntd = require("amos-antd"),
  _amosFramework = require("amos-framework"),
  _processor = require("../../utils/processor"),
  _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")),
  _AmosGridTable = _interopRequireDefault(require("./common/table/AmosGridTable")),
  _addRule = _interopRequireDefault(require("./addRule")),
  _editRule = _interopRequireDefault(require("./editRule")),
  _monitorObjList = _interopRequireDefault(require("./monitorObjList"));

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, n, o = {},
    a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((n = a ? Object.getOwnPropertyDescriptor(e, r) : null) && (n.get || n.set) ? Object.defineProperty(o, r, n) : o[r] = e[r]);
  return o.default = e, t && t.set(e, o), o
}

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, n = arguments[t];
      for (r in n) Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[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 n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
  }
}

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 n = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, n ? (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("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss"), require("./common/index.scss");
var monitorColumns = function(r) {
    return [{
      title: "任务名称",
      dataIndex: "name",
      key: "name",
      width: "20%"
    }, {
      title: "对象数量",
      dataIndex: "objNum",
      key: "objNum",
      width: "10%",
      render: function(e, t) {
        return _react.default.createElement("span", null, _react.default.createElement(_monitorObjList.default, {
          text: e,
          monitorRuleInfo: t
        }))
      }
    }, {
      title: "任务类型",
      dataIndex: "monitorType",
      key: "monitorType",
      width: "10%",
      render: function(e) {
        return 1 === e ? "采集" : "监听"
      }
    }, {
      title: "采集周期（秒/次）",
      dataIndex: "period",
      key: "period",
      width: "20%",
      render: function(e) {
        return 0 === e ? "--" : e
      }
    }, {
      title: "最后修改时间",
      dataIndex: "updateTime",
      key: "startTime",
      width: "20%"
    }, {
      title: "操作",
      key: "action",
      width: "20%",
      render: function(e, t) {
        return _react.default.createElement("span", null, _react.default.createElement(_editRule.default, {
          reload: r.reload,
          text: "编辑",
          monitorRuleInfo: t
        }), _react.default.createElement(_amosAntd.Button, {
          size: "small",
          style: {
            marginLeft: "10px"
          },
          onClick: function() {
            return r.delConfirm(t.id)
          }
        }, "删除"), _react.default.createElement(_amosFramework.Switch, {
          onLabel: "启",
          offLabel: "停",
          onOff: t.isEnabled,
          style: {
            marginLeft: "10px"
          },
          onChange: function(e) {
            return r.oneOpenOrClose(e, t.id)
          }
        }))
      }
    }]
  },
  RuleMgmt = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var o;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(o = t.call(this, e)), "onRefresh", function() {
        o.selectDataList({
          current: 0,
          pageSize: 10
        })
      }), _defineProperty(_assertThisInitialized(o), "oneOpenOrClose", function(e, t) {
        var r = [];
        r.push(t);
        e = {
          ruleIds: r,
          statusFlag: e
        };
        o.openOrClose(e)
      }), _defineProperty(_assertThisInitialized(o), "getSelectedRows", function(e, t) {
        o.setState({
          selectedRows: e,
          selectedRowKeys: t
        })
      }), _defineProperty(_assertThisInitialized(o), "batchOpenOrClose", function(e) {
        e = {
          ruleIds: o.state.selectedRowKeys,
          statusFlag: e
        };
        o.openOrClose(e)
      }), _defineProperty(_assertThisInitialized(o), "addButtons", function() {
        var e = [],
          t = o.state.reload;
        return e.push(_react.default.createElement(_addRule.default, _extends({
          reload: t,
          text: "新增"
        }, o.props))), e.push(_react.default.createElement(_amosAntd.Button, {
          type: "primary",
          style: {
            float: "left",
            marginLeft: "10px"
          },
          onClick: function() {
            return o.batchOpenOrClose(!0)
          }
        }, "批量启用")), e.push(_react.default.createElement(_amosAntd.Button, {
          type: "primary",
          style: {
            marginLeft: "10px"
          },
          onClick: function() {
            return o.batchOpenOrClose(!1)
          }
        }, "批量停用")), e
      }), _defineProperty(_assertThisInitialized(o), "reload", function(e) {
        o.setState({
          reload: function() {
            e(), o.setState({
              selectedRows: [],
              selectedRowKeys: []
            })
          }
        }, e())
      }), _defineProperty(_assertThisInitialized(o), "selectDataList", function(n) {
        n = n || o.state.filter;
        var e = "".concat(_urlConsts.default.monitorRuleDataList, "?pageNumber=").concat(n.current, "&pageSize=").concat(n.pageSize);
        _processor.AmosFetch.post(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t = new Date,
            r = t.getHours(),
            t = t.getMinutes();
          t < 10 && (t = "0".concat(t));
          r = "".concat(r, "时").concat(t, "分");
          "SUCCESS" === e.state ? (t = e.totalElements, null !== e.content && o.setState({
            dataList: e.content,
            refreshTime: r,
            total: t,
            filter: n
          })) : o.setState({
            dataList: [],
            refreshTime: r,
            total: 0,
            filter: n
          })
        })
      }), _defineProperty(_assertThisInitialized(o), "delConfirm", function(e) {
        _amosAntd.Modal.confirm({
          content: "确定删除吗？",
          onCancel: function() {},
          onOk: function() {
            o.delMonitorRule(e)
          }
        })
      }), _defineProperty(_assertThisInitialized(o), "delMonitorRule", function(e) {
        e = "".concat(_urlConsts.default.monitorRuleDel, "/").concat(e);
        _processor.AmosFetch.del(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? (o.selectDataList(), _amosFramework.message.success("删除成功！")) : _amosFramework.message.danger("删除失败！")
        })
      }), _defineProperty(_assertThisInitialized(o), "openOrClose", function(e) {
        var t = _urlConsts.default.monitorIsenable;
        _processor.AmosFetch.post(t, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          o.selectDataList()
        })
      }), o.state = {
        dataList: [],
        selectedRows: [],
        selectedRowKeys: [],
        total: 0,
        reload: function() {}
      }, o
    }
    return _createClass(r, [{
      key: "componentWillMount",
      value: function() {}
    }, {
      key: "render",
      value: function() {
        var e = this.state,
          t = e.dataList,
          r = e.refreshTime,
          n = e.total,
          e = e.reload,
          e = {
            delConfirm: this.delConfirm,
            oneOpenOrClose: this.oneOpenOrClose,
            reload: e
          };
        return _react.default.createElement("div", {
          className: "rule-view-content giot-content-card"
        }, _react.default.createElement("div", {
          className: "rule-view-header"
        }, _react.default.createElement("div", {
          className: "rule-view-header-title"
        }, _react.default.createElement("span", null, "最新刷新时刻：", r), _react.default.createElement(_amosAntd.Button, {
          type: "primary",
          onClick: this.onRefresh,
          style: {
            marginLeft: "30px"
          }
        }, "数据刷新"))), _react.default.createElement("div", {
          className: "rule-view-body"
        }, _react.default.createElement("div", {
          style: {
            marginTop: "10px"
          }
        }, _react.default.createElement(_AmosGridTable.default, {
          columns: monitorColumns(e),
          callBack: this.reload,
          dataList: t,
          totals: n,
          getTableDataAction: this.selectDataList,
          operBtns: this.addButtons(),
          getSelectedRows: this.getSelectedRows
        }))))
      }
    }]), r
  }();
RuleMgmt.displayName = "RuleMgmt", RuleMgmt.propTypes = {};
var _default = RuleMgmt;
exports.default = RuleMgmt, module.exports = exports.default;
