employee-group-unit.component.ts 4.78 KB
Newer Older
1 2 3 4
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { EmpGroupModel, MyEmpGroupModel } from 'src/app/shared/model/emp_group.model';
import { EmpGroupService } from 'src/app/shared/services/emp_group.service';
LAPTOP-CV4JFSHE\kantavee committed
5 6 7 8 9 10

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

16 17 18 19
  currentPage = 1
  page = Array.from({ length: 1 }, (_, i) => i + 1);
  emp_groupList: EmpGroupModel[] = []
  emp_group: EmpGroupModel = new MyEmpGroupModel({})
20 21
  search = "" 
  
22 23 24
  constructor(private EmpGroupService: EmpGroupService,
    private toastr: ToastrService
  ) { }
25 26 27 28 29 30 31 32 33

  // ฟังก์ชันในการเปลี่ยนแท็บ
  changeTab(tab: { id: string, text: string }) {
    this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text])
    this.activeTab = tab.id;
  }



34 35 36 37
  ngOnInit(): void {
    this.getEmpGroupList()
  }

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  modalOptions: {
    [nameModal: string]: {  // ชื่อตรวจสอบการเปิดปิด
      isModalOpen: boolean; // เปิด/ปิด 
      modalSize: string; // ขนาดของ Modal  (s,m,l,vw10-vw100 )
      backdropClose: boolean; // (คลิก Backdrop แล้ว true ปิด false ไม่ปิด )
    }
  } = {
      "add": {
        isModalOpen: false,
        modalSize: 'm',
        backdropClose: true,
      },
      "edit": {
        isModalOpen: false,
        modalSize: 'm',
        backdropClose: true,
54 55 56 57 58
      },
      "upload":{
        isModalOpen: false,
        modalSize: 'm',
        backdropClose: true,
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
      }
    }

  openModal(name: string, size: string, closeOnBackdrop?: boolean) {
    this.modalOptions[name].modalSize = size;
    this.modalOptions[name].backdropClose = closeOnBackdrop || false;
    this.modalOptions[name].isModalOpen = true;
    document.body.style.overflow = 'hidden'; // ล็อก Scroll
  }

  closeModal(name: string) {
    this.modalOptions[name].isModalOpen = false;
    // ตรวจสอบว่ามี Modal อื่นเปิดอยู่หรือไม่
    if (!this.isAnyModalOpen()) {
      document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว
    }
  }

  isAnyModalOpen(): boolean {
    // Logic ตรวจสอบว่า Modal อื่นยังเปิดอยู่หรือไม่
    return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // หากไม่มี Modal อื่นเปิด
  }
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  getEmpGroupList() {
    this.EmpGroupService.getList().subscribe(response => {
      this.emp_groupList = response
      this.searchChange()
    })
  }
  searchChange() {
    this.currentPage = 1
    this.page = Array.from({ length: Math.ceil(this.emp_groupListFilter().length / 10) }, (_, i) => i + 1);
  }
  emp_groupListFilter() {
    return this.emp_groupList.filter(x => x.groupId.toLowerCase().includes(this.search) ||
      x.tdesc.toLowerCase().includes(this.search) ||
      x.edesc.toLowerCase().includes(this.search))
  }
96

97 98 99 100 101 102
  selectEmp_group(emp_group: EmpGroupModel) {
    // this.showSuccess()
    this.emp_group = new MyEmpGroupModel(emp_group)
  }

  showSuccess() {
103 104 105 106 107 108 109 110 111 112 113 114 115
    this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  showSuccesssEdit() {
    this.toastr.success('เเก้ไขข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  showSuccessDelete() {
    this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', {
116 117 118 119 120 121 122 123 124 125 126 127
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  addEmp_group() {
    // this.emp_groupService.post(this.emp_group).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getemp_groupList()
    //   }
    // })
  }
  deleteEmp_group(emp_group: EmpGroupModel) {
128

129 130 131 132 133 134 135
    // this.emp_groupService.delete(new MyEmpGroupModel(emp_group)).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getemp_groupList()
    //   }
    // })
  }

136

LAPTOP-CV4JFSHE\kantavee committed
137
}