ส่วนย่อยที่1 เเละ ส่วนย่อยที่2 API

parent f98e2989
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
import { Bu3Service } from 'src/app/shared/services/bu3.service';
import { Bu4Service } from 'src/app/shared/services/bu4.service';
@Component({ @Component({
selector: 'app-sub-department-one', selector: 'app-sub-department-one',
...@@ -6,43 +10,52 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; ...@@ -6,43 +10,52 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
styleUrls: ['./sub-department-one.component.scss'] styleUrls: ['./sub-department-one.component.scss']
}) })
export class SubDepartmentOneComponent { export class SubDepartmentOneComponent {
modalOptions: { currentPage = 1
[nameModal: string]: { // ชื่อตรวจสอบการเปิดปิด page = Array.from({ length: 1 }, (_, i) => i + 1);
isModalOpen: boolean; // เปิด/ปิด bu4List: Bu4Model[] = []
modalSize: string; // ขนาดของ Modal (s,m,l,vw10-vw100 ) bu4: Bu4Model = new MyBu4Model({})
backdropClose: boolean; // (คลิก Backdrop แล้ว true ปิด false ไม่ปิด ) bu3: Bu3Model = new MyBu3Model({})
} search = ""
} = { constructor(private bu4Service: Bu4Service,
"add": { private bu3Service: Bu3Service
isModalOpen: false, ) { }
modalSize: 'm', ngOnInit(): void {
backdropClose: true, this.getBu4List()
},
"edit": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
}
}
openModal(name: string, size: string, closeOnBackdrop?: boolean) {
this.modalOptions[name].modalSize = size;
this.modalOptions[name].backdropClose = closeOnBackdrop || false;
this.modalOptions[name].isModalOpen = true;
document.body.style.overflow = 'hidden'; // ล็อก Scroll
} }
getBu4List() {
closeModal(name: string) { this.bu4Service.getList().subscribe(response => {
this.modalOptions[name].isModalOpen = false; this.bu4List = response
// ตรวจสอบว่ามี Modal อื่นเปิดอยู่หรือไม่ this.searchChange()
if (!this.isAnyModalOpen()) { })
document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว
}
} }
searchChange() {
isAnyModalOpen(): boolean { this.currentPage = 1
// Logic ตรวจสอบว่า Modal อื่นยังเปิดอยู่หรือไม่ this.page = Array.from({ length: Math.ceil(this.bu4ListFilter().length / 10) }, (_, i) => i + 1);
return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // หากไม่มี Modal อื่นเปิด }
bu4ListFilter() {
return this.bu4List.filter(x => x.bu4id.toLowerCase().includes(this.search) ||
x.tdesc.toLowerCase().includes(this.search) ||
x.edesc.toLowerCase().includes(this.search))
}
selectBu4(bu4: Bu4Model) {
this.bu3Service.getById(bu4.parent).subscribe(response => {
this.bu3 = response
})
this.bu4 = new MyBu4Model(bu4)
}
addBu4() {
// this.bu4Service.post(this.bu4).subscribe((response:any) => {
// if (response.success) {
// this.getBu4List()
// }
// })
}
deleteBu4(bu4: Bu4Model) {
// this.bu4Service.delete(new MyBu4Model(bu4)).subscribe((response:any) => {
// if (response.success) {
// this.getBu4List()
// }
// })
} }
} }
......
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, OnInit } from '@angular/core';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
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';
@Component({ @Component({
selector: 'app-sub-department-two', selector: 'app-sub-department-two',
templateUrl: './sub-department-two.component.html', templateUrl: './sub-department-two.component.html',
styleUrls: ['./sub-department-two.component.scss'] styleUrls: ['./sub-department-two.component.scss']
}) })
export class SubDepartmentTwoComponent { export class SubDepartmentTwoComponent implements OnInit {
modalOptions: { currentPage = 1
[nameModal: string]: { // ชื่อตรวจสอบการเปิดปิด page = Array.from({ length: 1 }, (_, i) => i + 1);
isModalOpen: boolean; // เปิด/ปิด bu5List: Bu5Model[] = []
modalSize: string; // ขนาดของ Modal (s,m,l,vw10-vw100 ) bu5: Bu5Model = new MyBu5Model({})
backdropClose: boolean; // (คลิก Backdrop แล้ว true ปิด false ไม่ปิด ) bu4: Bu4Model = new MyBu4Model({})
} search = ""
} = { constructor(private bu5Service: Bu5Service,
"add": { private bu4Service: Bu4Service
isModalOpen: false, ) { }
modalSize: 'm', ngOnInit(): void {
backdropClose: true, this.getBu5List()
},
"edit": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
}
}
openModal(name: string, size: string, closeOnBackdrop?: boolean) {
this.modalOptions[name].modalSize = size;
this.modalOptions[name].backdropClose = closeOnBackdrop || false;
this.modalOptions[name].isModalOpen = true;
document.body.style.overflow = 'hidden'; // ล็อก Scroll
} }
getBu5List() {
closeModal(name: string) { this.bu5Service.getList().subscribe(response => {
this.modalOptions[name].isModalOpen = false; this.bu5List = response
// ตรวจสอบว่ามี Modal อื่นเปิดอยู่หรือไม่ this.searchChange()
if (!this.isAnyModalOpen()) { })
document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว
}
} }
searchChange() {
isAnyModalOpen(): boolean { this.currentPage = 1
// Logic ตรวจสอบว่า Modal อื่นยังเปิดอยู่หรือไม่ this.page = Array.from({ length: Math.ceil(this.bu5ListFilter().length / 10) }, (_, i) => i + 1);
return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // หากไม่มี Modal อื่นเปิด }
bu5ListFilter() {
return this.bu5List.filter(x => x.bu5id.toLowerCase().includes(this.search) ||
x.tdesc.toLowerCase().includes(this.search) ||
x.edesc.toLowerCase().includes(this.search))
}
selectBu5(bu5: Bu5Model) {
this.bu4Service.getById(bu5.parent).subscribe(response => {
this.bu4 = response
})
this.bu5 = new MyBu5Model(bu5)
}
addBu5() {
// this.bu5Service.post(this.bu5).subscribe((response:any) => {
// if (response.success) {
// this.getBu5List()
// }
// })
}
deleteBu5(bu5: Bu5Model) {
// this.bu5Service.delete(new MyBu5Model(bu5)).subscribe((response:any) => {
// if (response.success) {
// this.getBu5List()
// }
// })
} }
} }
...@@ -44,7 +44,7 @@ import { FormsModule } from '@angular/forms'; ...@@ -44,7 +44,7 @@ import { FormsModule } from '@angular/forms';
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 { Bu4Service } from 'src/app/shared/services/bu4.service'; import { Bu4Service } from 'src/app/shared/services/bu4.service';
import { Bu5Service } from 'src/app/shared/services/bu5service'; import { Bu5Service } from 'src/app/shared/services/bu5.service';
import { Bu6Service } from 'src/app/shared/services/bu6.service'; import { Bu6Service } from 'src/app/shared/services/bu6.service';
import { Bu7Service } from 'src/app/shared/services/bu7.service'; import { Bu7Service } from 'src/app/shared/services/bu7.service';
......
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