import { Component, OnInit, TemplateRef, ViewContainerRef } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { NzModalService } from 'ng-zorro-antd/modal'; import { NzMessageService } from 'ng-zorro-antd/message'; import { HttpClient } from '@angular/common/http'; import { AddUpdateOfLicenseComponent } from './add-update-of-license/add-update-of-license.component'; import { EditUpdateOfLicenseComponent } from './edit-update-of-license/edit-update-of-license.component'; @Component({ selector: 'app-update-of-license', templateUrl: './update-of-license.component.html', styleUrls: ['./update-of-license.component.scss'] }) export class UpdateOfLicenseComponent implements OnInit { constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient) { } ngOnInit(): void { this.getLicense() } listOfData: any[] = []; //获取证照列表 isLoading = false getLicense() { this.isLoading = true let params = { SkipCount: '0', MaxResultCount: '999' } this.http.get('/api/services/app/ValidityLicenseType/GetAll', { params: params }).subscribe((data: any) => { console.log('证照列表', data.result.items) this.isLoading = false this.listOfData = data.result.items }) } addRole(): void { const modal = this.modal.create({ nzTitle: '新增证照', nzContent: AddUpdateOfLicenseComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 588, nzComponentParams: {}, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise(resolve => { console.log('表单信息', instance.validateForm) let body = { licenseName: instance.validateForm.value.name, handleRemindDays: instance.validateForm.value.handleRemindDays, closingRemindDays: instance.validateForm.value.closingRemindDays } this.http.post('/api/services/app/ValidityLicenseType/Create', body).subscribe(data => { resolve(data) this.message.create('success', '创建成功!'); this.getLicense() return true }) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!')); // Return a result when closed modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); } edit(item) { const modal = this.modal.create({ nzTitle: '编辑证照', nzContent: EditUpdateOfLicenseComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 588, nzComponentParams: { data: item }, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise(resolve => { console.log('表单信息', instance.validateForm) let body = { id: item.id, licenseName: instance.validateForm.value.name, handleRemindDays: instance.validateForm.value.handleRemindDays, closingRemindDays: instance.validateForm.value.closingRemindDays } this.http.put('/api/services/app/ValidityLicenseType/Update', body).subscribe(data => { resolve(data) this.message.create('success', '修改成功!'); this.getLicense() return true }) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!')); // Return a result when closed modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); } delete(item) { console.log(item) this.modal.confirm({ nzTitle: `确定要删除${item.licenseName}这个证照吗?`, nzOkText: '确定', nzOkType: 'danger', nzOnOk: () => { this.http.delete('/api/services/app/ValidityLicenseType/Delete', { params: { Id: item.id } }).subscribe(data => { this.message.create('success', '删除成功!'); this.getLicense() }) }, nzCancelText: '取消', nzOnCancel: () => { } }); } }