2017-09-25 15:36:23 +08:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2017-11-08 15:54:23 +08:00
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 ; } ;
2017-09-25 15:36:23 +08:00
var _react = require ( "react" ) ;
var _react2 = _interopRequireDefault ( _react ) ;
var _beeIcon = require ( "bee-icon" ) ;
var _beeIcon2 = _interopRequireDefault ( _beeIcon ) ;
var _beeFormControl = require ( "bee-form-control" ) ;
var _beeFormControl2 = _interopRequireDefault ( _beeFormControl ) ;
2017-11-02 14:01:03 +08:00
var _beeForm = require ( "bee-form" ) ;
var _beeForm2 = _interopRequireDefault ( _beeForm ) ;
var _beeTooltip = require ( "bee-tooltip" ) ;
var _beeTooltip2 = _interopRequireDefault ( _beeTooltip ) ;
var _propTypes = require ( "prop-types" ) ;
var _propTypes2 = _interopRequireDefault ( _propTypes ) ;
2017-09-25 15:36:23 +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 ; }
2017-11-08 15:54:23 +08:00
function _objectWithoutProperties ( obj , keys ) { var target = { } ; for ( var i in obj ) { if ( keys . indexOf ( i ) >= 0 ) continue ; if ( ! Object . prototype . hasOwnProperty . call ( obj , i ) ) continue ; target [ i ] = obj [ i ] ; } return target ; }
2017-09-25 15:36:23 +08:00
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 ) ; }
2017-11-02 14:01:03 +08:00
var propTypes = {
check : _propTypes2 [ "default" ] . func
} ;
var defaultProps = {
check : function check ( ) {
return "" ;
}
} ;
2017-09-25 15:36:23 +08:00
var InputRender = function ( _Component ) {
_inherits ( InputRender , _Component ) ;
function InputRender ( ) {
var _temp , _this , _ret ;
_classCallCheck ( this , InputRender ) ;
for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
args [ _key ] = arguments [ _key ] ;
}
return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , _Component . call . apply ( _Component , [ this ] . concat ( args ) ) ) , _this ) , _this . state = {
value : _this . props . value ,
editable : false
} , _this . handleChange = function ( e ) {
2017-10-12 16:54:17 +08:00
var value = e ;
2017-09-25 15:36:23 +08:00
_this . setState ( { value : value } ) ;
} , _this . check = function ( ) {
2017-11-02 14:01:03 +08:00
if ( typeof _this . flag === "undefined" || _this . flag ) {
_this . props . check ( _this . flag , _this . obj ) ;
_this . setState ( { editable : false } ) ;
if ( _this . props . onChange ) {
_this . props . onChange ( _this . state . value ) ;
}
_this . flag = undefined ;
2017-09-25 15:36:23 +08:00
}
2017-11-02 14:01:03 +08:00
} , _this . checkValidate = function ( flag , obj ) {
_this . flag = flag ;
_this . obj = obj ;
2017-09-25 15:36:23 +08:00
} , _this . edit = function ( ) {
_this . setState ( { editable : true } ) ;
} , _this . handleKeydown = function ( event ) {
if ( event . keyCode == 13 ) {
_this . check ( ) ;
}
2017-10-25 16:41:38 +08:00
} , _this . formatCurrency = function ( money ) {
if ( money && money != null && ! ! Number ( money ) ) {
money = String ( money ) ;
var left = money . split ( "." ) [ 0 ] ,
right = money . split ( "." ) [ 1 ] ;
right = right ? right . length >= 2 ? "." + right . substr ( 0 , 2 ) : "." + right + "0" : ".00" ;
var temp = left . split ( "" ) . reverse ( ) . join ( "" ) . match ( /(\d{1,3})/g ) ;
return ( Number ( money ) < 0 ? "-" : "" ) + temp . join ( "," ) . split ( "" ) . reverse ( ) . join ( "" ) + right ;
} else if ( money === 0 ) {
//注意===在这里的使用, 如果传入的money为0,if中会将其判定为boolean类型, 故而要另外做===判断
return "0.00" ;
} else {
return "" ;
}
2017-09-25 15:36:23 +08:00
} , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
}
2017-10-25 16:41:38 +08:00
//货币的格式化方法
2017-09-25 15:36:23 +08:00
InputRender . prototype . render = function render ( ) {
var _state = this . state ,
value = _state . value ,
editable = _state . editable ;
2017-11-08 15:54:23 +08:00
2017-10-25 16:41:38 +08:00
var _props = this . props ,
2017-11-02 14:01:03 +08:00
name = _props . name ,
placeholder = _props . placeholder ,
2017-10-25 16:41:38 +08:00
isclickTrigger = _props . isclickTrigger ,
2017-11-02 14:01:03 +08:00
format = _props . format ,
formItemClassName = _props . formItemClassName ,
mesClassName = _props . mesClassName ,
check = _props . check ,
2017-11-08 15:54:23 +08:00
other = _objectWithoutProperties ( _props , [ "name" , "placeholder" , "isclickTrigger" , "format" , "formItemClassName" , "mesClassName" , "check" ] ) ;
2017-09-25 15:36:23 +08:00
var cellContent = "" ;
if ( editable ) {
cellContent = isclickTrigger ? _react2 [ "default" ] . createElement (
"div" ,
{ className : "editable-cell-input-wrapper" } ,
2017-11-02 14:01:03 +08:00
_react2 [ "default" ] . createElement (
_beeForm2 [ "default" ] . FormItem ,
2017-11-08 15:54:23 +08:00
_extends ( {
2017-11-02 14:01:03 +08:00
className : "formItem-style " + formItemClassName ,
mesClassName : "errMessage-style " + mesClassName ,
change : this . handleChange ,
blur : this . check ,
check : this . checkValidate
2017-11-08 15:54:23 +08:00
} , other ) ,
2017-11-02 14:01:03 +08:00
_react2 [ "default" ] . createElement ( _beeFormControl2 [ "default" ] , {
name : name ,
placeholder : placeholder ,
onKeyDown : this . handleKeydown ,
autoFocus : true ,
value : value
} )
)
2017-09-25 15:36:23 +08:00
) : _react2 [ "default" ] . createElement (
"div" ,
{ className : "editable-cell-input-wrapper" } ,
2017-11-02 14:01:03 +08:00
_react2 [ "default" ] . createElement (
_beeForm2 [ "default" ] . FormItem ,
2017-11-08 15:54:23 +08:00
_extends ( {
2017-11-02 14:01:03 +08:00
className : "formItem-style " + formItemClassName ,
mesClassName : "errMessage-style " + mesClassName ,
change : this . handleChange ,
blur : this . check ,
check : this . checkValidate
2017-11-08 15:54:23 +08:00
} , other ) ,
2017-11-02 14:01:03 +08:00
_react2 [ "default" ] . createElement ( _beeFormControl2 [ "default" ] , {
name : name ,
placeholder : placeholder ,
onKeyDown : this . handleKeydown ,
autoFocus : true ,
value : value
} )
) ,
2017-09-25 15:36:23 +08:00
_react2 [ "default" ] . createElement ( _beeIcon2 [ "default" ] , {
type : "uf-correct" ,
className : "editable-cell-icon-check" ,
onClick : this . check
} )
) ;
} else {
2017-10-25 16:41:38 +08:00
if ( format && format === "Currency" ) {
value = this . formatCurrency ( value ) ;
}
2017-09-25 15:36:23 +08:00
cellContent = isclickTrigger ? _react2 [ "default" ] . createElement (
"div" ,
{ className : "editable-cell-text-wrapper" , onClick : this . edit } ,
value || " "
) : _react2 [ "default" ] . createElement (
"div" ,
{ className : "editable-cell-text-wrapper" } ,
value || " " ,
_react2 [ "default" ] . createElement ( _beeIcon2 [ "default" ] , {
type : "uf-pencil" ,
className : "editable-cell-icon" ,
onClick : this . edit
} )
) ;
}
return _react2 [ "default" ] . createElement (
"div" ,
{ className : "editable-cell" } ,
cellContent
) ;
} ;
return InputRender ;
} ( _react . Component ) ;
exports [ "default" ] = InputRender ;
2017-11-02 14:01:03 +08:00
InputRender . PropTypes = propTypes ;
InputRender . defaultProps = defaultProps ;
2017-09-25 15:36:23 +08:00
module . exports = exports [ "default" ] ;