import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ToastrService } from 'ngx-toastr'; import { MyPositionModel, PositionModel } from 'src/app/shared/model/position.model'; import { PositionService } from 'src/app/shared/services/position.service'; @Component({ selector: 'app-position-unit', templateUrl: './position-unit.component.html', styleUrls: ['./position-unit.component.scss'] }) export class PositionUnitComponent 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); positionList: PositionModel[] = [] position: PositionModel = new MyPositionModel({}) search = "" constructor(private positionService: PositionService, private toastr: ToastrService ) { } ngOnInit(): void { this.getPositionList() } getPositionList() { this.positionService.getList().subscribe(response => { this.positionList = response this.searchChange() }) } searchChange() { this.currentPage = 1 this.page = Array.from({ length: Math.ceil(this.positionListFilter().length / 10) }, (_, i) => i + 1); } positionListFilter() { return this.positionList.filter(x => x.positionId.toLowerCase().includes(this.search) || x.tdesc.toLowerCase().includes(this.search) || x.edesc.toLowerCase().includes(this.search)) } selectPosition(position: PositionModel) { // this.showSuccess() this.position = new MyPositionModel(position) } showSuccess() { this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } showSuccesssEdit() { this.toastr.success('เเก้ไขข้อมูลสำเร็จ', 'เเจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } showSuccessDelete() { this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } addPosition() { // this.positionService.post(this.position).subscribe((response:any) => { // if (response.success) { // this.getPositionList() // } // }) } deletePosition(position: PositionModel) { // this.positionService.delete(new MyPositionModel(position)).subscribe((response:any) => { // if (response.success) { // this.getPositionList() // } // }) } }