Commit 31087b14 by Nattana Chaiyamat

กลุ่มพนักงาน

parent 466ca458
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
</span> </span>
</label> </label>
<div class="relative flex rounded-md w-1/2"> <div class="relative flex rounded-md w-1/2">
<input type="text" class="ti-form-input h-16" <input type="text" class="ti-form-input"
[class.!border-red]="currentModal=='add'&&checkPrimary()" [class.!border-red]="currentModal=='add'&&checkPrimary()"
[class.!bg-input-readonly]="currentModal=='edit'" [readonly]="currentModal=='edit'" [class.!bg-input-readonly]="currentModal=='edit'" [readonly]="currentModal=='edit'"
[(ngModel)]="bu7.select.bu7id"> [(ngModel)]="bu7.select.bu7id">
......
<div class="w-full min-height-50px mb-10px justify-between items-center"> <div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between"> <div class="flex justify-end">
<div class="flex"> <div class="px-1">
<div class="flex items-center"> <div class="relative shadow-md">
<input type="checkbox" class="ti-form-checkbox pointer-events-none" id="hs-default-checkbox" <input type="text" class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 "
[(ngModel)]="isDataListChecked"> placeholder="Search by No. or Name" [(ngModel)]="search">
<label for="hs-default-checkbox" class="text-sm text-gray-500 mx-2 pointer-events-none"> <div
{{numDataListChecked}} Selected</label> class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
</div> <i class="ri-search-line text-gray"></i>
<div class="mx-1 flex items-center">
<button (click)="isDataListCheckedAll = !isDataListCheckedAll;dataListCheckAll()" id='check-boxall'
class="focus:ring-2 focus:ring-primary rounded-sm flex item-center">
<i class="fs-l transition-all duration-200"
[ngClass]="{'ri-checkbox-multiple-line text-gray-500': !isDataListCheckedAll, 'ri-checkbox-multiple-fill text-primary': isDataListCheckedAll}"></i>
</button>
<label class="text-sm text-gray-500 ml-2" for="check-boxall">Select All</label>
</div>
</div>
<div class="flex justify-end">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 "
placeholder="Search by No. or Name" [(ngModel)]="search" (ngModelChange)="searchChange()">
<div
class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
<i class="ri-search-line text-gray"></i>
</div>
</div> </div>
</div> </div>
<div class="px-1"> </div>
<button type="button" <div class="px-1">
class=" h-45px ti-btn ti-btn bg-pink-500/10 text-pink-500 hover:text-white hover:bg-pink-500 ring-offset-white focus:ring-pink-500 dark:focus:ring-offset-white/10 h-10 m-0 shadow-md" <button type="button"
data-hs-overlay="#employee-group-unit-component-upload-modal" class=" h-45px ti-btn ti-btn bg-pink-500/10 text-pink-500 hover:text-white hover:bg-pink-500 ring-offset-white focus:ring-pink-500 dark:focus:ring-offset-white/10 h-10 m-0 shadow-md"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'"> data-hs-overlay="#employee-group-unit-component-upload-modal"
<i class="ti ti-file-plus"></i> (click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
import <i class="ti ti-file-plus"></i>
</button> import
</div> </button>
<div class="px-1"> </div>
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md" <div class="px-1">
data-hs-overlay="#employee-group-unit-component-page-modal" (click)="modalStatus='add';setData()"> <button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
<i class="ri-add-line"></i> data-hs-overlay="#employee-group-unit-component-page-modal"
Add (click)="currentModal='add';selectEmp_group()">
</button> <i class="ri-add-line"></i>
</div> Add
<div class="px-1"> </button>
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md" </div>
data-hs-overlay="#employee-group-unit-component-page-alert-modal" <div class="px-1">
(click)="modalStatus='deleteGroup';setData()"> <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
<i class="ri-delete-bin-6-line"></i> data-hs-overlay="#employee-group-unit-component-page-alert-modal"
Delete (click)="currentModal='delete';selectEmp_group()">
</button> <i class="ri-delete-bin-6-line"></i>
</div> Delete
<!-- <div class="px-1"> </button>
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-20px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div> </div>
</div> </div>
</div> </div>
<div class="page px-rem"> <div class="page px-rem">
<div class="overflow-auto shadow-md rounded-t-md"> <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="emp_group.dataList"
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover table-bordered"> [columns]="columns" [selectedItems]="selectedItems" modalName="#employee-group-unit-component-page-modal"
<thead> (sendSelectData)="currentModal='edit';selectEmp_group($event)" (sendSelectedItems)="onSelectItemChange($event)">
<tr> </app-datagrid-syncfution>
<ng-container
*ngFor="let item of ['','รหัสกลุ่มพนักงาน','รายละเอียด(ไทย) ','รายละเอียด(อังกฤษ)','การจัดการ']; let f = first; let l = last; let i = index">
<th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary !text-center">
<span class="font-size-12px font-weight-700">{{ item }}</span>
<div class="absolute top-1/2 transform -translate-y-1/2 right-0" *ngIf="!l&&!f">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="dataLoading">
<tr>
<td class="text-center" colspan="100%">
<div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1" role="status"
aria-label="loading">
<span class="sr-only">Loading...</span>
</div>
</td>
</tr>
</tbody>
<tbody *ngIf="!dataLoading&&!emp_groupListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!dataLoading&&emp_groupListFilter().length">
<tr
*ngFor="let item of emp_groupListFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center">
<input type="checkbox" class="ti-form-checkbox cursor-pointer"
id="checkbox-{{item.data.groupId}}" [(ngModel)]="item.check"
(ngModelChange)="dataListCheck()">
</td>
<td class="text-center">
<label for="checkbox-{{item.data.groupId}}">&nbsp;{{item.data.groupId}}</label>
</td>
<td>{{item.data.tdesc}}</td>
<td>{{item.data.edesc}}</td>
<td class="flex justify-center">
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1"
(click)="modalStatus='edit';setData(item.data)"
data-hs-overlay="#employee-group-unit-component-page-modal"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1"
(click)="modalStatus='delete';setData(item.data)"
data-hs-overlay="#employee-group-unit-component-page-alert-modal"></i> -->
</td>
</tr>
</tbody>
</table>
</div>
<app-pagination [totalItems]="emp_groupListFilter().length" [pageSize]="pageSize"
(pageChange)="currentPage = $event" (pageSizeChange)="pageSize = $event;currentPage = 1"></app-pagination>
</div> </div>
...@@ -129,7 +50,7 @@ ...@@ -129,7 +50,7 @@
<div class="max-h-full overflow-hidden ti-modal-content"> <div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header"> <div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary"> <h3 class="text-xxl font-bold text-primary">
{{modalStatus=='add'?'เพิ่มข้อมูลกลุ่มพนักงาน':'แก้ไขข้อมูลกลุ่มพนักงาน'}} {{currentModal=='add'?'เพิ่มข้อมูลกลุ่มพนักงาน':'แก้ไขข้อมูลกลุ่มพนักงาน'}}
</h3> </h3>
<div class="flex justify-end"> <div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger" <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
...@@ -143,7 +64,7 @@ ...@@ -143,7 +64,7 @@
<div class="flex justify-end" style="padding-right: 1rem;"> <div class="flex justify-end" style="padding-right: 1rem;">
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
(click)="clearEmp_group(modalStatus)"> (click)="selectEmp_group()">
<svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00" <svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00"
xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#595BEA" stroke-width="3.84" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#595BEA" stroke-width="3.84"
transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)"> transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
...@@ -159,32 +80,26 @@ ...@@ -159,32 +80,26 @@
Clear Clear
</button> </button>
</div> </div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div> </div>
</div> </div>
<div class="ti-modal-body "> <div class="ti-modal-body ">
<label for="input-label" class="ti-form-label mt-2rem">รหัสกลุ่มพนักงาน <label for="input-label" class="ti-form-label mt-2rem">รหัสกลุ่มพนักงาน
<span class="text-danger"> <span class="text-danger">
* *
<ng-container *ngIf="modalStatus=='add'&&checkPrimary()"> <ng-container *ngIf="currentModal=='add'&&checkPrimary()">
รหัสกลุ่มพนักงานซ้ำ รหัสกลุ่มพนักงานซ้ำ
</ng-container> </ng-container>
</span> </span>
</label> </label>
<input type="text" id="input-label" class="ti-form-input w-1/2" <input type="text" id="input-label" class="ti-form-input w-1/2"
[class.!border-red]="modalStatus=='add'&&checkPrimary()" [class.!border-red]="currentModal=='add'&&checkPrimary()"
[ngClass]="{'bg-input-readonly':modalStatus=='edit'}" [readonly]="modalStatus=='edit'" [ngClass]="{'bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="dataSelect.groupId"> [(ngModel)]="emp_group.select.groupId">
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียดกลุ่มพนักงาน (ไทย)<span <label for="detail_th" class="ti-form-label mt-2rem">รายละเอียดกลุ่มพนักงาน (ไทย)<span
class="text-danger">*</span></label> class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="dataSelect.tdesc"> <input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="emp_group.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดกลุ่มพนักงาน (อังกฤษ)</label> <label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดกลุ่มพนักงาน (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="dataSelect.edesc"> <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="emp_group.select.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-2"> <div class="flex justify-end mt-2rem mb-1rem space-x-2">
<button type="button" <button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10" class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
...@@ -193,8 +108,8 @@ ...@@ -193,8 +108,8 @@
</button> </button>
<button type="button" class="ti-btn ti-btn-success" <button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#employee-group-unit-component-page-alert-modal" data-hs-overlay="#employee-group-unit-component-page-alert-modal"
[class.ti-btn-disabled]="!dataSelect.groupId||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())" [class.ti-btn-disabled]="!emp_group.select.groupId||!emp_group.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!dataSelect.groupId||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())"> [disabled]="!emp_group.select.groupId||!emp_group.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </div>
...@@ -211,14 +126,14 @@ ...@@ -211,14 +126,14 @@
แจ้งเตือน แจ้งเตือน
</h3> </h3>
<div class="flex justify-end"> <div class="flex justify-end">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'"> <ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger" <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#employee-group-unit-component-page-modal"> data-hs-overlay="#employee-group-unit-component-page-modal">
<span class="sr-only">Close</span> <span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i> <i class="ti ti-circle-x fs-xxl"></i>
</button> </button>
</ng-container> </ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'"> <ng-container *ngIf="currentModal=='delete'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger" <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#employee-group-unit-component-page-alert-modal"> data-hs-overlay="#employee-group-unit-component-page-alert-modal">
<span class="sr-only">Close</span> <span class="sr-only">Close</span>
...@@ -229,21 +144,21 @@ ...@@ -229,21 +144,21 @@
</div> </div>
<div class="ti-modal-body "> <div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70"> <p class="mt-1 text-gray-800 dark:text-white/70">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'"> <ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
ยืนยันการบันทึกข้อมูลหรือไม่ ยืนยันการบันทึกข้อมูลหรือไม่
</ng-container> </ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'"> <ng-container *ngIf="currentModal=='delete'">
<ng-container *ngIf="numDataListChecked"> <ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่ ยืนยันการลบข้อมูลหรือไม่
</ng-container> </ng-container>
<ng-container *ngIf="!numDataListChecked"> <ng-container *ngIf="!numSelectItem()">
เลือกข้อมูลที่ต้องการลบ เลือกข้อมูลที่ต้องการลบ
</ng-container> </ng-container>
</ng-container> </ng-container>
</p> </p>
<div class="flex justify-end mt-2rem mb-1rem"> <div class="flex justify-end mt-2rem mb-1rem">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'"> <ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button" <button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10" class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#employee-group-unit-component-page-modal"> data-hs-overlay="#employee-group-unit-component-page-modal">
...@@ -254,7 +169,7 @@ ...@@ -254,7 +169,7 @@
บันทึกข้อมูล บันทึกข้อมูล
</a> </a>
</ng-container> </ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'"> <ng-container *ngIf="currentModal=='delete'">
<button type="button" <button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10" class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#employee-group-unit-component-page-alert-modal"> data-hs-overlay="#employee-group-unit-component-page-alert-modal">
...@@ -262,7 +177,7 @@ ...@@ -262,7 +177,7 @@
</button> </button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);" <a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#employee-group-unit-component-page-alert-modal" data-hs-overlay="#employee-group-unit-component-page-alert-modal"
(click)="deleteEmp_group()" *ngIf="numDataListChecked"> (click)="deleteEmp_group()" *ngIf="numSelectItem()">
ลบข้อมูล ลบข้อมูล
</a> </a>
</ng-container> </ng-container>
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { EmpGroupModel, MyEmpGroupModel } from 'src/app/shared/model/emp-group.model'; import { EmpGroupModel, MyEmpGroupModel } from 'src/app/shared/model/emp-group.model';
import { EmpGroupService } from 'src/app/shared/services/emp-group.service'; import { EmpGroupService } from 'src/app/shared/services/emp-group.service';
...@@ -19,20 +20,35 @@ export interface DataModel { ...@@ -19,20 +20,35 @@ export interface DataModel {
export class EmployeeGroupUnit implements OnInit { export class EmployeeGroupUnit implements OnInit {
currentPage = 1 currentPage = 1
pageSize = 10 pageSize = 10
selectedItems: string[] = []; currentModal: 'add' | 'edit' | 'delete' = 'add'
modalStatus: 'add' | 'edit' | 'delete' | 'deleteGroup' = 'add'
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
dataLoading = false emp_group: { loading: boolean, select: EmpGroupModel, dataList: EmpGroupModel[] } = { loading: false, select: new MyEmpGroupModel(), dataList: [] }
dataSelect: DataModel = { groupId: "", tdesc: "", edesc: "", companyId: "", checked: false }
emp_groupList: { check: boolean; data: DataModel & { checked?: boolean } }[] = []
emp_group: EmpGroupModel = new MyEmpGroupModel({})
search = ""
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
numDataListChecked = 0 columns: ColumnModel[] = [{
isDataListChecked = false field: "groupId",
isDataListCheckedAll = false headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['groupId', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
constructor(private empGroupService: EmpGroupService, constructor(private empGroupService: EmpGroupService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -55,7 +71,7 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -55,7 +71,7 @@ export class EmployeeGroupUnit implements OnInit {
} }
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.dataLoading = true this.emp_group.loading = true
this.fileService.uploadExcel(formData, 'mgroup').subscribe({ this.fileService.uploadExcel(formData, 'mgroup').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -63,11 +79,11 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -63,11 +79,11 @@ export class EmployeeGroupUnit implements OnInit {
this.getEmpGroupList() this.getEmpGroupList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false this.emp_group.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false this.emp_group.loading = false
} }
}) })
} }
...@@ -92,66 +108,58 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -92,66 +108,58 @@ export class EmployeeGroupUnit implements OnInit {
} }
getEmpGroupList() { getEmpGroupList() {
this.dataLoading = true this.emp_group.loading = true
this.selectedItems.data.clear()
this.empGroupService.getList().subscribe({ this.empGroupService.getList().subscribe({
next: response => { next: response => {
this.emp_groupList = response.map(x => ({ check: false, data: { groupId: x.groupId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId, checked: false } })) this.emp_group.dataList = response.map(x => {
this.dataLoading = false this.selectedItems.data.set(x.groupId, false)
this.searchChange() return new MyEmpGroupModel(x)
this.isDataListCheckedAll = false })
this.dataListCheckAll() this.selectedItems.key = 'groupId'
this.selectedItems.count = 0
this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
this.dataLoading = false this.emp_group.loading = false
console.error('Error fetching employee types:', error);
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
} }
searchChange() {
this.currentPage = 1 selectEmp_group(emp_group?: EmpGroupModel) {
this.page = Array.from({ length: Math.ceil(this.emp_groupListFilter().length / 10) }, (_, i) => i + 1); if (emp_group) {
this.dataListCheck() this.emp_group.select = new MyEmpGroupModel(emp_group)
} } else if (this.currentModal == 'add') {
emp_groupListFilter() { this.emp_group.select = new MyEmpGroupModel()
return this.emp_groupList.filter(x => { } else if (this.currentModal == 'edit') {
const data = x.data this.emp_group.select = new MyEmpGroupModel({ groupId: this.emp_group.select.groupId })
const match = data.groupId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase()); }
return match;
});
}
setData(data?: DataModel) {
this.dataSelect = JSON.parse(JSON.stringify(data || { groupId: "", tdesc: "", edesc: "", companyId: "" }));
} }
addEmp_group() { addEmp_group() {
const body = new MyEmpGroupModel({ groupId: this.dataSelect.groupId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }) this.emp_group.loading = true
this.dataLoading = true this.empGroupService.post(this.emp_group.select).subscribe({
this.empGroupService.post(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getEmpGroupList() this.getEmpGroupList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
} }
deleteEmp_group() { deleteEmp_group() {
let body: EmpGroupModel | EmpGroupModel[] = []; this.emp_group.loading = true
if (this.dataSelect.groupId) { const selectedKeys = Array.from(this.selectedItems.data.keys());
body = new MyEmpGroupModel({ groupId: this.dataSelect.groupId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }); const body = this.emp_group.dataList.filter(x => selectedKeys.includes(x.groupId) && this.selectedItems.data.get(x.groupId)).map(x => new MyEmpGroupModel(x))
} else {
body = this.emp_groupList.filter(x => x.check).map(x => new MyEmpGroupModel({ groupId: x.data.groupId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId }));
}
this.dataLoading = true
this.empGroupService.delete(body).subscribe({ this.empGroupService.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -159,35 +167,18 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -159,35 +167,18 @@ export class EmployeeGroupUnit implements OnInit {
this.getEmpGroupList(); this.getEmpGroupList();
} else { } else {
this.showAlert(response.message, 'error'); this.showAlert(response.message, 'error');
this.dataLoading = false this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}, },
error: error => { error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}); });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.emp_groupList.filter(x => {
const data = x.data
const match = data.groupId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.emp_groupListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.emp_groupList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000, timeOut: 3000,
...@@ -195,18 +186,17 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -195,18 +186,17 @@ export class EmployeeGroupUnit implements OnInit {
}) })
} }
clearEmp_group(modalStatus: string) { checkPrimary() {
if (modalStatus == 'add') { return this.emp_group.dataList.find(x => x.groupId == this.emp_group.select.groupId)
this.dataSelect.groupId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
} }
checkPrimary() { numSelectItem() {
return this.emp_groupList.find(x => x.data.groupId == this.dataSelect.groupId) const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.emp_group.dataList.filter(x => selectedKeys.includes(x.groupId) && this.selectedItems.data.get(x.groupId)).length
return num
}
onSelectItemChange(arg: any) {
this.selectedItems = arg
} }
} }
export interface EmpGroupModel{ export interface EmpGroupModel {
groupId: string; groupId: string;
tdesc: string; tdesc: string;
edesc: string; edesc: string;
...@@ -11,11 +11,11 @@ export class MyEmpGroupModel implements EmpGroupModel { ...@@ -11,11 +11,11 @@ export class MyEmpGroupModel implements EmpGroupModel {
tdesc: string; tdesc: string;
edesc: string; edesc: string;
companyId: string; companyId: string;
constructor(data: Partial<EmpGroupModel>) { constructor(data?: Partial<EmpGroupModel>) {
this.groupId = data.groupId || "" this.groupId = data?.groupId || ""
this.tdesc = data.tdesc || "" this.tdesc = data?.tdesc || ""
this.edesc = data.edesc || "" this.edesc = data?.edesc || ""
this.companyId = data.companyId || "" this.companyId = data?.companyId || ""
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment