"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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 = _interopRequireDefault(require("dt2react")), _ActionConf = require("./../common/ActionConf"), _AmosGridTable = _interopRequireDefault(require("./../../common/tableComponent/table/AmosGridTable")), _DeviceEnum = require("./../../deviceManage/common/DeviceEnum"), _DeviceLang = require("./../../deviceManage/common/DeviceLang");

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

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