import { HttpClient } from '@angular/common/http'; import { Component, OnInit, Inject } from '@angular/core'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; @Component({ selector: 'app-add-six-familiar', templateUrl: './add-six-familiar.component.html', styleUrls: ['./add-six-familiar.component.scss'] }) export class AddSixFamiliarComponent implements OnInit { constructor(private http:HttpClient,public dialog: MatDialog,public snackBar: MatSnackBar) { } title:String = "新增六熟悉记录" unitname:any address:any contactname:any contactphone:any peoplenum:any leadname:any ngOnInit(): void { } //选择单位 openUnitList(){ let dialogRef = this.dialog.open(SelectUnit); dialogRef.afterClosed().subscribe(data=>{ if(data){ this.unitname = data.name this.address = data.address this.contactname = data.contacts this.contactphone = data.phone } }); } //确定 ok(){ console.log(this.unitname) if(this.unitname && this.address && this.contactname && this.contactphone && this.peoplenum && this.leadname){ }else{ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('存在未填项','确定',config) } } //取消 cancel(){ } } //选择单位 @Component({ selector: 'app-editBuilding', templateUrl: './Select-unit-list.html', styleUrls: ['./add-six-familiar.component.scss'] }) export class SelectUnit { constructor(private http:HttpClient,public dialog: MatDialog,public dialogRef: MatDialogRef,@Inject(MAT_DIALOG_DATA) public data) { } unitName:any //输入的单位名 allUnitList:any ngOnInit(): void { this.getAllKeyUnit() } //获得所有单位 getAllKeyUnit(){ let paramsdata:any = { Name: this.unitName || '', OrganizationId: '', HasChildren: '', USCI:'', IsFollowed: '', BuildingTypeId: '', PageNumber:'1', PageSize: 100, Sort: '' } this.http.get("/api/Companies",{params:paramsdata}).subscribe((data:any)=>{ this.allUnitList = data.items console.log(789,data.items) }) } selectedUnit:any//选中的单位 selected(item){ this.selectedUnit = item console.log(item) } //搜索 search(){ this.getAllKeyUnit() } //确定选择 ok(){ this.dialogRef.close(this.selectedUnit); } }