import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ToastrService } from 'ngx-toastr'; import { MyPLModel, PLModel } from 'src/app/shared/model/pl.model'; import { PLService } from 'src/app/shared/services/pl.service'; @Component({ selector: 'app-employee-level', templateUrl: './employee-level.component.html', styleUrls: ['./employee-level.component.scss'] }) export class EmployeeLevel implements OnInit { @Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน'] @Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>(); activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น // ฟังก์ชันในการเปลี่ยนแท็บ changeTab(tab: { id: string, text: string }) { this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text]) this.activeTab = tab.id; } currentPage = 1 page = Array.from({ length: 1 }, (_, i) => i + 1); plList: PLModel[] = [] pl: PLModel = new MyPLModel({}) search = "" constructor(private plService: PLService, private toastr: ToastrService ) { } ngOnInit(): void { this.getPLList() } getPLList() { this.plService.getList().subscribe(response => { this.plList = response this.searchChange() }) } searchChange() { this.currentPage = 1 this.page = Array.from({ length: Math.ceil(this.plListFilter().length / 10) }, (_, i) => i + 1); } plListFilter() { return this.plList.filter(x => x.plId.toLowerCase().includes(this.search) || x.tdesc.toLowerCase().includes(this.search) || x.edesc.toLowerCase().includes(this.search)) } selectPL(pl: PLModel) { // this.showSuccess() this.pl = new MyPLModel(pl) } addPL() { // this.plService.post(this.pl).subscribe((response:any) => { // if (response.success) { // this.getPLList() // } // }) } deletePL(pl: PLModel) { // this.plService.delete(new MyPLModel(pl)).subscribe((response:any) => { // if (response.success) { // this.getPLList() // } // }) } showSuccessAdd() { this.toastr.success('บันทึกข้อมูลสำเร็จ', 'แจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } showSuccessEdit() { this.toastr.success('แก้ไขข้อมูลสำเร็จ', 'แจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } showSuccessDelete() { this.toastr.success('ลบข้อมูลสำเร็จ', 'แจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } }