diff --git a/src/app/plan-management/pass-plan/open-or/open-or.component.ts b/src/app/plan-management/pass-plan/open-or/open-or.component.ts index 0d0c9e1..5c0d97e 100644 --- a/src/app/plan-management/pass-plan/open-or/open-or.component.ts +++ b/src/app/plan-management/pass-plan/open-or/open-or.component.ts @@ -1,5 +1,13 @@ import { HttpClient } from "@angular/common/http"; -import { Component, OnInit, AfterViewInit, ViewChild } from "@angular/core"; +import { + Component, + OnInit, + AfterViewInit, + ViewChild, + Inject, +} from "@angular/core"; +import { MatSnackBar } from "@angular/material/snack-bar"; +import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog"; import { NzFormatEmitEvent, NzTreeComponent, @@ -12,7 +20,12 @@ import { styleUrls: ["./open-or.component.scss"], }) export class OpenOrComponent implements OnInit { - constructor(private http: HttpClient) {} + constructor( + private http: HttpClient, + public snackBar: MatSnackBar, + @Inject(MAT_DIALOG_DATA) public data: any, + public dialogRef: MatDialogRef + ) {} @ViewChild("nzTreeComponent", { static: false }) nzTreeComponent!: NzTreeComponent; defaultCheckedKeys = []; @@ -77,8 +90,12 @@ export class OpenOrComponent implements OnInit { } return node; } + if (this.data.plan.publicOrganizationIds.length === 0) { + this.defaultCheckedKeys = [...lookForAllId([item])]; + } else { + this.defaultCheckedKeys = this.data.plan.publicOrganizationIds; + } - this.defaultCheckedKeys = [...lookForAllId([item])]; this.nodes = [...[item]]; } }); @@ -86,7 +103,24 @@ export class OpenOrComponent implements OnInit { }); } save() { - console.log(this.nzTreeComponent); - console.log(this.nzTreeComponent.getCheckedNodeList()); + let ids = + this.nzTreeComponent.getCheckedNodeList().map((item) => { + return item.key; + }) || []; + if (ids.length === 0) { + this.snackBar.open("至少选择一个队站公开", "确定", { + verticalPosition: "top", + duration: 3000, + }); + } + this.http + .put(`/api/PlanAudits/${this.data.plan.id}/Public`, ids) + .subscribe((data) => { + this.snackBar.open("预案已公开", "确定", { + verticalPosition: "top", + duration: 3000, + }); + this.dialogRef.close("公开成功"); + }); } } diff --git a/src/app/plan-management/pass-plan/pass-plan.component.ts b/src/app/plan-management/pass-plan/pass-plan.component.ts index 062dcfa..33b5b04 100644 --- a/src/app/plan-management/pass-plan/pass-plan.component.ts +++ b/src/app/plan-management/pass-plan/pass-plan.component.ts @@ -494,21 +494,15 @@ export class PassPlanComponent implements OnInit { } //预案公开 openReserve(e) { - console.log(e); const dialogRef = this.dialog.open(OpenOrComponent, { width: "500px", data: { plan: e }, }); - dialogRef.afterClosed().subscribe((result) => { - console.log("The dialog was closed"); + if (result && result === "公开成功") { + this.getAllPlanInfo(); + } }); - // this.http.put(`/api/PlanAudits/${e.id}/Public`, []).subscribe(data => { - // const config = new MatSnackBarConfig(); - // config.verticalPosition = 'top'; - // config.duration = 3000 - // this.snackBar.open('预案已公开', '确定', config); - // }) } //预案取消公开 @@ -518,6 +512,7 @@ export class PassPlanComponent implements OnInit { config.verticalPosition = "top"; config.duration = 3000; this.snackBar.open("预案已取消公开", "确定", config); + this.getAllPlanInfo(); }); }