import { Component , OnInit , ViewChild , ElementRef } from '@angular/core' ;
import { HttpClient } from '@angular/common/http' ;
import { TreeService } from 'src/app/service/tree.service' ;
import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
import { NzContextMenuService , NzDropdownMenuComponent } from 'ng-zorro-antd/dropdown' ;
import { NzFormatEmitEvent , NzTreeComponent , NzTreeNode } from 'ng-zorro-antd/tree' ;
import { Router } from '@angular/router' ;
import { NavChangeService } from 'src/app/service/navChange.service' ;
import { fromEvent } from 'rxjs' ;
import { debounceTime } from 'rxjs/operators' ;
@Component ( {
selector : 'app-oil-station-list' ,
templateUrl : './oil-station-list.component.html' ,
styleUrls : [ './oil-station-list.component.scss' ]
} )
export class OilStationListComponent implements OnInit {
validateForm ! : FormGroup ;
constructor ( private element : ElementRef , private navChangeService : NavChangeService , private http : HttpClient , private toTree : TreeService , private fb : FormBuilder , private nzContextMenuService : NzContextMenuService , private router : Router ) { }
tableScrollHeight
resizeListener
ngOnInit ( ) : void {
this . tableScrollHeight = ( document . getElementById ( 'tablebox' ) . clientHeight - 42 ) + 'px'
console . log ( 'tableScrollHeight' , this . tableScrollHeight )
// 页面监听
this . resizeListener = fromEvent ( window , 'resize' ) . pipe ( debounceTime ( 100 ) ) . subscribe ( ( event ) = > {
this . tableScrollHeight = ( document . getElementById ( 'tablebox' ) . clientHeight - 42 ) + 'px'
} ) ;
this . validateForm = this . fb . group ( {
name : [ null ]
} ) ;
this . tableSpin = true
}
ngOnDestroy ( ) : void {
this . resizeListener . unsubscribe ( )
}
ngAfterViewInit ( ) : void {
fromEvent ( this . element . nativeElement . querySelector ( ` .ant-table-body ` ) as HTMLCanvasElement , 'scroll' ) . pipe ( debounceTime ( 100 ) ) . subscribe ( async ( event : any ) = > { //监听 DOM 滚动事件
if ( event . target . scrollHeight - ( event . target . scrollTop + event . target . clientHeight ) <= 10 ) {
if ( this . totalCount > this . list . length ) {
console . log ( '需要加载数据了' , event )
this . SkipCount = String ( Number ( this . SkipCount ) + 50 )
await this . getGasStation ( )
}
}
} ) ;
}
submitForm ( ) : void {
for ( const i in this . validateForm . controls ) {
this . validateForm . controls [ i ] . markAsDirty ( ) ;
this . validateForm . controls [ i ] . updateValueAndValidity ( ) ;
}
this . list = [ ]
this . SkipCount = '0'
this . getGasStation ( )
}
resetForm ( e : MouseEvent ) : void {
e . preventDefault ( ) ;
this . validateForm . reset ( ) ;
for ( const key in this . validateForm . controls ) {
this . validateForm . controls [ key ] . markAsPristine ( ) ;
this . validateForm . controls [ key ] . updateValueAndValidity ( ) ;
}
this . list = [ ]
this . SkipCount = '0'
this . getGasStation ( )
}
look ( item ) {
let gastionobj = {
organization : {
displayName : item.stationName ,
isGasStation : true ,
id : item.organizationUnitId
}
}
sessionStorage . setItem ( 'userdataOfgasstation' , JSON . stringify ( gastionobj ) )
this . router . navigate ( [ '/todaywarning/petrolStation' ] )
let obj = {
name : 'oilstation'
}
this . navChangeService . sendMessage ( obj ) ; //发布一条消息
}
tableSpin : boolean
totalCount : any //总数
//获取点击组织机构的所有加油站
SkipCount : string = '0'
MaxResultCount : string = '100'
orId
list : any = [ ]
async getGasStation() {
let params = {
StationName : this.validateForm.value.name ,
OrganizationUnitId : String ( sessionStorage . getItem ( 'planAdminOrid' ) ) ,
IsContainsChildren : 'true' ,
SkipCount : this.SkipCount ,
MaxResultCount : this.MaxResultCount ,
Sorting : ' BuildingBasicInfo.Id asc'
}
this . tableSpin = true
await new Promise ( ( resolve , reject ) = > {
this . http . get ( '/api/services/app/GasStation/GetAll' , {
params : params
} ) . subscribe ( ( data : any ) = > {
this . totalCount = data . result . totalCount
this . list = this . list . concat ( data . result . items ) ;
this . list = [ . . . this . list ]
this . tableSpin = false
resolve ( data )
} )
} )
}
//父组件调用子组件方法
public onChildMethod() {
this . getGasStation ( )
}
}