Commit 39c6ff1f by Nattana Chaiyamat

ทะเบียนส่วนย่อย3

parent 33e760c9
......@@ -19,7 +19,7 @@ interface table {
export class SubDepartmentThreeComponent implements OnInit {
bu6List: Bu6Model[] = []
bu6ListLoading = false
bu6: Bu6Model = new MyBu6Model({})
bu6: Bu6Model = new MyBu6Model()
bu6Table: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
......@@ -41,7 +41,7 @@ export class SubDepartmentThreeComponent implements OnInit {
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: ""
}
currentModal = ""
currentModal: 'add' | 'edit' | 'detele' = "add"
constructor(private bu6Service: Bu6Service,
private bu5Service: Bu5Service,
private toastr: ToastrService,
......@@ -65,6 +65,7 @@ export class SubDepartmentThreeComponent implements OnInit {
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.bu6ListLoading = true
this.fileService.upload(formData, 'mbu6').subscribe({
next: response => {
if (response.success) {
......@@ -72,9 +73,11 @@ export class SubDepartmentThreeComponent implements OnInit {
this.getBu6List()
} else {
this.showAlert(response.message, 'error')
this.bu6ListLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu6ListLoading = false
}
})
}
......@@ -118,11 +121,11 @@ export class SubDepartmentThreeComponent implements OnInit {
}
filterBu6Table() {
return this.bu6List.filter(x => x.bu6id.toLowerCase().includes(this.bu6Table.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.bu6Table.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.bu6Table.search.toLowerCase()))
x.tdesc.toLowerCase().includes(this.bu6Table.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.bu6Table.search.toLowerCase()))
}
selectBu6(bu6?: Bu6Model) {
this.bu6 = new MyBu6Model(bu6 || {})
this.bu6 = new MyBu6Model(bu6)
this.selectBu5()
if (this.bu6.parent) {
this.bu5Service.getById(this.bu6.parent).subscribe(response => {
......@@ -141,34 +144,40 @@ export class SubDepartmentThreeComponent implements OnInit {
}
filterBu6Modal() {
return this.bu6List.filter(x => x.bu6id.toLowerCase().includes(this.bu6Modal.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.bu6Modal.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.bu6Modal.search.toLowerCase()))
x.tdesc.toLowerCase().includes(this.bu6Modal.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.bu6Modal.search.toLowerCase()))
}
addBu6() {
this.bu6Service.post({ ...this.bu6, parent: this.bu5.bu5id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu6List()
} else {
this.showAlert(response.message, 'error')
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu6ListLoading = true
this.bu6Service.post({ ...this.bu6, parent: this.bu5.bu5id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu6List()
} else {
this.showAlert(response.message, 'error')
this.bu6ListLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu6ListLoading = false
}
})
}
deleteBu6() {
this.bu6Service.delete(this.bu6).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu6List()
} else {
this.showAlert(response.message, 'error')
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu6ListLoading = true
this.bu6Service.delete(this.bu6).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu6List()
} else {
this.showAlert(response.message, 'error')
this.bu6ListLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu6ListLoading = false
}
})
}
......@@ -189,11 +198,11 @@ export class SubDepartmentThreeComponent implements OnInit {
}
filterBu5Modal() {
return this.bu5List.filter(x => x.bu5id.toLowerCase().includes(this.bu5Modal.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.bu5Modal.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.bu5Modal.search.toLowerCase()))
x.tdesc.toLowerCase().includes(this.bu5Modal.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.bu5Modal.search.toLowerCase()))
}
selectBu5(bu5?: Bu5Model) {
this.bu5 = new MyBu5Model(bu5 || {})
this.bu5 = new MyBu5Model(bu5)
}
showAlert(text: string, type: 'success' | 'error') {
......
......@@ -13,12 +13,12 @@ export class MyBu6Model implements Bu6Model {
edesc: string;
parent: string;
companyId: string;
constructor(data: Partial<Bu6Model>) {
this.bu6id = data.bu6id || ""
this.tdesc = data.tdesc || ""
this.edesc = data.edesc || ""
this.parent = data.parent || ""
this.companyId = data.companyId || ""
constructor(data?: Partial<Bu6Model>) {
this.bu6id = data?.bu6id || ""
this.tdesc = data?.tdesc || ""
this.edesc = data?.edesc || ""
this.parent = data?.parent || ""
this.companyId = data?.companyId || ""
}
}
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