file import { MyJQuery } from 'my-jquery/types/MyJQuery' ; import { Picker } from '../picker' ; import { IOptions } from '../API' ; import { IWheel } from '../IWheel' ; import util from '../util/util' ; import browserUtil from '../util/browserUtil' ; export abstract class AWheel implements IWheel { protected picker : Picker ; protected option : IOptions ; protected index : number ; protected dom : MyJQuery ; protected contains : MyJQuery ; protected selectedValue : any ; protected selectedIndex : number ; protected list = [ ] ; protected valueHashMap = { } ; protected labelKey : string ; protected itemValueKey : string ; param { number } offsetY protected abstract startDrag ( offsetY ) ; param { number } offsetY protected abstract drag ( offsetY ) ; /**
     * 拖拽结束
     */ protected abstract endDrag ( ) ; protected onSelectItemCallbackList : { ( index , value ) : void ; } [ ] = [ ] ; /**
    * 获得用户可选的标签
    */ getOptions ( ) { return this . list ; } /**
    * 给定指定标签的值,选择指定标签
    */ selectOption ( value , showAnimation = false ) { if ( this . valueHashMap [ value ] != null ) { var index = this . valueHashMap [ value ] ; this . selectIndex ( index , showAnimation ) ; } } /**
    * 获取被选值
    */ getValue ( ) { return this . selectedValue ; } param index param showAnimation protected abstract selectIndex ( index , showAnimation ? ) ; abstract setOptions ( list , defaultValue ) ; param { { ( index : number , value : any ) : void } } fn addSelectItemListener ( fn ) { this . onSelectItemCallbackList . push ( fn ) ; } param { { ( index : number , value : any ) : void } } fn removeSelectItemListener ( fn ) { this . onSelectItemCallbackList = this . onSelectItemCallbackList . filter ( _fn => _fn !== fn ) ; } getDOM ( ) { return this . dom ; } param index param value toggleSelected ( index , value ) { this . onSelectItemCallbackList . forEach ( fn => { fn . call ( this , index , value ) ; } ) ; } /**
     * 销毁
     */ destroy ( ) { this . onSelectItemCallbackList = null ; } protected initMouseWheel ( ) { this . getDOM ( ) . on ( 'wheel' , ( e ) => { let sign = Math . sign ( e . deltaY ) ; if ( sign > 0 && this . selectedIndex < this . list . length - 1 ) { this . selectIndex ( this . selectedIndex + 1 ) ; } else if ( sign < 0 && this . selectedIndex > 0 ) { this . selectIndex ( this . selectedIndex - 1 ) ; } } ) ; } }