import { Component , OnInit , ViewEncapsulation } from '@angular/core' ; import { NzCascaderOption } from 'ng-zorro-antd/cascader' ; import type { NzSafeAny } from 'ng-zorro-antd/core/types' ; import { SFValue } from '../../interface' ; import { SFSchemaEnum } from '../../schema' ; import { getData , toBool } from '../../utils' ; import { ControlUIWidget } from '../../widget' ; import { SFCascaderWidgetSchema } from './schema' ; @ Component ( { selector : 'sf-cascader' , templateUrl : './cascader.widget.html' , preserveWhitespaces : false , encapsulation : ViewEncapsulation . None } ) export class CascaderWidget extends ControlUIWidget < SFCascaderWidgetSchema > implements OnInit { clearText ! : string ; showArrow ! : boolean ; showInput ! : boolean ; triggerAction ! : string [ ] ; data : SFSchemaEnum [ ] = [ ] ; loadData ? : ( node : NzCascaderOption , index : number ) => PromiseLike < NzSafeAny > ; ngOnInit ( ) { const { clearText , showArrow , showInput , triggerAction , asyncData } = this . ui ; this . clearText = clearText || '清除' ; this . showArrow = toBool ( showArrow , true ) ; this . showInput = toBool ( showInput , true ) ; this . triggerAction = triggerAction || [ 'click' ] ; if ( ! ! asyncData ) { this . loadData = ( node , index ) => asyncData ( node , index , this ) . then ( ( ) => this . detectChanges ( ) ) ; } } reset ( value ) { getData ( this . schema , { } , value ) . subscribe ( list => { this . data = list ; this . detectChanges ( ) ; } ) ; } _visibleChange ( status ) { if ( this . ui . visibleChange ) this . ui . visibleChange ( status ) ; } _change ( value ) { this . setValue ( value ) ; if ( this . ui . change ) { this . ui . change ( value ) ; } } _selectionChange ( options ) { if ( this . ui . selectionChange ) { this . ui . selectionChange ( options ) ; } } _clear ( ) { if ( this . ui . clear ) this . ui . clear ( ) ; } }