employee-level.component.ts 2.87 KB
Newer Older
1 2 3 4
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';
5 6 7 8 9 10

@Component({
  selector: 'app-employee-level',
  templateUrl: './employee-level.component.html',
  styleUrls: ['./employee-level.component.scss']
})
11
export class EmployeeLevel implements OnInit {
12 13 14 15 16 17 18 19 20
  @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;
  }
21 22 23 24 25 26 27 28 29 30
  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()
31
  }
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  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)
50
  }
51 52 53 54 55 56 57 58 59 60 61 62 63
  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()
    //   }
    // })
64
  }
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  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',
    });
  }
83
}