position-unit.component.ts 3.1 KB
Newer Older
1 2 3 4
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';
Natthaphat Pankiang committed
5 6 7 8 9 10

@Component({
  selector: 'app-position-unit',
  templateUrl: './position-unit.component.html',
  styleUrls: ['./position-unit.component.scss']
})
11 12
export class PositionUnitComponent implements OnInit {
  @Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน']
Natthaphat Pankiang committed
13 14 15 16 17
  @Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
  activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น

  // ฟังก์ชันในการเปลี่ยนแท็บ
  changeTab(tab: { id: string, text: string }) {
18
    this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text])
Natthaphat Pankiang committed
19 20
    this.activeTab = tab.id;
  }
21 22 23 24 25 26 27 28 29 30
  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()
31
  }
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  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)
50 51
  }

52
  showSuccess() {
53 54 55 56 57 58 59 60 61 62 63 64 65
    this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  showSuccesssEdit() {
    this.toastr.success('เเก้ไขข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  showSuccessDelete() {
    this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', {
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
      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()
    //   }
    // })
83 84
  }

Natthaphat Pankiang committed
85
}
86