Commit 55e84dd8 by Nakarin Luankla

แก้ modal

parent aff91f9f
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild, } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
......@@ -6,6 +7,7 @@ import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model';
import { Bu4Service } from 'src/app/shared/services/bu4.service';
import { Bu5Service } from 'src/app/shared/services/bu5.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table {
currentPage: number,
page: number[],
......@@ -56,17 +58,39 @@ export class SubDepartmentTwoComponent implements OnInit {
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("subDepartmentTwoModal") subDepartmentTwoModal: any;
@ViewChild("subDepartmentTwoModalBu4") subDepartmentTwoModalBu4: any;
dialogRef: any
dialogRefBu4: any
constructor(private bu5Service: Bu5Service,
private bu4Service: Bu4Service,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getBu5List()
this.getBu4List()
}
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentTwoModal, {
width: '500px',
})
}
openDialogBu4() {
this.dialogRefBu4 = this.dialog.open(this.subDepartmentTwoModalBu4, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu4() {
this.dialogRefBu4.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
......@@ -153,23 +177,47 @@ export class SubDepartmentTwoComponent implements OnInit {
}
addBu5() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.bu5.loading = true
this.bu5Service.post({ ...this.bu5.select, parent: this.bu4.bu4id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu5List()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.bu5.loading = false
this.closeDialog()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu5.loading = false
this.closeDialog()
}
})
}
})
}
deleteBu5() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
this.bu5.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu5.dataList.filter(x => selectedKeys.includes(x.bu5id) && this.selectedItems.data.get(x.bu5id)).map(x => new MyBu5Model(x))
......@@ -187,6 +235,7 @@ export class SubDepartmentTwoComponent implements OnInit {
this.bu5.loading = false
}
})
})
}
getBu4List() {
......@@ -213,9 +262,12 @@ export class SubDepartmentTwoComponent implements OnInit {
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
Swal.fire({
icon: type,
title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment