2018-05-11 09:29:43 +08:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
exports [ "default" ] = filterColumn ;
var _react = require ( "react" ) ;
var _react2 = _interopRequireDefault ( _react ) ;
2018-06-25 00:44:05 +08:00
var _beeCheckbox = require ( "bee-checkbox" ) ;
var _beeCheckbox2 = _interopRequireDefault ( _beeCheckbox ) ;
var _beeIcon = require ( "bee-icon" ) ;
var _beeIcon2 = _interopRequireDefault ( _beeIcon ) ;
2018-09-06 19:31:10 +08:00
var _util = require ( "./util" ) ;
2018-07-05 11:01:19 +08:00
2019-01-10 16:07:41 +08:00
var _i18n = require ( "./i18n" ) ;
2018-11-01 14:35:46 +08:00
var _i18n2 = _interopRequireDefault ( _i18n ) ;
var _tool = require ( "bee-locale/build/tool" ) ;
2019-02-25 16:44:05 +08:00
var _propTypes = require ( "prop-types" ) ;
var _propTypes2 = _interopRequireDefault ( _propTypes ) ;
2018-05-11 09:29:43 +08:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { "default" : obj } ; }
function _defaults ( obj , defaults ) { var keys = Object . getOwnPropertyNames ( defaults ) ; for ( var i = 0 ; i < keys . length ; i ++ ) { var key = keys [ i ] ; var value = Object . getOwnPropertyDescriptor ( defaults , key ) ; if ( value && value . configurable && obj [ key ] === undefined ) { Object . defineProperty ( obj , key , value ) ; } } return obj ; }
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : _defaults ( subClass , superClass ) ; }
2018-09-04 10:16:53 +08:00
function noop ( ) { }
2018-05-11 09:29:43 +08:00
/ * *
* 参数 : 过滤表头
* @ param { * } Table
2018-05-22 19:38:15 +08:00
* @ param { * } Popover
* @ param { * } Icon
2018-05-11 09:29:43 +08:00
* /
2018-06-25 00:44:05 +08:00
function filterColumn ( Table , Popover ) {
2018-05-11 09:29:43 +08:00
var _class , _temp , _initialiseProps ;
return _temp = _class = function ( _Component ) {
2018-05-22 19:38:15 +08:00
_inherits ( FilterColumn , _Component ) ;
2018-05-11 09:29:43 +08:00
2018-05-22 19:38:15 +08:00
function FilterColumn ( props ) {
_classCallCheck ( this , FilterColumn ) ;
2018-05-11 09:29:43 +08:00
var _this = _possibleConstructorReturn ( this , _Component . call ( this , props ) ) ;
_initialiseProps . call ( _this ) ;
var columns = props . columns ;
_this . state = {
2018-09-06 19:31:10 +08:00
columns : _this . setColumOrderByIndex ( ( 0 , _util . ObjectAssign ) ( columns ) ) ,
2018-05-11 09:29:43 +08:00
showModal : false ,
screenY : 0
} ;
return _this ;
}
2018-06-25 00:44:05 +08:00
FilterColumn . prototype . componentWillReceiveProps = function componentWillReceiveProps ( nextProps ) {
2018-07-05 11:01:19 +08:00
if ( nextProps . columns != this . props . columns ) {
this . setState ( {
2018-09-06 19:31:10 +08:00
columns : this . setColumOrderByIndex ( ( 0 , _util . ObjectAssign ) ( nextProps . columns ) )
2018-07-05 11:01:19 +08:00
} ) ;
}
2018-06-25 00:44:05 +08:00
this . setState ( {
2018-09-04 10:16:53 +08:00
showModal : nextProps . showFilterPopover ? true : false
2018-06-25 00:44:05 +08:00
} ) ;
} ;
2018-05-22 19:38:15 +08:00
FilterColumn . prototype . render = function render ( ) {
2018-05-14 11:27:16 +08:00
var _props = this . props ,
data = _props . data ,
2018-07-05 11:01:19 +08:00
prefixCls = _props . prefixCls ,
scrollPro = _props . scroll ;
2018-05-11 09:29:43 +08:00
var _state = this . state ,
columns = _state . columns ,
2018-06-25 00:44:05 +08:00
showModal = _state . showModal ;
2018-05-11 09:29:43 +08:00
2018-07-05 11:01:19 +08:00
2019-02-25 15:42:15 +08:00
var locale = ( 0 , _tool . getComponentLocale ) ( this . props , this . context , 'Table' , function ( ) {
2018-11-01 14:35:46 +08:00
return _i18n2 [ "default" ] ;
} ) ;
2018-07-05 11:01:19 +08:00
var _columns = [ ] ,
widthState = 0 ,
scroll = scrollPro ;
2018-05-11 09:29:43 +08:00
columns . forEach ( function ( da ) {
2018-09-04 10:16:53 +08:00
if ( da . ifshow ) {
2018-05-11 09:29:43 +08:00
_columns . push ( da ) ;
2018-07-16 17:14:15 +08:00
if ( da . width ) {
widthState ++ ;
}
2018-07-05 11:01:19 +08:00
}
2018-05-11 09:29:43 +08:00
} ) ;
2018-10-11 15:56:06 +08:00
// if(_columns.length == widthState){
// scroll.x = this.getCloumnsScroll(columns);
// }
2018-05-11 09:29:43 +08:00
var content = _react2 [ "default" ] . createElement (
"div" ,
2018-05-14 11:27:16 +08:00
{ className : prefixCls + "-pop-cont" } ,
2018-05-11 09:29:43 +08:00
_react2 [ "default" ] . createElement (
"span" ,
2018-05-14 11:27:16 +08:00
{ className : prefixCls + "-clear-setting" , onClick : this . clear } ,
2018-11-29 11:44:56 +08:00
locale [ "resetSettings" ]
2018-05-11 09:29:43 +08:00
) ,
_react2 [ "default" ] . createElement (
"div" ,
null ,
this . getCloumItem ( )
)
) ;
return _react2 [ "default" ] . createElement (
"div" ,
2018-05-14 11:27:16 +08:00
{ className : prefixCls + "-cont" } ,
2018-11-29 11:44:56 +08:00
_react2 [ "default" ] . createElement ( Table , _extends ( { } , this . props , {
columns : _columns ,
data : data
2018-10-11 15:56:06 +08:00
// scroll={scroll}
2018-07-05 11:01:19 +08:00
// scroll={{x:this.getCloumnsScroll(columns)}}
} ) ) ,
2018-11-29 11:44:56 +08:00
this . props . columnFilterAble == false ? "" : _react2 [ "default" ] . createElement (
2018-06-25 00:44:05 +08:00
"div" ,
{ className : prefixCls + "-filter-icon" } ,
2018-05-11 09:29:43 +08:00
_react2 [ "default" ] . createElement (
2018-06-25 00:44:05 +08:00
Popover ,
{
id : "filter_column_popover" ,
2018-10-11 15:04:31 +08:00
placement : "left" ,
2018-06-25 00:44:05 +08:00
content : content ,
2019-07-06 10:59:19 +08:00
show : showModal ,
onHide : this . onHide
2018-11-29 11:44:56 +08:00
} ,
2018-06-25 00:44:05 +08:00
_react2 [ "default" ] . createElement (
"div" ,
2018-06-25 09:11:12 +08:00
{ className : prefixCls + "-pop-column-filter-cont" } ,
2018-09-27 15:24:29 +08:00
_react2 [ "default" ] . createElement ( _beeIcon2 [ "default" ] , { type : "uf-grid" , onClick : this . openCloumList } )
2018-06-25 00:44:05 +08:00
)
2018-05-11 09:29:43 +08:00
)
)
) ;
} ;
2018-05-22 19:38:15 +08:00
return FilterColumn ;
2018-05-14 11:27:16 +08:00
} ( _react . Component ) , _class . defaultProps = {
2018-09-04 10:16:53 +08:00
prefixCls : "u-table-filter-column" ,
afterFilter : noop ,
2018-11-29 11:44:56 +08:00
columnFilterAble : true ,
2018-09-04 10:16:53 +08:00
scroll : { }
2019-02-25 15:42:15 +08:00
} , _class . contextTypes = {
2019-02-25 16:44:05 +08:00
beeLocale : _propTypes2 [ "default" ] . object
2018-05-14 11:27:16 +08:00
} , _initialiseProps = function _initialiseProps ( ) {
2018-05-11 09:29:43 +08:00
var _this2 = this ;
2018-07-06 14:33:29 +08:00
this . setColumOrderByIndex = function ( _column ) {
_column . forEach ( function ( da ) {
2018-09-04 10:16:53 +08:00
//默认所有的列都显示, 如果传递ifshow属性, 根据ifshow属性值来判断是否显示某列
2018-11-29 11:44:56 +08:00
if ( da . hasOwnProperty ( "ifshow" ) ) {
2018-09-04 10:16:53 +08:00
da . checked = da . ifshow ? true : false ;
da . ifshow = da . checked ;
} else {
da . checked = true ;
da . ifshow = true ;
}
2018-07-06 14:33:29 +08:00
} ) ;
return _column ;
} ;
2018-05-11 09:29:43 +08:00
this . checkedColumItemClick = function ( da ) {
2018-09-04 10:16:53 +08:00
var _props2 = _this2 . props ,
checkMinSize = _props2 . checkMinSize ,
afterFilter = _props2 . afterFilter ;
2018-07-05 11:01:19 +08:00
// if(checkMinSize)
2018-07-06 14:33:29 +08:00
2018-07-05 11:01:19 +08:00
var sum = 0 ,
leng = 0 ;
_this2 . state . columns . forEach ( function ( da ) {
da . fixed ? "" : leng ++ ;
! da . fixed && da . checked ? sum ++ : "" ;
} ) ;
2018-07-06 14:33:29 +08:00
if ( sum < checkMinSize && da . checked ) {
2018-07-05 11:01:19 +08:00
return ;
} else {
2018-07-06 14:33:29 +08:00
if ( sum <= 1 && da . checked ) return ;
2018-07-05 11:01:19 +08:00
}
2018-07-06 14:33:29 +08:00
da . checked = da . checked ? false : true ;
2018-09-04 10:16:53 +08:00
da . ifshow = da . checked ? true : false ;
2018-05-11 09:29:43 +08:00
_this2 . setState ( _extends ( { } , _this2 . state ) ) ;
2018-09-04 10:16:53 +08:00
afterFilter ( da , _this2 . state . columns ) ;
2018-05-11 09:29:43 +08:00
} ;
2018-07-04 15:55:48 +08:00
this . openCloumList = function ( ) {
2018-05-11 09:29:43 +08:00
_this2 . setState ( {
showModal : true
} ) ;
} ;
2019-07-06 10:59:19 +08:00
this . onHide = function ( ) {
_this2 . setState ( {
showModal : false
} ) ;
} ;
2018-05-11 09:29:43 +08:00
this . getCloumItem = function ( ) {
2018-05-14 11:27:16 +08:00
var prefixCls = _this2 . props . prefixCls ;
2018-05-11 09:29:43 +08:00
var columns = _this2 . state . columns ;
return columns . map ( function ( da , i ) {
2018-11-29 17:12:28 +08:00
var paramObj = {
id : da . key ,
checked : da . checked
} ;
2019-11-25 17:58:02 +08:00
if ( da . fixed || da . required ) {
2018-11-29 17:12:28 +08:00
paramObj . disabled = true ;
} else {
paramObj . onClick = function ( ) {
_this2 . checkedColumItemClick ( da ) ;
} ;
}
2018-11-29 11:44:56 +08:00
return _react2 [ "default" ] . createElement (
"div" ,
{
key : da . key + "_" + i ,
2019-04-25 14:19:48 +08:00
className : prefixCls + "-pop-cont-item" ,
onClick : paramObj . onClick ? paramObj . onClick : null
2018-11-29 11:44:56 +08:00
} ,
_react2 [ "default" ] . createElement (
2019-04-23 18:47:27 +08:00
_beeCheckbox2 [ "default" ] ,
paramObj ,
2019-04-25 10:03:41 +08:00
da . title
2018-11-29 11:44:56 +08:00
)
) ;
2018-05-11 09:29:43 +08:00
} ) ;
} ;
this . clear = function ( ) {
var columns = _this2 . state . columns ;
columns . forEach ( function ( da ) {
da . checked = true ;
2018-09-04 10:16:53 +08:00
da . ifshow = true ;
2018-05-11 09:29:43 +08:00
} ) ;
2018-11-06 13:49:43 +08:00
_this2 . setState ( {
columns : columns
} ) ;
_this2 . props . afterFilter ( _this2 . state . columns , _this2 . state . columns ) ;
2018-05-11 09:29:43 +08:00
} ;
2018-07-05 11:01:19 +08:00
this . getCloumnsScroll = function ( columns ) {
var sum = 0 ;
columns . forEach ( function ( da ) {
if ( da . checked ) {
sum += da . width ;
}
} ) ;
2018-09-04 10:16:53 +08:00
// console.log("sum",sum);
2018-07-05 11:01:19 +08:00
return sum ;
} ;
2018-05-11 09:29:43 +08:00
} , _temp ;
}
module . exports = exports [ "default" ] ;