Commit 23a71772 by Nakarin Luankla

UPDATE เปี่ลยน dialog

parent 52f56c3d
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { BranchModel, MyBranchModel } from 'src/app/shared/model/branch.model'; import { BranchModel, MyBranchModel } from 'src/app/shared/model/branch.model';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model'; import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
...@@ -33,6 +33,8 @@ import { EmpStatusService } from 'src/app/shared/services/emp-status.service'; ...@@ -33,6 +33,8 @@ import { EmpStatusService } from 'src/app/shared/services/emp-status.service';
import { StatusModel, MyStatusModel } from 'src/app/shared/model/status.model'; import { StatusModel, MyStatusModel } from 'src/app/shared/model/status.model';
import { MyBossModel } from 'src/app/shared/model/boss.model'; import { MyBossModel } from 'src/app/shared/model/boss.model';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { MatDialog } from '@angular/material/dialog';
import Swal from 'sweetalert2';
export interface DataModal { export interface DataModal {
search: string, search: string,
currentPage: number, currentPage: number,
...@@ -83,6 +85,9 @@ export class SubEmployeeRegistrationComponent { ...@@ -83,6 +85,9 @@ export class SubEmployeeRegistrationComponent {
page: Array.from({ length: 1 }, (_, i) => i + 1), page: Array.from({ length: 1 }, (_, i) => i + 1),
pageSize: 10 pageSize: 10
} }
pageSize: number = 10
page: number = 1
currentPage: number = 1
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
...@@ -102,6 +107,29 @@ export class SubEmployeeRegistrationComponent { ...@@ -102,6 +107,29 @@ export class SubEmployeeRegistrationComponent {
empType: { loading: boolean, dataList: EmpTypeModel[] } = { loading: false, dataList: [] } empType: { loading: boolean, dataList: EmpTypeModel[] } = { loading: false, dataList: [] }
pl: { loading: boolean, dataList: PLModel[] } = { loading: false, dataList: [] } pl: { loading: boolean, dataList: PLModel[] } = { loading: false, dataList: [] }
empStatus: { loading: boolean, dataList: StatusModel[] } = { loading: false, dataList: [] } empStatus: { loading: boolean, dataList: StatusModel[] } = { loading: false, dataList: [] }
@ViewChild('employeeRegistrationModal') employeeRegistrationModal: any
dialogRef: any
@ViewChild('empGroupModal') empGroupModal: any
empGroupDialogRef: any
@ViewChild('employeeListModal') employeeListModal: any
employeeListDialogRef: any
@ViewChild('bu1Modal') bu1Modal: any
bu1DialogRef: any
@ViewChild('bu2Modal') bu2Modal: any
bu2DialogRef: any
@ViewChild('bu3Modal') bu3Modal: any
bu3DialogRef: any
@ViewChild('bu4Modal') bu4Modal: any
bu4DialogRef: any
@ViewChild('bu5Modal') bu5Modal: any
bu5DialogRef: any
@ViewChild('bu6Modal') bu6Modal: any
bu6DialogRef: any
@ViewChild('bu7Modal') bu7Modal: any
bu7DialogRef: any
constructor(private toastr: ToastrService, constructor(private toastr: ToastrService,
private employeeService: EmployeeService, private employeeService: EmployeeService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -119,7 +147,9 @@ export class SubEmployeeRegistrationComponent { ...@@ -119,7 +147,9 @@ export class SubEmployeeRegistrationComponent {
private empTypeService: EmpTypeService, private empTypeService: EmpTypeService,
private empStatusService: EmpStatusService, private empStatusService: EmpStatusService,
private fileService: FileService, private fileService: FileService,
private pLService: PLService) { } private pLService: PLService,
private dialog: MatDialog
) { }
ngOnInit(): void { ngOnInit(): void {
this.getEmployeeList() this.getEmployeeList()
...@@ -132,6 +162,87 @@ export class SubEmployeeRegistrationComponent { ...@@ -132,6 +162,87 @@ export class SubEmployeeRegistrationComponent {
this.getPlList() this.getPlList()
this.getEmpStatusList() this.getEmpStatusList()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.employeeRegistrationModal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
openEmpGroupDialog() {
this.empGroupDialogRef = this.dialog.open(this.empGroupModal, {
width: '800px',
})
}
closeEmpGroupDialog() {
this.empGroupDialogRef.close()
}
openEmployeeListDialog() {
this.employeeListDialogRef = this.dialog.open(this.employeeListModal, {
width: '800px',
})
}
closeEmployeeListDialog() {
this.employeeListDialogRef.close()
}
openBu1Dialog() {
this.bu1DialogRef = this.dialog.open(this.bu1Modal, {
width: '800px',
})
}
closeBu1Dialog() {
this.bu1DialogRef.close()
}
openBu2Dialog() {
this.bu2DialogRef = this.dialog.open(this.bu2Modal, {
width: '800px',
})
}
closeBu2Dialog() {
this.bu2DialogRef.close()
}
openBu3Dialog() {
this.bu3DialogRef = this.dialog.open(this.bu3Modal, {
width: '800px',
})
}
closeBu3Dialog() {
this.bu3DialogRef.close()
}
openBu4Dialog() {
this.bu4DialogRef = this.dialog.open(this.bu4Modal, {
width: '800px',
})
}
closeBu4Dialog() {
this.bu4DialogRef.close()
}
openBu5Dialog() {
this.bu5DialogRef = this.dialog.open(this.bu5Modal, {
width: '800px',
})
}
closeBu5Dialog() {
this.bu5DialogRef.close()
}
openBu6Dialog() {
this.bu6DialogRef = this.dialog.open(this.bu6Modal, {
width: '800px',
})
}
closeBu6Dialog() {
this.bu6DialogRef.close()
}
openBu7Dialog() {
this.bu7DialogRef = this.dialog.open(this.bu7Modal, {
width: '800px',
})
}
closeBu7Dialog() {
this.bu7DialogRef.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -301,9 +412,9 @@ export class SubEmployeeRegistrationComponent { ...@@ -301,9 +412,9 @@ export class SubEmployeeRegistrationComponent {
}) })
} }
bu1ListFilter() { bu1ListFilter() {
return this.bu1.dataList.filter(x => x.bu1id.toLowerCase().includes(this.modal.search.toLowerCase()) || return this.bu1.dataList.filter(x => x.bu1id.toLowerCase().includes(this.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.modal.search.toLowerCase()) || x.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.modal.search.toLowerCase())) x.edesc.toLowerCase().includes(this.search.toLowerCase()))
} }
selectBu1(data?: Bu1Model) { selectBu1(data?: Bu1Model) {
this.employee.select.bu1 = new MyBu1Model(data) this.employee.select.bu1 = new MyBu1Model(data)
...@@ -334,9 +445,9 @@ export class SubEmployeeRegistrationComponent { ...@@ -334,9 +445,9 @@ export class SubEmployeeRegistrationComponent {
}) })
} }
bu2ListFilter() { bu2ListFilter() {
return this.bu2.dataList.filter(x => x.bu2id.toLowerCase().includes(this.modal.search.toLowerCase()) || return this.bu2.dataList.filter(x => x.bu2id.toLowerCase().includes(this.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.modal.search.toLowerCase()) || x.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.modal.search.toLowerCase())) x.edesc.toLowerCase().includes(this.search.toLowerCase()))
} }
selectBu2(data?: Bu2Model) { selectBu2(data?: Bu2Model) {
this.employee.select.bu2 = new MyBu2Model(data) this.employee.select.bu2 = new MyBu2Model(data)
...@@ -506,9 +617,9 @@ export class SubEmployeeRegistrationComponent { ...@@ -506,9 +617,9 @@ export class SubEmployeeRegistrationComponent {
}) })
} }
empGroupListFilter() { empGroupListFilter() {
return this.empGroup.dataList.filter(x => x.groupId.toLowerCase().includes(this.modal.search.toLowerCase()) || return this.empGroup.dataList.filter(x => x.groupId.toLowerCase().includes(this.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.modal.search.toLowerCase()) || x.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.modal.search.toLowerCase())) x.edesc.toLowerCase().includes(this.search.toLowerCase()))
} }
...@@ -533,40 +644,52 @@ export class SubEmployeeRegistrationComponent { ...@@ -533,40 +644,52 @@ export class SubEmployeeRegistrationComponent {
}) })
} }
employeeModalListFilter() { employeeModalListFilter() {
return this.employeeModal.dataList.filter(x => x.employeeId.toLowerCase().includes(this.modal.search.toLowerCase()) || return this.employeeModal.dataList.filter(x => x.employeeId.toLowerCase().includes(this.search.toLowerCase()) ||
x.fname.toLowerCase().includes(this.modal.search.toLowerCase()) || x.fname.toLowerCase().includes(this.search.toLowerCase()) ||
x.lname.toLowerCase().includes(this.modal.search.toLowerCase()) || x.lname.toLowerCase().includes(this.search.toLowerCase()) ||
x.position.tdesc.toLowerCase().includes(this.modal.search.toLowerCase())) x.position.tdesc.toLowerCase().includes(this.search.toLowerCase()))
} }
updateEmployeeList(type: 'add' | 'update' | 'delete') { updateEmployeeList(type: 'add' | 'update' | 'delete') {
this.employee.loading = true this.employee.loading = true
let body: any = this.employee.select let body: any = this.employee.select
switch (type) { if (type == 'delete') {
case 'delete': { if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
body = this.employee.dataList.filter(x => selectedKeys.includes(x.employeeId) && this.selectedItems.data.get(x.employeeId)).map(x => new MyEmployeeModel(x)) body = this.employee.dataList.filter(x => selectedKeys.includes(x.employeeId) && this.selectedItems.data.get(x.employeeId)).map(x => new MyEmployeeModel(x))
break;
}
} }
this.employeeService[type](body).subscribe({ Swal.fire({
next: response => { icon: 'question',
if (response.success) { title: 'แจ้งเตือน',
this.showAlert(response.message, 'success') text: type == 'delete' ? 'ยืนยันการลบข้อมูลหรือไม่' : 'ยืนยันการบันทึกข้อมูลหรือไม่',
this.search = "" showCancelButton: true,
this.getEmployeeList() confirmButtonText: type == 'delete' ? 'ลบข้อมูล' : 'บันทึกข้อมูล',
} else { }).then((result) => {
this.showAlert(response.message, 'error') if (result.isConfirmed) {
this.employee.loading = false this.employeeService[type](body).subscribe({
this.cdr.detectChanges() next: response => {
} if (response.success) {
}, error: error => { this.showAlert(response.message, 'success')
this.showAlert(error.message, 'error') this.search = ""
this.employee.loading = false this.getEmployeeList()
this.cdr.detectChanges() } else {
this.showAlert(response.message, 'error')
this.employee.loading = false
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.employee.loading = false
this.cdr.detectChanges()
}
})
} }
}) })
} }
selectEmployee(data?: EmployeeModel) { selectEmployee(data?: EmployeeModel) {
if (this.currentModal == 'update' && !data) { if (this.currentModal == 'update' && !data) {
...@@ -631,17 +754,21 @@ export class SubEmployeeRegistrationComponent { ...@@ -631,17 +754,21 @@ export class SubEmployeeRegistrationComponent {
} }
searchModalChange(dataList: any[]) { searchModalChange(dataList: any[]) {
this.modal.currentPage = 1 this.currentPage = 1
this.modal.page = Array.from({ length: Math.ceil(dataList.length / 10) }, (_, i) => i + 1); this.page = Math.ceil(dataList.length / this.pageSize);
} }
selectDataModal(target: { [key: string]: any }, field: string, data: any) { selectDataModal(target: { [key: string]: any }, field: string, data: any) {
target[field] = JSON.parse(JSON.stringify(data)) target[field] = JSON.parse(JSON.stringify(data))
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, icon: type,
positionClass: 'toast-top-right', title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
}) })
} }
......
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