"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 _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime/helpers/objectDestructuringEmpty")), _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"), _rayEventpool = require("ray-eventpool"), _amosFramework = require("amos-framework"), _dt2react = require("dt2react"), _ActionConf = require("./../common/ActionConf"), _AmosGridTable = _interopRequireDefault(require("./../../common/tableComponent/table/AmosGridTable")), _DeviceEnum = require("./../../deviceManage/common/DeviceEnum"), _DeviceLang = require("./../../deviceManage/common/DeviceLang");

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

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, i = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(i, arguments, n);
    } else r = i.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;
  }
}

var deviceColumns = function(e, t, r) {
  return [ {
    title: "设备名称",
    dataIndex: "name",
    key: "name",
    width: "16%"
  }, {
    title: "设备类型",
    dataIndex: "tmplName",
    key: "tmplName",
    width: "12%",
    render: function(e, r) {
      var i = "tree-td-children";
      return r.children && 0 === r.children.length && (i = "tree-td-children-empty"), 
      _react.default.createElement("div", {
        className: i
      }, t.name);
    }
  }, {
    title: "设备类别",
    dataIndex: "type",
    key: "type",
    width: "12%",
    render: function(e) {
      return (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, t.type);
    }
  }, {
    title: "所属行业",
    dataIndex: "industryId",
    key: "industryId",
    width: "10%",
    render: function(e) {
      return t.equipTemplateIndustry.name;
    }
  }, {
    title: "设备型号",
    dataIndex: "model",
    key: "model",
    width: "12%",
    render: function(e) {
      return t.model;
    }
  }, {
    title: "设备描述",
    dataIndex: "descr",
    key: "descr",
    width: "16%"
  }, , {
    title: "所属视图",
    dataIndex: "nodeName",
    key: "nodeName",
    width: "12%"
  }, {
    title: "操作",
    key: "action",
    width: "16%",
    render: function(i, n) {
      return _react.default.createElement("span", null, _react.default.createElement("label", {
        className: "view-detail",
        onClick: function() {
          return e.updateMainView({
            flag: "5",
            device: t,
            resourceFlag: "3",
            equipment: n,
            pageConfig: r
          });
        }
      }, "详情"), _react.default.createElement("label", {
        className: "edit-device",
        onClick: function() {
          return e.updateMainView({
            flag: "4",
            device: t,
            resourceFlag: "3",
            equipment: n,
            pageConfig: r
          });
        }
      }, "编辑"), _react.default.createElement("label", {
        className: "delete-device",
        onClick: function() {
          return e.deleteDevice(n.id);
        }
      }, "删除"));
    }
  } ];
}, offsetHeight = 110, defaultHeight = 450, DeviceListPanelContent = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var i;
    return (0, _classCallCheck2.default)(this, r), i = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(i), "getSelectedRows", (function(e, t) {
      i.setState({
        selectedRows: e,
        selectedRowKeys: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "reload", (function(e) {
      i.setState({
        reload: function() {
          e(), i.setState({
            selectedRows: [],
            selectedRowKeys: []
          });
        }
      }, e());
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "deleteDevice", (function(e) {
      _amosAntd.Modal.confirm({
        content: "确定要删除吗？",
        onCancel: function() {},
        onOk: function() {
          var t = [ e ];
          i.props.deleteDeviceById(t);
        }
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "deleteMultiDevice", (function(e) {
      _amosAntd.Modal.confirm({
        content: "确定要删除吗？",
        onCancel: function() {},
        onOk: function() {
          i.props.deleteDeviceById(e);
        }
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "getRowClassName", (function(e, t) {
      var r = i.highlight;
      return r && e.id === r ? "highlight-row" : "normal-row";
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "setPageConfig", (function(e) {
      var t = e.pageSize, r = e.current;
      void 0 !== t && (i.pageConfig.pageSize = t), void 0 !== r && (i.pageConfig.current = r);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "getPanelHeight", (function() {
      var e = i.alarmTablePanel, t = (0, _dt2react.getOffset)(e) || {};
      return void 0 !== t ? t.height - offsetHeight : defaultHeight;
    })), i.pageConfig = {
      current: e.outterPageConfig ? e.outterPageConfig.current : 1,
      pageSize: e.outterPageConfig ? e.outterPageConfig.pageSize : 10
    }, i.state = {
      selectedRows: [],
      selectedRowKeys: [],
      reload: function() {}
    }, i;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {
      var e = this;
      this.batchDelete = _rayEventpool.PubSub.subscribe(_ActionConf.EQUIPMENT_BATCH_DELETE_TOPIC.equipmentBatchDelete, (function(t, r) {
        (0, _objectDestructuringEmpty2.default)(r);
        var i = e.state.selectedRowKeys;
        0 === i.length ? _amosFramework.message.danger("请选择要删除的设备") : e.deleteMultiDevice(i);
      }));
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = e.equipment;
      if (void 0 !== t) {
        var r = this.state, i = r.selectedRows, n = r.selectedRowKeys;
        i.push(t), n.push(t.id), this.highlight = t.id;
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function() {
      _rayEventpool.PubSub.unsubscribe(this.batchDelete);
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.props, r = t.equipmentList, i = t.fetchData, n = t.device, a = t.count, o = t.updateMainView, l = this.state.reload, u = this.pageConfig, c = this.pageConfig, s = {
        deleteDevice: this.deleteDevice,
        reload: l,
        updateMainView: o
      };
      return _react.default.createElement("div", {
        className: "device-list-content",
        ref: function(t) {
          return e.alarmTablePanel = t;
        }
      }, _react.default.createElement(_AmosGridTable.default, {
        columns: deviceColumns(s, n, c),
        callBack: this.reload,
        dataList: r,
        totals: a,
        getTableDataAction: i,
        getSelectedRows: this.getSelectedRows,
        rowClassName: this.getRowClassName,
        setPageConfig: this.setPageConfig,
        defaultPageConfig: u,
        getPanelHeight: this.getPanelHeight
      }));
    }
  } ]), r;
}(_react.Component);

DeviceListPanelContent.displayName = "DeviceListPanelContent", DeviceListPanelContent.propTypes = {
  equipmentList: _propTypes.default.array,
  fetchData: _propTypes.default.func,
  device: _propTypes.default.object,
  count: _propTypes.default.number,
  updateMainView: _propTypes.default.func,
  deleteDeviceById: _propTypes.default.func,
  equipment: _propTypes.default.object,
  outterPageConfig: _propTypes.default.object
};

var _default = DeviceListPanelContent;

exports.default = _default;