import { IOptions , StringCol , IPicker } from './API' ; import { Col } from './Col' ; import defaultOption from './defaultOption' ; import { Wheel3D } from './wheel/Wheel3D' ; import { Wheel } from './wheel/Wheel' ; import { IWheel } from './IWheel' ; import browserUtil from './util/browserUtil' ; import util from './util/util' ; declare function require ( name ) ; var Frame = require ( "./frame" ) ; export class Picker implements IPicker { private _option : IOptions ; private _wheels : IWheel [ ] = [ ] ; private _frame : any ; private _cols : Col [ ] = [ ] ; get visible ( ) : boolean { return this . _visible ; } private _visible : boolean ; constructor ( options ) { this . _option = util . assign ( { } , defaultOption , options ) as IOptions < any > ; this . _frame = new Frame ( this , this . _option ) ; var cols = [ ] , i = 0 ; if ( Array . isArray ( this . _option . cols ) ) { if ( this . _option . cols . length === 0 || typeof this . _option . cols [ 0 ] === 'string' ) { cols . push ( new Col ( this . _option . cols as string [ ] ) ) ; } else { for ( i = 0 ; i < this . _option . cols . length ; i ++ ) { cols . push ( new Col ( this . _option . cols [ i ] as StringCol ) ) ; } } } else { cols . push ( new Col ( this . _option . cols ) ) ; } this . _cols = cols ; this . _wheels = [ ] ; var wheel , col ; for ( let i = 0 ; i < cols . length ; i ++ ) { let col = cols [ i ] ; wheel = ( ! browserUtil . isIE ( ) && ! ( browserUtil . isAndroid ( ) && browserUtil . androidVersion ( ) < 4.4 ) && this . _option . isPerspective ) ? new Wheel3D ( this , col , this . _option , i ) : new Wheel ( this , col , this . _option , i ) ; this . _wheels . push ( wheel ) ; this . _frame . body ( ) . append ( wheel . getDOM ( ) ) ; var that = this ; wheel . addSelectItemListener ( ( function ( i ) { return function ( index , value ) { if ( typeof that . _option . onSelectItem == 'function' ) { that . _option . onSelectItem . call ( that , i , index , value ) ; } } ; } ) ( i ) ) ; } for ( let i = 0 ; i < cols . length ; i ++ ) { that . setValue ( i , that . _option . setValues [ i ] ) ; } this . _visible = false ; } /**
     * 显示
     */ show ( ) { this . _frame . showCover ( ) ; this . _frame . showFrame ( ) ; this . _visible = true ; } /**
     * 隐藏
     */ hide ( ) { this . _frame . hideCover ( ) ; this . _frame . hideFrame ( ) ; this . _visible = false ; } /**
     * 关闭
     */ close ( ) { this . _frame . close ( ) ; this . _frame . hideCover ( ) ; this . _option = null ; this . _wheels . forEach ( wheel => wheel . destroy ( ) ) ; this . _wheels = null ; this . _frame = null ; this . _cols = null ; } param { number } index param { any [ ] } list param { * } defaultValue setOptions ( index , list , defaultValue ) { if ( this . _wheels [ index ] ) this . _wheels [ index ] . setOptions ( list , defaultValue ) ; } param { number } index getOptions ( index ) { if ( this . _wheels [ index ] ) { return this . _wheels [ index ] . getOptions ( ) ; } else { return null ; } } param { number } index param { * } value setValue ( index , value ) { if ( this . _wheels [ index ] ) this . _wheels [ index ] . selectOption ( value ) ; } param { number } index getValue ( index ) { if ( index != null ) { if ( this . _wheels [ index ] ) return this . _wheels [ index ] . getValue ( ) ; } else { var values = [ ] ; var i ; for ( i = 0 ; i < this . _cols . length ; i ++ ) { values . push ( this . _wheels [ i ] . getValue ( ) ) ; } return values ; } } }