import { OrganizationUnitDto } from '@shared/service-proxies/service-proxies' ; import { Component , Injector } from '@angular/core' ; import { NzTreeNode } from 'ng-zorro-antd/tree' ; import { filter as _filter , map as _map } from 'lodash-es' ; import { AppComponentBase } from '@shared/common/app-component-base' ; import { ArrayService } from '@delon/util' ; export interface IOrganizationUnitsTreeComponentData { allOrganizationUnits : OrganizationUnitDto [ ] ; selectedOrganizationUnits : string [ ] ; } @ Component ( { selector : 'organization-unit-tree' , templateUrl : './organization-unit-tree.component.html' , } ) export class OrganizationUnitsTreeComponent extends AppComponentBase { private _allOrganizationUnits : OrganizationUnitDto [ ] = [ ] ; defaultCheckedOrganizationUnits : number [ ] = [ ] ; checkStrictly = true ; loading = false ; set data ( data ) { this . _allOrganizationUnits = data . allOrganizationUnits ; this . ouCodeArrToIdArr ( data . selectedOrganizationUnits ) ; this . arrToTreeNode ( ) ; } filterText : string ; _treeData : NzTreeNode [ ] = [ ] ; constructor ( injector , private _arrayService ) { super ( injector ) ; } arrToTreeNode ( ) { this . loading = true ; this . _treeData = this . _arrayService . arrToTreeNode ( this . _allOrganizationUnits , { idMapName : 'id' , parentIdMapName : 'parentId' , titleMapName : 'displayName' , cb : ( item ) => { item . expanded = true ; } } ) ; setTimeout ( ( ) => { this . loading = false ; } , 500 ) ; } reload ( ) { this . arrToTreeNode ( ) ; this . filterText = '' ; } getSelectedOrganizations ( ) { const organizationIds = this . _arrayService . getKeysByTreeNode ( this . _treeData ) ; return organizationIds ; } ouCodeArrToIdArr ( codes ) { const filterOUs = _filter ( this . _allOrganizationUnits , ( u ) => { return codes . indexOf ( u . code ) >= 0 ; } ) ; const ids = _map ( filterOUs , f => f . id ) ; this . defaultCheckedOrganizationUnits = ids ; } filterTextEmptyChange ( ) { if ( ! this . filterText ) { this . reload ( ) ; } } }