Commit 2a30be7c by Nattana Chaiyamat

syncfution ทะเบียนส่วน

parent 307b800b
......@@ -149,22 +149,21 @@ export class DepartmentRegisterComponent implements OnInit {
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
console.log(" 🐒 result:", result)
// this.bu1.loading = true
// this.bu1Service.post(this.bu1.select).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu1List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu1.loading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu1.loading = false
// }
// })
this.bu1.loading = true
this.bu1Service.post(this.bu1.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu1List()
} else {
this.showAlert(response.message, 'error')
this.bu1.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu1.loading = false
}
})
}
})
}
......@@ -183,24 +182,23 @@ export class DepartmentRegisterComponent implements OnInit {
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
console.log(" 🐒 result:", result)
// this.bu1.loading = true
// const selectedKeys = Array.from(this.selectedItems.data.keys());
// const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
// this.bu1Service.delete(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu1List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu1.loading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu1.loading = false
// }
// })
this.bu1.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
this.bu1Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu1List()
} else {
this.showAlert(response.message, 'error')
this.bu1.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu1.loading = false
}
})
}
});
}
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
......@@ -17,25 +18,10 @@ interface table {
styleUrls: ['./section-registration.component.scss']
})
export class SectionRegistrationComponent implements OnInit {
bu3List: { check: boolean, data: Bu3Model }[] = []
bu3ListLoading = false
bu3: Bu3Model = new MyBu3Model()
bu3Table: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu3: { loading: boolean, select: Bu3Model, dataList: Bu3Model[] } = { loading: false, select: new MyBu3Model(), dataList: [] }
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
bu3Modal: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu2List: Bu2Model[] = []
bu2: Bu2Model = new MyBu2Model()
bu2Modal: table = {
......@@ -46,9 +32,30 @@ export class SectionRegistrationComponent implements OnInit {
}
currentModal: 'add' | 'edit' | 'delete' = "add"
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
columns: ColumnModel[] = [{
field: "bu3id",
headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['bu3id', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
constructor(private bu3Service: Bu3Service,
private bu2Service: Bu2Service,
private toastr: ToastrService,
......@@ -73,7 +80,7 @@ export class SectionRegistrationComponent implements OnInit {
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.bu3ListLoading = true
this.bu3.loading = true
this.fileService.uploadExcel(formData, 'mbu3').subscribe({
next: response => {
if (response.success) {
......@@ -81,11 +88,11 @@ export class SectionRegistrationComponent implements OnInit {
this.getBu3List()
} else {
this.showAlert(response.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
})
}
......@@ -110,80 +117,62 @@ export class SectionRegistrationComponent implements OnInit {
}
getBu3List() {
this.bu3ListLoading = true
this.bu3.loading = true
this.bu3Service.getList().subscribe({
next: response => {
this.bu3List = response.map(x => ({ check: false, data: new MyBu3Model(x) }))
this.bu3ListLoading = false
this.onBu3TableSearchChange()
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.bu3.dataList = response.map(x => {
this.selectedItems.data.set(x.bu3id, false)
return new MyBu3Model(x)
})
this.selectedItems.key = 'bu3id'
this.selectedItems.count = 0
this.bu3.loading = false
this.cdr.detectChanges()
}, error: error => {
this.bu3ListLoading = false
this.bu3.loading = false
this.cdr.detectChanges()
}
})
}
onBu3TableSearchChange() {
this.bu3Table.currentPage = 1
this.bu3Table.page = Array.from({ length: Math.ceil(this.filterBu3Table().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
filterBu3Table() {
return this.bu3List.filter(x => {
const data = x.data
return data.bu3id.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu3Table.search.toLowerCase())
})
}
selectBu3(bu3?: Bu3Model) {
this.bu3 = new MyBu3Model(bu3)
if (bu3) {
this.bu3.select = new MyBu3Model(bu3)
} else if (this.currentModal == 'add') {
this.bu3.select = new MyBu3Model()
} else if (this.currentModal == 'edit') {
this.bu3.select = new MyBu3Model({ bu3id: this.bu3.select.bu3id })
}
this.selectBu2()
if (this.bu3.parent) {
this.bu2Service.getById(this.bu3.parent).subscribe(response => {
if (this.bu3.select.parent) {
this.bu2Service.getById(this.bu3.select.parent).subscribe(response => {
this.bu2 = new MyBu2Model(response)
this.cdr.detectChanges()
})
}
}
// bu3idChange() {
// const bu3 = this.bu3List.find(x => x.bu3id == this.bu3.bu3id)
// this.selectBu3(bu3 || new MyBu3Model({ bu3id: this.bu3.bu3id }))
// }
onBu3ModalSearchChange() {
this.bu3Modal.currentPage = 1
this.bu3Modal.page = Array.from({ length: Math.ceil(this.filterBu3Modal().length / 10) }, (_, i) => i + 1);
}
filterBu3Modal() {
return this.bu3List.filter(x => {
const data = x.data
return data.bu3id.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu3Table.search.toLowerCase())
})
}
addBu3() {
this.bu3ListLoading = true
this.bu3Service.post({ ...this.bu3, parent: this.bu2.bu2id }).subscribe({
this.bu3.loading = true
this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu3List()
} else {
this.showAlert(response.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
})
}
deleteBu3() {
this.bu3ListLoading = true
const body = this.bu3List.filter(x => x.check).map(x => new MyBu3Model(x.data))
this.bu3.loading = true
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))
this.bu3Service.delete(body).subscribe({
next: response => {
if (response.success) {
......@@ -191,11 +180,11 @@ export class SectionRegistrationComponent implements OnInit {
this.getBu3List()
} else {
this.showAlert(response.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
})
}
......@@ -230,21 +219,20 @@ export class SectionRegistrationComponent implements OnInit {
})
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.filterBu3Table().forEach(x => x.check = selectAll);
this.dataListCheck();
checkPrimary() {
return this.bu3.dataList.find(x => x.bu3id == this.bu3.select.bu3id)
}
dataListCheck() {
const dataCheck = this.filterBu3Table();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.bu3List.filter(x => x.check).length
this.isDataListChecked = Boolean(this.numDataListChecked)
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).length
return num
}
checkPrimary() {
return this.bu3List.find(x => x.data.bu3id == this.bu3.bu3id)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
}
export const environment = {
production: true,
firebase: {
apiKey: '********************************',
authDomain: '********************************',
projectId: '********************************',
storageBucket: '********************************',
messagingSenderId: '********************************',
appId: '********************************',
measurementId: '********************************',
},
};
baseUrl: window.location.origin + '/api',
}
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