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 => { let body = { licenseName: instance.validateForm.value.name, handleRemindDays: instance.validateForm.value.handleRemindDays, closingRemindDays: instance.validateForm.value.closingRemindDays, hasAttachment: instance.validateForm.value.isEctype, handleTypes: instance.validateForm.value.handleType, isYearlyCheck: instance.validateForm.value.isYearlyCheck } 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, hasAttachment: instance.validateForm.value.isEctype, handleTypes: instance.validateForm.value.handleType, isYearlyCheck: instance.validateForm.value.isYearlyCheck } 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: 'primary', nzOnOk: () => { this.http.delete('/api/services/app/ValidityLicenseType/Delete', { params: { Id: item.id } }).subscribe(data => { this.message.create('success', '删除成功!'); this.getLicense() }) }, nzCancelText: '取消', nzOnCancel: () => { } }); } handleTypeList = [ { value: 0, name: "无" }, { value: 1, name: "年度公示" }, { value: 2, name: "年检" }, { value: 3, name: "到期换证" }, { value: 4, name: "年度执行报告" }, { value: 5, name: "到期检测" }, { value: 6, name: "年度复训" }, { value: 7, name: "年度检测" }, { value: 8, name: "到期备案" }, { value: 9, name: "到期评价" }, ] //获取办理类型 getHandleTypes(handleTypes: any[]): string { if (!handleTypes || !handleTypes.length) { return } let names: string[] = [] let handleTypeList = JSON.parse(JSON.stringify(handleTypes)); let list = this.handleTypeList; handleTypeList.forEach(item => { list.find(element => { item == element.value ? names.push(element.name) : null }) }) return names.join(',') } }