"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosTool = require("amos-tool"),
  _amosAntd = require("amos-antd"),
  _VagueTextFilter = _interopRequireDefault(require("./filter/VagueTextFilter"));

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

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

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 o = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, o ? (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
}
var dataToTree = function r(e) {
    var o = [];
    return (0 < arguments.length && void 0 !== e ? e : []).map(function(e) {
      var t = (e = e || {}).object || {};
      e.id = e.value, e.companyName = t.companyName, e.departmentName = t.departmentName, e.description = t.description, e.companyLevel = t.companyLevel, e.children && (e.children = r(e.children)), o.push(e)
    }), o
  },
  SystemTableTree = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var a;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(a = t.call(this, e)), "onSelectChange", function(e, t) {
        a.setState({
          selectedRowKeys: e,
          selectedRows: t
        }, a.props.getSelectedRows(t, e))
      }), _defineProperty(_assertThisInitialized(a), "getbtns", function() {
        var r = [];
        return a.props.operBtns.map(function(e, t) {
          r.push(_react.default.createElement("div", {
            key: "btn-".concat(t),
            className: "amos-grid-oper-btn"
          }, e))
        }), r
      }), _defineProperty(_assertThisInitialized(a), "changeFilters", function(e) {
        var r = e,
          o = {};
        Object.keys(r).map(function(e) {
          var t = r[e];
          t && "" !== t && (o[e] = t, "enabled" === e && (o[e] = "启用" === t))
        }), a.setState({
          filter: o
        }, a.reload), console.log("filter:res", a.state.filter)
      }), _defineProperty(_assertThisInitialized(a), "clone", function(e) {
        var t = Object.getPrototypeOf(e);
        return _extends(Object.create(t), e)
      }), _defineProperty(_assertThisInitialized(a), "openFilter", function() {
        var e = a.state.showFilter;
        a.setState({
          showFilter: !e
        })
      }), _defineProperty(_assertThisInitialized(a), "reload", function() {
        a.props.getTableDataAction(a.props.otherFilter)
      }), _defineProperty(_assertThisInitialized(a), "addOperateCol", function(e, t) {
        t = (0, a.props.operateCol)(e, t);
        return _react.default.createElement("div", {
          className: "operation-buttons"
        }, t)
      }), 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 _createClass(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 r = this,
          e = this.props,
          t = e.dataList,
          o = e.invokeFeDataFilter,
          a = e.vagueExtra,
          n = this.state,
          i = n.loading,
          l = n.selectedRowKeys,
          s = n.size,
          c = n.expandedKeys;
        dataToTree(t), _amosTool.Log.debug("SystemTable expandedKeys|dataList:", c, t);
        var u = t[0] ? [t[0].key] : ["1"],
          e = this.props,
          n = e.columns,
          c = e.isChecked,
          e = e.operateCol,
          l = {
            selectedRowKeys: this.props.selectedRowKeys || l,
            onChange: this.onSelectChange
          },
          l = c ? l : void 0;
        return e && (n[n.length - 1].render = function(e, t) {
          return r.addOperateCol(e, t)
        }), _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: n,
          changeFilters: this.changeFilters,
          invokeFeDataFilter: o,
          vagueExtra: a
        }))), _react.default.createElement("div", {
          className: "amos-tree-table-body"
        }, _react.default.createElement(_amosAntd.Table, {
          className: "amos-table tree-table",
          defaultExpandedRowKeys: u,
          onExpand: this.onExpand,
          pagination: !1,
          loading: i,
          rowSelection: l,
          columns: n,
          dataSource: t,
          size: s
        })), _react.default.createElement("div", null, _react.default.createElement("img", {
          src: "",
          alt: ""
        })))
      }
    }]), r
  }();
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 = SystemTableTree, module.exports = exports.default;
