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

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

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 _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
}
require("./style/amosGrid.scss");
var AmosGridTable = function() {
  _inherits(r, _react.Component);
  var t = _createSuper(r);

  function r(e) {
    var n;
    return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(n = t.call(this, e)), "onSelectChange", function(e, t) {
      n.setState({
        selectedRowKeys: e,
        selectedRows: t
      }, n.props.getSelectedRows(t, e))
    }), _defineProperty(_assertThisInitialized(n), "onSizeChange", function(e, t) {
      n.setState({
        current: e,
        pageSize: t
      }, n.reload)
    }), _defineProperty(_assertThisInitialized(n), "onPaginationChange", function(e) {
      n.setState({
        current: e
      }, n.reload)
    }), _defineProperty(_assertThisInitialized(n), "getbtns", function() {
      var r = [];
      return n.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(n), "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))
      }), n.setState({
        filter: o
      }, n.reload)
    }), _defineProperty(_assertThisInitialized(n), "openFilter", function() {
      var e = n.state.showFilter;
      n.setState({
        showFilter: !e
      })
    }), _defineProperty(_assertThisInitialized(n), "reload", function() {
      var e = n.state,
        t = e.current,
        r = e.pageSize,
        o = e.filter,
        e = e.otherFilter;
      n.props.getTableDataAction({
        current: t - 1,
        pageSize: r
      }, JSON.stringify(o), e)
    }), _defineProperty(_assertThisInitialized(n), "addOperateCol", function(e, t) {
      t = (0, n.props.operateCol)(e, t);
      return _react.default.createElement("div", {
        className: "operation-buttons"
      }, t)
    }), _defineProperty(_assertThisInitialized(n), "showTotal", function(e) {
      return "共 ".concat(e, " 条")
    }), _defineProperty(_assertThisInitialized(n), "generateRowkey", function(e, t) {
      return e.id || t + (n.state.current - 1) * n.state.pageSize
    }), n.state = {
      selectedRowKeys: [],
      selectedRows: [],
      loading: !1,
      dataList: [],
      size: "middle",
      current: 1,
      pageSize: 10,
      filter: {},
      totals: 1,
      showFilter: !1,
      otherFilter: e.otherFilter
    }, n
  }
  return _createClass(r, [{
    key: "componentDidMount",
    value: function() {
      this.props.callBack(this.reload)
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      e.url !== this.props.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.state,
        t = e.loading,
        o = e.selectedRowKeys,
        n = e.size,
        i = this.props,
        a = i.columns,
        s = i.isChecked,
        l = i.operateCol,
        u = i.isTreeTable,
        c = i.isPageable,
        p = i.pagination,
        e = i.dataList,
        i = i.totals,
        o = {
          selectedRowKeys: this.props.selectedRowKeys || o,
          onChange: this.onSelectChange
        },
        o = s ? o : void 0;
      l && (a[a.length - 1].render = function(e, t) {
        return r.addOperateCol(e, t)
      });
      i = !1 !== p && (p || {
        size: "small",
        total: i,
        current: this.state.current,
        pageSize: this.state.pageSize,
        onShowSizeChange: this.onSizeChange,
        onChange: this.onPaginationChange,
        showSizeChanger: !0,
        showTotal: this.showTotal
      }), i = !1 !== c && i;
      return _amosTool.Log.info("the table has pagination", !!i), _react.default.createElement("div", null, _react.default.createElement("div", null, _react.default.createElement("div", null, this.getbtns())), _react.default.createElement("div", {
        style: {
          marginTop: "10px"
        }
      }, _react.default.createElement(_amosAntd.Table, {
        rowKey: u ? "key" : this.generateRowkey,
        loading: t,
        rowSelection: o,
        columns: a,
        dataSource: e,
        pagination: i,
        size: n,
        bordered: !0,
        scroll: {
          y: 450
        }
      })))
    }
  }]), r
}();
AmosGridTable.displayName = "AmosGridTable", AmosGridTable.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,
  callBack: _propTypes.default.func,
  otherFilter: _propTypes.default.string,
  dataList: _propTypes.default.array,
  getTableDataAction: _propTypes.default.func,
  selectedRowKeys: _propTypes.default.array,
  totals: _propTypes.default.number,
  pagination: _propTypes.default.any,
  isPageable: _propTypes.default.bool,
  isTreeTable: _propTypes.default.bool
}, AmosGridTable.defaultProps = {
  operBtns: [],
  dataList: [],
  totals: 1,
  columns: [],
  isChecked: !0,
  isTreeTable: !1,
  otherFilter: ""
};
var _default = AmosGridTable;
exports.default = AmosGridTable, module.exports = exports.default;
