Commit 7c9e1e0e by Nattana Chaiyamat

ส่วนย่อย1

parent f048227e
......@@ -122,7 +122,7 @@
</label>
<div class="relative flex rounded-md w-1/2">
<input type="text" class="ti-form-input" [class.!bg-input-readonly]="currentModal=='edit'"
[required]="currentModal=='edit'" [class.!border-red]="currentModal=='add'&&checkPrimary()"
[readonly]="currentModal=='edit'" [class.!border-red]="currentModal=='add'&&checkPrimary()"
[(ngModel)]="bu3.select.bu3id">
</div>
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียดส่วน (ไทย)<span
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
......@@ -17,15 +18,7 @@ interface table {
styleUrls: ['./sub-department-one.component.scss']
})
export class SubDepartmentOneComponent implements OnInit {
bu4List: { check: boolean, data: Bu4Model }[] = []
bu4ListLoading = false
bu4: Bu4Model = new MyBu4Model()
bu4Table: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu4: { loading: boolean, select: Bu4Model, dataList: Bu4Model[] } = { loading: false, select: new MyBu4Model(), dataList: [] }
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
......@@ -46,9 +39,30 @@ export class SubDepartmentOneComponent implements OnInit {
}
currentModal: 'add' | 'edit' | 'delete' = "add"
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
columns: ColumnModel[] = [{
field: "bu4id",
headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['bu4id', '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 bu4Service: Bu4Service,
private bu3Service: Bu3Service,
private toastr: ToastrService,
......@@ -73,7 +87,7 @@ export class SubDepartmentOneComponent implements OnInit {
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.bu4ListLoading = true
this.bu4.loading = true
this.fileService.uploadExcel(formData, 'mbu4').subscribe({
next: response => {
if (response.success) {
......@@ -81,11 +95,11 @@ export class SubDepartmentOneComponent implements OnInit {
this.getBu4List()
} else {
this.showAlert(response.message, 'error')
this.bu4ListLoading = false
this.bu4.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu4ListLoading = false
this.bu4.loading = false
}
})
}
......@@ -109,74 +123,62 @@ export class SubDepartmentOneComponent implements OnInit {
}
getBu4List() {
this.bu4ListLoading = true
this.bu4.loading = true
this.bu4Service.getList().subscribe({
next: response => {
this.bu4List = response.map(x => ({ check: false, data: new MyBu4Model(x) }))
this.bu4ListLoading = false
this.onBu4TableSearchChange()
this.bu4.dataList = response.map(x => {
this.selectedItems.data.set(x.bu4id, false)
return new MyBu4Model(x)
})
this.selectedItems.key = 'bu4id'
this.selectedItems.count = 0
this.bu4.loading = false
this.cdr.detectChanges()
}, error: error => {
this.bu4ListLoading = false
this.bu4.loading = false
this.cdr.detectChanges()
}
})
}
onBu4TableSearchChange() {
this.bu4Table.currentPage = 1
this.bu4Table.page = Array.from({ length: Math.ceil(this.filterBu4Table().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
filterBu4Table() {
return this.bu4List.filter(x => {
const data = x.data
return data.bu4id.toLowerCase().includes(this.bu4Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu4Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu4Table.search.toLowerCase())
})
}
selectBu4(bu4?: Bu4Model) {
this.bu4 = new MyBu4Model(bu4 || {})
if (bu4) {
this.bu4.select = new MyBu4Model(bu4)
} else if (this.currentModal == 'add') {
this.bu4.select = new MyBu4Model()
} else if (this.currentModal == 'edit') {
this.bu4.select = new MyBu4Model({ bu4id: this.bu4.select.bu4id })
}
this.selectBu3()
if (this.bu4.parent) {
this.bu3Service.getById(this.bu4.parent).subscribe(response => {
if (this.bu4.select.parent) {
this.bu3Service.getById(this.bu4.select.parent).subscribe(response => {
this.bu3 = new MyBu3Model(response)
this.cdr.detectChanges()
})
}
}
onBu4ModalSearchChange() {
this.bu4Modal.currentPage = 1
this.bu4Modal.page = Array.from({ length: Math.ceil(this.filterBu4Modal().length / 10) }, (_, i) => i + 1);
}
filterBu4Modal() {
return this.bu4List.filter(x => {
const data = x.data
return data.bu4id.toLowerCase().includes(this.bu4Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu4Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu4Table.search.toLowerCase())
})
}
addBu4() {
this.bu4ListLoading = true
this.bu4Service.post({ ...this.bu4, parent: this.bu3.bu3id }).subscribe({
this.bu4.loading = true
this.bu4Service.post({ ...this.bu4.select, parent: this.bu3.bu3id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu4List()
} else {
this.showAlert(response.message, 'error')
this.bu4ListLoading = false
this.bu4.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu4ListLoading = false
this.bu4.loading = false
}
})
}
deleteBu4() {
this.bu4ListLoading = true
const body = this.bu4List.filter(x => x.check).map(x => new MyBu4Model(x.data))
this.bu4.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x))
this.bu4Service.delete(body).subscribe({
next: response => {
if (response.success) {
......@@ -184,11 +186,11 @@ export class SubDepartmentOneComponent implements OnInit {
this.getBu4List()
} else {
this.showAlert(response.message, 'error')
this.bu4ListLoading = false
this.bu4.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu4ListLoading = false
this.bu4.loading = false
}
})
}
......@@ -224,22 +226,18 @@ export class SubDepartmentOneComponent implements OnInit {
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.filterBu4Table().forEach(x => x.check = selectAll);
this.dataListCheck();
checkPrimary() {
return this.bu4.dataList.find(x => x.bu4id == this.bu4.select.bu4id)
}
dataListCheck() {
const dataCheck = this.filterBu4Table();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.bu4List.filter(x => x.check).length
this.isDataListChecked = Boolean(this.numDataListChecked)
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).length
return num
}
checkPrimary() {
return this.bu4List.find(x => x.data.bu4id == this.bu4.bu4id)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
}
......
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