Commit d64e63f4 by Nattana Chaiyamat

ส่วนย่อย2

parent 6e853dbf
...@@ -132,6 +132,7 @@ export class DepartmentListComponent implements OnInit { ...@@ -132,6 +132,7 @@ export class DepartmentListComponent implements OnInit {
getBu2List() { getBu2List() {
this.bu2ListLoading = true this.bu2ListLoading = true
this.selectedItems.data.clear()
this.bu2Service.getList().subscribe({ this.bu2Service.getList().subscribe({
next: response => { next: response => {
this.bu2List = response.map(x => { this.bu2List = response.map(x => {
......
...@@ -102,6 +102,7 @@ export class DepartmentRegisterComponent implements OnInit { ...@@ -102,6 +102,7 @@ export class DepartmentRegisterComponent implements OnInit {
getBu1List() { getBu1List() {
this.bu1.loading = true this.bu1.loading = true
this.selectedItems.data.clear()
this.bu1Service.getList().subscribe({ this.bu1Service.getList().subscribe({
next: response => { next: response => {
this.bu1.dataList = response.map(x => { this.bu1.dataList = response.map(x => {
......
...@@ -118,6 +118,7 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -118,6 +118,7 @@ export class SectionRegistrationComponent implements OnInit {
getBu3List() { getBu3List() {
this.bu3.loading = true this.bu3.loading = true
this.selectedItems.data.clear()
this.bu3Service.getList().subscribe({ this.bu3Service.getList().subscribe({
next: response => { next: response => {
this.bu3.dataList = response.map(x => { this.bu3.dataList = response.map(x => {
......
...@@ -124,6 +124,7 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -124,6 +124,7 @@ export class SubDepartmentOneComponent implements OnInit {
} }
getBu4List() { getBu4List() {
this.bu4.loading = true this.bu4.loading = true
this.selectedItems.data.clear()
this.bu4Service.getList().subscribe({ this.bu4Service.getList().subscribe({
next: response => { next: response => {
this.bu4.dataList = response.map(x => { this.bu4.dataList = response.map(x => {
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model'; import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model'; import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model';
...@@ -17,25 +18,11 @@ interface table { ...@@ -17,25 +18,11 @@ interface table {
styleUrls: ['./sub-department-two.component.scss'] styleUrls: ['./sub-department-two.component.scss']
}) })
export class SubDepartmentTwoComponent implements OnInit { export class SubDepartmentTwoComponent implements OnInit {
bu5List: { check: boolean, data: Bu5Model }[] = [] bu5: { loading: boolean, select: Bu5Model, dataList: Bu5Model[] } = { loading: false, select: new MyBu5Model(), dataList: [] }
bu5ListLoading = false
bu5: Bu5Model = new MyBu5Model()
bu5Table: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
bu5Modal: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu4List: Bu4Model[] = [] bu4List: Bu4Model[] = []
bu4: Bu4Model = new MyBu4Model() bu4: Bu4Model = new MyBu4Model()
bu4Modal: table = { bu4Modal: table = {
...@@ -46,10 +33,29 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -46,10 +33,29 @@ export class SubDepartmentTwoComponent implements OnInit {
} }
currentModal: 'add' | 'edit' | 'delete' = "add" currentModal: 'add' | 'edit' | 'delete' = "add"
columns: ColumnModel[] = [{
numDataListChecked = 0 field: "bu5id",
isDataListChecked = false headerText: "รหัสฝ่าย",
isDataListCheckedAll = false type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['bu5id', '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 bu5Service: Bu5Service, constructor(private bu5Service: Bu5Service,
private bu4Service: Bu4Service, private bu4Service: Bu4Service,
private toastr: ToastrService, private toastr: ToastrService,
...@@ -73,7 +79,7 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -73,7 +79,7 @@ export class SubDepartmentTwoComponent implements OnInit {
} }
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.bu5ListLoading = true this.bu5.loading = true
this.fileService.uploadExcel(formData, 'mbu5').subscribe({ this.fileService.uploadExcel(formData, 'mbu5').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -81,11 +87,11 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -81,11 +87,11 @@ export class SubDepartmentTwoComponent implements OnInit {
this.getBu5List() this.getBu5List()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu5ListLoading = false this.bu5.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu5ListLoading = false this.bu5.loading = false
} }
}) })
} }
...@@ -110,76 +116,63 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -110,76 +116,63 @@ export class SubDepartmentTwoComponent implements OnInit {
} }
getBu5List() { getBu5List() {
this.bu5ListLoading = true this.bu5.loading = true
this.selectedItems.data.clear()
this.bu5Service.getList().subscribe({ this.bu5Service.getList().subscribe({
next: response => { next: response => {
this.bu5List = response.map(x => ({ check: false, data: new MyBu5Model(x) })) this.bu5.dataList = response.map(x => {
this.bu5ListLoading = false this.selectedItems.data.set(x.bu5id, false)
this.onBu5TableSearchChange() return new MyBu5Model(x)
this.isDataListCheckedAll = false })
this.dataListCheckAll() this.selectedItems.key = 'bu5id'
this.selectedItems.count = 0
this.bu5.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
this.bu5ListLoading = false this.bu5.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
} }
onBu5TableSearchChange() {
this.bu5Table.currentPage = 1
this.bu5Table.page = Array.from({ length: Math.ceil(this.filterBu5Table().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
filterBu5Table() {
return this.bu5List.filter(x => {
const data = x.data
return data.bu5id.toLowerCase().includes(this.bu5Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu5Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu5Table.search.toLowerCase())
})
}
selectBu5(bu5?: Bu5Model) { selectBu5(bu5?: Bu5Model) {
this.bu5 = new MyBu5Model(bu5 || {}) if (bu5) {
this.bu5.select = new MyBu5Model(bu5)
} else if (this.currentModal == 'add') {
this.bu5.select = new MyBu5Model()
} else if (this.currentModal == 'edit') {
this.bu5.select = new MyBu5Model({ bu5id: this.bu5.select.bu5id })
}
this.selectBu4() this.selectBu4()
if (this.bu5.parent) { if (this.bu5.select.parent) {
this.bu4Service.getById(this.bu5.parent).subscribe(response => { this.bu4Service.getById(this.bu5.select.parent).subscribe(response => {
this.bu4 = new MyBu4Model(response) this.bu4 = new MyBu4Model(response)
this.cdr.detectChanges() this.cdr.detectChanges()
}) })
} }
} }
onBu5ModalSearchChange() {
this.bu5Modal.currentPage = 1
this.bu5Modal.page = Array.from({ length: Math.ceil(this.filterBu5Modal().length / 10) }, (_, i) => i + 1);
}
filterBu5Modal() {
return this.bu5List.filter(x => {
const data = x.data
return data.bu5id.toLowerCase().includes(this.bu5Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu5Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu5Table.search.toLowerCase())
})
}
addBu5() { addBu5() {
this.bu5ListLoading = true this.bu5.loading = true
this.bu5Service.post({ ...this.bu5, parent: this.bu4.bu4id }).subscribe({ this.bu5Service.post({ ...this.bu5.select, parent: this.bu4.bu4id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu5List() this.getBu5List()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu5ListLoading = false this.bu5.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu5ListLoading = false this.bu5.loading = false
} }
}) })
} }
deleteBu5() { deleteBu5() {
this.bu5ListLoading = true this.bu5.loading = true
const body = this.bu5List.filter(x => x.check).map(x => new MyBu5Model(x.data)) const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu5.dataList.filter(x => selectedKeys.includes(x.bu5id) && this.selectedItems.data.get(x.bu5id)).map(x => new MyBu5Model(x))
this.bu5Service.delete(body).subscribe({ this.bu5Service.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -187,11 +180,11 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -187,11 +180,11 @@ export class SubDepartmentTwoComponent implements OnInit {
this.getBu5List() this.getBu5List()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu5ListLoading = false this.bu5.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu5ListLoading = false this.bu5.loading = false
} }
}) })
} }
...@@ -226,21 +219,18 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -226,21 +219,18 @@ export class SubDepartmentTwoComponent implements OnInit {
}) })
} }
dataListCheckAll() { checkPrimary() {
const selectAll = this.isDataListCheckedAll; return this.bu5.dataList.find(x => x.bu5id == this.bu5.select.bu5id)
this.filterBu5Table().forEach(x => x.check = selectAll);
this.dataListCheck();
} }
dataListCheck() { numSelectItem() {
const dataCheck = this.filterBu5Table(); const selectedKeys = Array.from(this.selectedItems.data.keys());
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false; const num = this.bu5.dataList.filter(x => selectedKeys.includes(x.bu5id) && this.selectedItems.data.get(x.bu5id)).length
this.numDataListChecked = this.bu5List.filter(x => x.check).length return num
this.isDataListChecked = Boolean(this.numDataListChecked)
} }
checkPrimary() { onSelectItemChange(arg: any) {
return this.bu5List.find(x => x.data.bu5id == this.bu5.bu5id) this.selectedItems = arg
} }
} }
...@@ -64,6 +64,7 @@ export class CompanyRegistrationPageComponent { ...@@ -64,6 +64,7 @@ export class CompanyRegistrationPageComponent {
getCompanyList() { getCompanyList() {
this.dataLoading = true this.dataLoading = true
this.selectedItems.data.clear()
this.companyService.getList().subscribe({ this.companyService.getList().subscribe({
next: response => { next: response => {
this.dataList = response.map(x => { this.dataList = response.map(x => {
......
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