"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")), _propTypes = _interopRequireDefault(require("prop-types")), _amosTool = require("amos-tool"), _amosAntd = require("amos-antd"), _VagueTextFilter = _interopRequireDefault(require("./filter/VagueTextFilter"));

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

var dataToTree = function e() {
  var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [], r = [];
  return t.map((function(t) {
    var a = (t = t || {}).object || {};
    t.id = t.value, t.companyName = a.companyName, t.departmentName = a.departmentName, 
    t.description = a.description, t.companyLevel = a.companyLevel, t.children && (t.children = e(t.children)), 
    r.push(t);
  })), r;
}, SystemTableTree = 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), "onSelectChange", (function(e, t) {
      a.setState({
        selectedRowKeys: e,
        selectedRows: t
      }, a.props.getSelectedRows(t, e));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getbtns", (function() {
      var e = [];
      return a.props.operBtns.map((function(t, r) {
        e.push(_react.default.createElement("div", {
          key: "btn-".concat(r),
          className: "amos-grid-oper-btn"
        }, t));
      })), e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "changeFilters", (function(e) {
      var t = e, r = {};
      Object.keys(t).map((function(e) {
        var a = t[e];
        a && "" !== a && (r[e] = a, "enabled" === e && (r[e] = "启用" === a));
      })), a.setState({
        filter: r
      }, a.reload), console.log("filter:res", a.state.filter);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "clone", (function(e) {
      var t = Object.getPrototypeOf(e);
      return (0, _extends2.default)(Object.create(t), e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "openFilter", (function() {
      var e = a.state.showFilter;
      a.setState({
        showFilter: !e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "reload", (function() {
      a.props.getTableDataAction(a.props.otherFilter);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "addOperateCol", (function(e, t) {
      var r = (0, a.props.operateCol)(e, t);
      return _react.default.createElement("div", {
        className: "operation-buttons"
      }, r);
    })), a.state = {
      localeUrl: e.url || "",
      selectedRowKeys: [],
      selectedRows: [],
      loading: !1,
      dataList: [],
      searchValue: "",
      value: "",
      size: "middle",
      filter: {},
      showFilter: !1,
      expandedKeys: [],
      defaultExpandedRowKeys: [],
      expandedRowKeys: void 0,
      otherFilter: e.otherFilter
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {
      this.props.callBack(this.reload);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      e.url !== this.props.url && this.setState({
        localeUrl: e.url
      }, this.reload), e.otherFilter && e.otherFilter !== this.props.otherFilter && this.setState({
        otherFilter: e.otherFilter
      }, this.reload);
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.props, r = t.dataList, a = t.invokeFeDataFilter, l = t.vagueExtra, i = this.state, o = i.loading, n = i.selectedRowKeys, s = i.size, u = i.expandedKeys;
      dataToTree(r), _amosTool.Log.debug("SystemTable expandedKeys|dataList:", u, r);
      var p = r[0] ? [ r[0].key ] : [ "1" ], d = this.props, c = d.columns, f = d.isChecked, _ = d.operateCol, h = {
        selectedRowKeys: this.props.selectedRowKeys || n,
        onChange: this.onSelectChange
      };
      h = f ? h : void 0;
      return _ && (c[c.length - 1].render = function(t, r) {
        return e.addOperateCol(t, r);
      }), _react.default.createElement("div", {
        className: "amos-grid-table"
      }, _react.default.createElement("div", {
        className: "amos-grid-table-head"
      }, _react.default.createElement("div", {
        className: "amos-grid-table-filter-btns"
      }, this.getbtns(), _react.default.createElement(_VagueTextFilter.default, {
        filterSearchModel: c,
        changeFilters: this.changeFilters,
        invokeFeDataFilter: a,
        vagueExtra: l
      }))), _react.default.createElement("div", {
        className: "amos-tree-table-body"
      }, _react.default.createElement(_amosAntd.Table, {
        className: "amos-table tree-table",
        defaultExpandedRowKeys: p,
        onExpand: this.onExpand,
        pagination: !1,
        loading: o,
        rowSelection: h,
        columns: c,
        dataSource: r,
        size: s
      })), _react.default.createElement("div", null, _react.default.createElement("img", {
        src: "",
        alt: ""
      })));
    }
  } ]), r;
}(_react.Component);

SystemTableTree.displayName = "SystemTableTree", SystemTableTree.propTypes = {
  url: _propTypes.default.string,
  columns: _propTypes.default.array,
  getSelectedRows: _propTypes.default.func,
  operBtns: _propTypes.default.array,
  isChecked: _propTypes.default.bool,
  operateCol: _propTypes.default.func,
  dataList: _propTypes.default.array,
  invokeFeDataFilter: _propTypes.default.func,
  vagueExtra: _propTypes.default.any,
  selectedRowKeys: _propTypes.default.array,
  getTableDataAction: _propTypes.default.func,
  callBack: _propTypes.default.func,
  otherFilter: _propTypes.default.string
}, SystemTableTree.defaultProps = {
  operBtns: [],
  columns: [],
  dataList: [],
  isChecked: !0,
  otherFilter: ""
};

var _default = SystemTableTree;

exports.default = _default;