"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")), _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 _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 = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var o in e) if ("default" !== o && Object.prototype.hasOwnProperty.call(e, o)) {
    var i = n ? Object.getOwnPropertyDescriptor(e, o) : null;
    i && (i.get || i.set) ? Object.defineProperty(a, o, i) : a[o] = e[o];
  }
  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 n = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, n);
    } 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("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss"), 
require("./common/index.scss");

var monitorColumns = function(e) {
  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, t) {
      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(t, r) {
      return _react.default.createElement("span", null, _react.default.createElement(_editRule.default, {
        reload: e.reload,
        text: "编辑",
        monitorRuleInfo: r
      }), _react.default.createElement(_amosAntd.Button, {
        size: "small",
        style: {
          marginLeft: "10px"
        },
        onClick: function() {
          return e.delConfirm(r.id);
        }
      }, "删除"), _react.default.createElement(_amosFramework.Switch, {
        onLabel: "启",
        offLabel: "停",
        onOff: r.isEnabled,
        style: {
          marginLeft: "10px"
        },
        onChange: function(t) {
          return e.oneOpenOrClose(t, r.id);
        }
      }));
    }
  } ];
}, RuleMgmt = 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), "onRefresh", (function() {
      a.selectDataList({
        current: 0,
        pageSize: 10
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "oneOpenOrClose", (function(e, t) {
      var r = [];
      r.push(t);
      var n = {
        ruleIds: r,
        statusFlag: e
      };
      a.openOrClose(n);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getSelectedRows", (function(e, t) {
      a.setState({
        selectedRows: e,
        selectedRowKeys: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "batchOpenOrClose", (function(e) {
      var t = {
        ruleIds: a.state.selectedRowKeys,
        statusFlag: e
      };
      a.openOrClose(t);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "addButtons", (function() {
      var e = [], t = a.state.reload;
      return e.push(_react.default.createElement(_addRule.default, (0, _extends2.default)({
        reload: t,
        text: "新增"
      }, a.props))), e.push(_react.default.createElement(_amosAntd.Button, {
        type: "primary",
        style: {
          float: "left",
          marginLeft: "10px"
        },
        onClick: function() {
          return a.batchOpenOrClose(!0);
        }
      }, "批量启用")), e.push(_react.default.createElement(_amosAntd.Button, {
        type: "primary",
        style: {
          marginLeft: "10px"
        },
        onClick: function() {
          return a.batchOpenOrClose(!1);
        }
      }, "批量停用")), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "reload", (function(e) {
      a.setState({
        reload: function() {
          e(), a.setState({
            selectedRows: [],
            selectedRowKeys: []
          });
        }
      }, e());
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "selectDataList", (function(e) {
      e || (e = a.state.filter);
      var t = "".concat(_urlConsts.default.monitorRuleDataList, "?pageNumber=").concat(e.current, "&pageSize=").concat(e.pageSize);
      _processor.AmosFetch.post(t).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        var r = new Date, n = r.getHours(), o = r.getMinutes();
        o < 10 && (o = "0".concat(o));
        var i = "".concat(n, "时").concat(o, "分");
        if ("SUCCESS" === t.state) {
          var l = t.totalElements;
          null !== t.content && a.setState({
            dataList: t.content,
            refreshTime: i,
            total: l,
            filter: e
          });
        } else a.setState({
          dataList: [],
          refreshTime: i,
          total: 0,
          filter: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "delConfirm", (function(e) {
      _amosAntd.Modal.confirm({
        content: "确定删除吗？",
        onCancel: function() {},
        onOk: function() {
          a.delMonitorRule(e);
        }
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "delMonitorRule", (function(e) {
      var t = "".concat(_urlConsts.default.monitorRuleDel, "/").concat(e);
      _processor.AmosFetch.del(t).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        "SUCCESS" === e.result ? (a.selectDataList(), _amosFramework.message.success("删除成功！")) : _amosFramework.message.danger("删除失败！");
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "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) {
        a.selectDataList();
      }));
    })), a.state = {
      dataList: [],
      selectedRows: [],
      selectedRowKeys: [],
      total: 0,
      reload: function() {}
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "render",
    value: function() {
      var e = this.state, t = e.dataList, r = e.refreshTime, a = e.total, n = e.reload, o = {
        delConfirm: this.delConfirm,
        oneOpenOrClose: this.oneOpenOrClose,
        reload: n
      };
      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(o),
        callBack: this.reload,
        dataList: t,
        totals: a,
        getTableDataAction: this.selectDataList,
        operBtns: this.addButtons(),
        getSelectedRows: this.getSelectedRows
      }))));
    }
  } ]), r;
}(_react.Component);

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

var _default = RuleMgmt;

exports.default = _default;