import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { Component, OnInit, AfterViewInit, ViewChild, ViewContainerRef } from '@angular/core'; import { TreeService } from 'src/app/service/tree.service'; import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { NzModalService } from 'ng-zorro-antd/modal'; import { NzMessageService } from 'ng-zorro-antd/message'; import { AddUnitComponent } from '../add-unit/add-unit.component'; import { UnitEditComponent }from '../unit-edit/unit-edit.component' @Component({ selector: 'app-unit', templateUrl: './unit.component.html', styleUrls: ['./unit.component.scss'] }) export class UnitComponent implements OnInit { checked = true listOfData: any = []; integrity = 0 validateForm!: FormGroup; constructor(private router: Router, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService, private modal: NzModalService, private message: NzMessageService, private viewContainerRef: ViewContainerRef) { } datas = "" ngOnInit(): void { this.validateForm = this.fb.group({ level: [null], type: [null], event: [null], area: [null], disposalState: [null], }); this.getCompanies() } searchValue = ''; next() { this.router.navigate(['/basicInfo/unit/details']); } getCompanies() { this.http.get('/api/Companies').subscribe((data: any) => { console.log(data); this.listOfData = data.items this.listOfData = [...this.listOfData] console.log(this.listOfData); for (let index = 0; index < this.listOfData.length; index++) { this.listOfData[index].creationTime=this.listOfData[index].creationTime.substring(0,10) } }) } ngOnDestroy(): void { console.log('删除了6666666666666') // CustomReuseStrategy.deleteRouteSnapshot('/basicInfo/unit'); } addOr(node?: any) { console.log(node); const modal = this.modal.create({ nzTitle: "新增单位", nzContent: AddUnitComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 450, nzComponentParams: {}, nzOnOk: async () => { console.log(instance.validateForm); if (instance.validateForm.valid) { console.log(instance.validateForm); return await new Promise(resolve => { let body = { companyName: instance.validateForm.value.unit, directorName: instance.validateForm.value.name, directorPhone: instance.validateForm.value.iphone, address: instance.validateForm.value.addr, organizationId: instance.validateForm.value.role || null, relatedOrganizationId: instance.validateForm.value.role2 || null, buildingTypeId: instance.validateForm.value.role4 || null, useNature: instance.validateForm.value.nature, data: null } this.http.post('/api/Companies', body).subscribe({ next: (data: any) => { this.message.create('success', '编辑成功!'); modal.destroy() this.getCompanies() return true }, error: (err) => { console.log(err) this.message.create('warning', '创建失败'); return false } } ) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); } }