Commit 9b7d69c1 by Nakarin Luankla

แก้ model bu1-4

parent b4ff8dbf
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 { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model'; import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
...@@ -6,6 +7,7 @@ import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model'; ...@@ -6,6 +7,7 @@ import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service'; import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { Bu2Service } from 'src/app/shared/services/bu2.service'; import { Bu2Service } from 'src/app/shared/services/bu2.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table { interface table {
currentPage: number, currentPage: number,
page: number[], page: number[],
...@@ -70,18 +72,38 @@ export class DepartmentListComponent implements OnInit { ...@@ -70,18 +72,38 @@ export class DepartmentListComponent implements OnInit {
pageSize: 10 pageSize: 10
} }
currentModal: 'add' | 'edit' | 'delete' = "add" currentModal: 'add' | 'edit' | 'delete' = "add"
@ViewChild("departmentListModal") departmentListModal: any;
@ViewChild("departmentListBu1Modal") departmentListBu1Modal: any;
dialogRef: any
dialogRefBu1: any
constructor(private bu2Service: Bu2Service, constructor(private bu2Service: Bu2Service,
private bu1Service: Bu1Service, private bu1Service: Bu1Service,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getBu2List() this.getBu2List()
this.getBu1List() this.getBu1List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.departmentListModal, {
width: '500px',
})
}
openBu1Dialog() {
this.dialogRefBu1 = this.dialog.open(this.departmentListBu1Modal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeBu1Dialog() {
this.dialogRefBu1.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -185,45 +207,80 @@ export class DepartmentListComponent implements OnInit { ...@@ -185,45 +207,80 @@ export class DepartmentListComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
confirmButtonText: 'ตกลง',
});
} }
addBu2() { addBu2() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.bu2ListLoading = true this.bu2ListLoading = true
this.bu2Service.post({ ...this.bu2, parent: this.bu1.bu1id }).subscribe({ this.bu2Service.post({ ...this.bu2, parent: this.bu1.bu1id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu2List() this.getBu2List()
this.closeDialog();
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu2ListLoading = false this.bu2ListLoading = false
this.closeDialog();
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu2ListLoading = false this.bu2ListLoading = false
this.closeDialog();
} }
}) })
} }
});
}
deleteBu2() { deleteBu2() {
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.bu2ListLoading = true this.bu2ListLoading = true
// const body = this.bu2List.filter(x => x.check).map(x => new MyBu2Model(x.data)) const selectedKeys = Array.from(this.selectedItems.data.keys());
// this.bu2Service.delete(body).subscribe({ const body = this.bu2List.filter(x => selectedKeys.includes(x.bu2id) && this.selectedItems.data.get(x.bu2id)).map(x => new MyBu2Model(x))
// next: response => { this.bu2Service.delete(body).subscribe({
// if (response.success) { next: response => {
// this.showAlert(response.message, 'success') if (response.success) {
// this.getBu2List() this.showAlert(response.message, 'success')
// } else { this.getBu2List()
// this.showAlert(response.message, 'error') } else {
// this.bu2ListLoading = false this.showAlert(response.message, 'error')
// } this.bu2ListLoading = false
// }, error: error => { }
// this.showAlert(error.message, 'error') }, error: error => {
// this.bu2ListLoading = false this.showAlert(error.message, 'error')
// } this.bu2ListLoading = false
// }) }
})
}
});
} }
......
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 { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model'; import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
...@@ -6,6 +7,7 @@ import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model'; ...@@ -6,6 +7,7 @@ import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu2Service } from 'src/app/shared/services/bu2.service'; import { Bu2Service } from 'src/app/shared/services/bu2.service';
import { Bu3Service } from 'src/app/shared/services/bu3.service'; import { Bu3Service } from 'src/app/shared/services/bu3.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table { interface table {
currentPage: number, currentPage: number,
page: number[], page: number[],
...@@ -56,17 +58,38 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -56,17 +58,38 @@ export class SectionRegistrationComponent implements OnInit {
}; };
search = '' search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("sectionRegistrationModal") sectionRegistrationModal: any;
@ViewChild("sectionRegistrationModalBu2") sectionRegistrationModalBu2: any;
dialogRef: any
dialogRefBu2: any
constructor(private bu3Service: Bu3Service, constructor(private bu3Service: Bu3Service,
private bu2Service: Bu2Service, private bu2Service: Bu2Service,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getBu3List() this.getBu3List()
this.getBu2List() this.getBu2List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.sectionRegistrationModal, {
width: '500px',
})
}
openDialogBu2() {
this.dialogRefBu2 = this.dialog.open(this.sectionRegistrationModalBu2, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu2() {
this.dialogRefBu2.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
...@@ -154,23 +177,48 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -154,23 +177,48 @@ export class SectionRegistrationComponent implements OnInit {
} }
addBu3() { addBu3() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu3.loading = true this.bu3.loading = true
this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({ this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu3List() this.getBu3List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu3.loading = false this.bu3.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu3.loading = false this.bu3.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu3() { deleteBu3() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu3.loading = true this.bu3.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x)) const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x))
...@@ -189,6 +237,8 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -189,6 +237,8 @@ export class SectionRegistrationComponent implements OnInit {
} }
}) })
} }
})
}
getBu2List() { getBu2List() {
this.bu2Service.getList().subscribe(response => { this.bu2Service.getList().subscribe(response => {
...@@ -214,10 +264,12 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -214,10 +264,12 @@ export class SectionRegistrationComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
confirmButtonText: 'ตกลง',
});
} }
checkPrimary() { checkPrimary() {
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { MatDialog } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model'; import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model'; import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
import { Bu3Service } from 'src/app/shared/services/bu3.service'; import { Bu3Service } from 'src/app/shared/services/bu3.service';
import { Bu4Service } from 'src/app/shared/services/bu4.service'; import { Bu4Service } from 'src/app/shared/services/bu4.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table { interface table {
currentPage: number, currentPage: number,
page: number[], page: number[],
...@@ -63,11 +65,17 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -63,11 +65,17 @@ export class SubDepartmentOneComponent implements OnInit {
}; };
search = '' search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("subDepartmentOneModal") subDepartmentOneModal: any;
@ViewChild("subDepartmentOneBu3TableModal") subDepartmentOneBu3TableModal: any;
dialogRef: any
dialogRefBu3: any
constructor(private bu4Service: Bu4Service, constructor(private bu4Service: Bu4Service,
private bu3Service: Bu3Service, private bu3Service: Bu3Service,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
...@@ -75,6 +83,23 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -75,6 +83,23 @@ export class SubDepartmentOneComponent implements OnInit {
this.getBu3List() this.getBu3List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentOneModal, {
width: '500px',
})
}
openDialogBu3() {
this.dialogRefBu3 = this.dialog.open(this.subDepartmentOneBu3TableModal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu3() {
this.dialogRefBu3.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -160,23 +185,48 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -160,23 +185,48 @@ export class SubDepartmentOneComponent implements OnInit {
} }
addBu4() { addBu4() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu4.loading = true this.bu4.loading = true
this.bu4Service.post({ ...this.bu4.select, parent: this.bu3.bu3id }).subscribe({ this.bu4Service.post({ ...this.bu4.select, parent: this.bu3.bu3id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu4List() this.getBu4List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu4.loading = false this.bu4.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu4.loading = false this.bu4.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu4() { deleteBu4() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu4.loading = true this.bu4.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x)) const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x))
...@@ -195,6 +245,8 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -195,6 +245,8 @@ export class SubDepartmentOneComponent implements OnInit {
} }
}) })
} }
})
}
getBu3List() { getBu3List() {
this.bu3Service.getList().subscribe(response => { this.bu3Service.getList().subscribe(response => {
...@@ -220,10 +272,12 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -220,10 +272,12 @@ export class SubDepartmentOneComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
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