Commit 39c6ff1f by Nattana Chaiyamat

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

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