Commit 2f8519d6 by Nakarin Luankla

UPDATE แก้ model ข้อมูลลักษณะงาน

parent f3407a40
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { EmpTypeModel, MyEmpTypeModel } from 'src/app/shared/model/employee-type.model';
import { EmpTypeService } from 'src/app/shared/services/employee-type.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
@Component({
selector: 'app-employee-categories',
templateUrl: './employee-categories.component.html',
......@@ -40,15 +42,29 @@ export class EmployeeCategories {
ignoreCase: false
}
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("employeeCategoriesModal") employeeCategoriesModal: any;
dialogRef: any
constructor(private empTypeService: EmpTypeService,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getEmpTypeList()
}
openDialog() {
this.dialogRef = this.dialog.open(this.employeeCategoriesModal, {
width: '500px',
height: '500px'
})
}
closeDialog() {
this.dialogRef.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
......@@ -132,12 +148,21 @@ export class EmployeeCategories {
addEmp_type() {
this.emp_type.loading = true
this.empTypeService.post(this.emp_type.select).subscribe({
next: response => {
if (response.success) {
Swal.fire({
icon: 'warning',
title: 'แจ้งเตือน',
text: 'คุณต้องการเพิ่มประเภทพนักงานหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.emp_type.loading = true
this.empTypeService.post(this.emp_type.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getEmpTypeList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.emp_type.loading = false
......@@ -146,14 +171,28 @@ export class EmployeeCategories {
}, error: error => {
this.showAlert(error.message, 'error')
this.emp_type.loading = false
this.cdr.detectChanges()
this.cdr.detectChanges()
}
})
}
})
}
deleteEmp_type() {
this.emp_type.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'warning',
title: 'แจ้งเตือน',
text: 'คุณต้องการลบประเภทพนักงานทั้งหมดหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.emp_type.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.emp_type.dataList.filter(x => selectedKeys.includes(x.codeId) && this.selectedItems.data.get(x.codeId)).map(x => new MyEmpTypeModel(x))
this.empTypeService.delete(body).subscribe({
next: response => {
......@@ -168,16 +207,21 @@ export class EmployeeCategories {
}, error: error => {
this.showAlert(error.message, 'error')
this.emp_type.loading = false
this.cdr.detectChanges()
this.cdr.detectChanges()
}
})
}
})
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
Swal.fire({
icon: type,
title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
})
}
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { MyPLModel, PLModel } from 'src/app/shared/model/pl.model';
import { FileService } from 'src/app/shared/services/file.service';
import { PLService } from 'src/app/shared/services/pl.service';
import Swal from 'sweetalert2';
@Component({
selector: 'app-employee-level',
templateUrl: './employee-level.component.html',
......@@ -41,16 +43,30 @@ export class EmployeeLevel implements OnInit {
ignoreCase: false
}
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("employeeLevelModal") employeeLevelModal: any;
dialogRef: any
constructor(private plService: PLService,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getPLList()
}
openDialog() {
this.dialogRef = this.dialog.open(this.employeeLevelModal, {
width: '500px',
height: '500px'
})
}
closeDialog() {
this.dialogRef.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
......@@ -132,11 +148,20 @@ export class EmployeeLevel implements OnInit {
}
addPL() {
this.pl.loading = true
this.plService.post(this.pl.select).subscribe({
next: response => {
if (response.success) {
Swal.fire({
icon: 'warning',
title: 'แจ้งเตือน',
text: 'คุณต้องการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.pl.loading = true
this.plService.post(this.pl.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.closeDialog()
this.getPLList()
} else {
this.showAlert(response.message, 'error')
......@@ -146,12 +171,26 @@ export class EmployeeLevel implements OnInit {
}, error: error => {
this.showAlert(error.message, 'error')
this.pl.loading = true
this.cdr.detectChanges()
this.cdr.detectChanges()
}
})
}
})
}
deletePL() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.pl.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.pl.dataList.filter(x => selectedKeys.includes(x.plId) && this.selectedItems.data.get(x.plId)).map(x => new MyPLModel(x))
......@@ -169,15 +208,20 @@ export class EmployeeLevel implements OnInit {
this.showAlert(error.message, 'error')
this.pl.loading = true
this.cdr.detectChanges()
}
})
}
})
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
Swal.fire({
icon: type,
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