Commit 2a30be7c by Nattana Chaiyamat

syncfution ทะเบียนส่วน

parent 307b800b
......@@ -149,22 +149,21 @@ export class DepartmentRegisterComponent implements OnInit {
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
console.log(" 🐒 result:", result)
// this.bu1.loading = true
// this.bu1Service.post(this.bu1.select).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu1List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu1.loading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu1.loading = false
// }
// })
this.bu1.loading = true
this.bu1Service.post(this.bu1.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu1List()
} else {
this.showAlert(response.message, 'error')
this.bu1.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu1.loading = false
}
})
}
})
}
......@@ -183,24 +182,23 @@ export class DepartmentRegisterComponent implements OnInit {
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
console.log(" 🐒 result:", result)
// this.bu1.loading = true
// const selectedKeys = Array.from(this.selectedItems.data.keys());
// const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
// this.bu1Service.delete(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu1List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu1.loading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu1.loading = false
// }
// })
this.bu1.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
this.bu1Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu1List()
} else {
this.showAlert(response.message, 'error')
this.bu1.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu1.loading = false
}
})
}
});
}
......
<div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between">
<div class="flex">
<div class="flex items-center">
<input type="checkbox" class="ti-form-checkbox pointer-events-none" id="hs-default-checkbox"
[(ngModel)]="isDataListChecked">
<label for="hs-default-checkbox" class="text-sm text-gray-500 mx-2 pointer-events-none">
{{numDataListChecked}} Selected</label>
</div>
<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" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="bu3Table.search" (ngModelChange)="onBu3TableSearchChange()">
<div class="flex justify-end">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="search">
<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
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 class="px-1">
<button type="button"
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"
data-hs-overlay="#section-registration-upload-modal"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ti ti-file-plus"></i>
import
</button>
</div>
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
(click)="currentModal='add';selectBu2();selectBu3()"
data-hs-overlay="#section-registration-modal-add">
<i class="ri-add-line"></i>
Add
</button>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-info h-45px m-0 shadow-md">
<i class="ri-printer-line"></i>
Print
</button>
</div> -->
<div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
(click)="currentModal='delete'" data-hs-overlay="#section-registration-alert-delete-modal">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</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 class="px-1">
<button type="button"
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"
data-hs-overlay="#section-registration-upload-modal"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ti ti-file-plus"></i>
import
</button>
</div>
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
(click)="currentModal='add';selectBu2();selectBu3()" data-hs-overlay="#section-registration-modal">
<i class="ri-add-line"></i>
Add
</button>
</div>
<div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
(click)="currentModal='delete'" data-hs-overlay="#section-registration-alert-delete-modal">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</div>
</div>
</div>
<div class="page px-rem">
<div class="overflow-auto shadow-md rounded-t-md">
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover table-bordered">
<thead>
<tr>
<ng-container
*ngFor="let item of ['','รหัสส่วน','รายละเอียดส่วน (ไทย)','รายละเอียดส่วน (อังกฤษ)','การจัดการ']; let f = first; let l = last">
<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="!f&&!l">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="bu3ListLoading">
<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="!bu3ListLoading&&!filterBu3Table().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!bu3ListLoading&&filterBu3Table().length">
<tr
*ngFor="let item of filterBu3Table() | slice:((bu3Table.currentPage-1) * bu3Table.pageSize) : (((bu3Table.currentPage-1) * bu3Table.pageSize) + bu3Table.pageSize);let i = index">
<td class="text-center">
<input type="checkbox" class="ti-form-checkbox cursor-pointer" id="checkbox-{{item.data.bu3id}}"
[(ngModel)]="item.check" (ngModelChange)="dataListCheck()">
</td>
<td class="text-center">{{item.data.bu3id}}</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)="selectBu3(item.data);currentModal='edit'"
data-hs-overlay="#section-registration-modal-edit"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1" currentModal='delete'
(click)="selectBu3(item)" data-hs-overlay="#section-registration-alert-delete-modal"></i> -->
</td>
</tr>
</tbody>
</table>
</div>
<app-pagination [totalItems]="filterBu3Table().length" [pageSize]="bu3Table.pageSize"
(pageChange)="bu3Table.currentPage = $event"
(pageSizeChange)="bu3Table.pageSize = $event;bu3Table.currentPage = 1"></app-pagination>
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu3.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#section-registration-modal"
(sendSelectData)="currentModal='edit';selectBu3($event)" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution>
</div>
<div id="section-registration-modal-add" class="hs-overlay hidden ti-modal">
<div id="section-registration-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]">
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
เพิ่มข้อมูลทะเบียนส่วน
<ng-container *ngIf="currentModal=='add'">
เพิ่มข้อมูลทะเบียนส่วน
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
แก้ไขข้อมูลทะเบียนส่วน
</ng-container>
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal-add">
data-hs-overlay="#section-registration-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
......@@ -165,12 +87,6 @@
Clear
</button>
</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 class="ti-modal-body">
......@@ -198,143 +114,32 @@
</div>
</div>
<label class="ti-form-label mt-2rem">ส่วน
<span class="text-danger">*
<span class="text-danger">*
<ng-container *ngIf="currentModal=='add'&&checkPrimary()">
ส่วนซ้ำ
</ng-container>
</span>
</label>
<div class="relative flex rounded-md w-1/2">
<input type="text" class="ti-form-input h-16"
[class.!border-red]="currentModal=='add'&&checkPrimary()" [(ngModel)]="bu3.bu3id">
<!-- <input type="text" id="hs-leading-button-add-on-with-icon-and-button"
name="hs-leading-button-add-on-with-icon-and-button"
class="ti-form-input rounded-sm ltr:rounded-r-sm rtl:rounded-l-sm focus:z-10"
style="padding-right: 3.5rem;" [(ngModel)]="bu3.bu3id" (ngModelChange)="bu3idChange()">
<div
class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
<button type="button" class="flex items-center text-red-500" (click)="selectBu3()">
<i class="ti ti-circle-x cursor-pointer"></i>
</button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70"
data-hs-overlay="#section-registration-bu3-table-modal">
<i class="ri-search-line cursor-pointer text-gray"></i>
</button>
</div> -->
<input type="text" class="ti-form-input" [class.!bg-input-readonly]="currentModal=='edit'"
[required]="currentModal=='edit'" [class.!border-red]="currentModal=='add'&&checkPrimary()"
[(ngModel)]="bu3.select.bu3id">
</div>
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียดส่วน (ไทย)<span
class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu3.tdesc">
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu3.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วน (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu3.edesc">
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu3.select.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-4">
<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"
data-hs-overlay="#section-registration-modal-add">
data-hs-overlay="#section-registration-modal">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#section-registration-alert-modal"
[class.ti-btn-disabled]="!bu2.bu2id||!bu3.bu3id||!bu3.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!bu2.bu2id||!bu3.bu3id||!bu3.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
</div>
</div>
</div>
</div>
<div id="section-registration-modal-edit" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]">
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
แก้ไขข้อมูลทะเบียนส่วน
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal-edit">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-center">
<div class="flex justify-end" style="padding-right: 1rem;">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
(click)="selectBu2();bu3.tdesc='';bu3.edesc=''">
<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"
transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M15 49A24 24 0 0 1 32 8"></path>
<path d="M49 15a24 24 0 0 1-17 41"></path>
<polyline points="15.03 40 15.03 48.97 8 48.97"></polyline>
<polyline points="48.97 24 48.97 15.03 56 15.03"></polyline>
</g>
</svg>
Clear
</button>
</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 class="ti-modal-body">
<label for="hs-trailing-button-add-on-with-icon" class="ti-form-label">อยู่ภายใต้หน่วยงาน<span
class="text-danger">*</span></label>
<div class="flex">
<div class="relative flex rounded-md">
<input type="text" id="hs-leading-button-add-on-with-icon-and-button"
name="hs-leading-button-add-on-with-icon-and-button"
class="ti-form-input rounded-sm ltr:rounded-r-sm rtl:rounded-l-sm focus:z-10" readonly
style="padding-right: 3.5rem;" [(ngModel)]="bu2.bu2id" (ngModelChange)="bu2idChange()">
<div
class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
<button type="button" class="flex items-center text-red-500" (click)="selectBu2()">
<i class="ti ti-circle-x cursor-pointer"></i>
</button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70"
data-hs-overlay="#section-registration-bu2-table-modal">
<i class="ri-search-line cursor-pointer text-gray"></i>
</button>
</div>
</div>
<div class="flex rounded-md w-1/2 pl-1rem">
<input type="text" id="input-label" class="ti-form-input w-full pr-10 bg-input-readonly"
readonly [value]="bu2.tdesc">
</div>
</div>
<label for="input-label" class="ti-form-label mt-2rem">ส่วน<span class="text-danger">*</span></label>
<div class="sm:grid grid-cols-2 gap-1">
<div class="relative w-full">
<input type="text" id="input-label" class="ti-form-input w-full pr-10 bg-input-readonly"
readonly [value]="bu3.bu3id">
</div>
</div>
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียดส่วน (ไทย)<span
class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu3.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วน (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu3.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-4 ">
<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"
data-hs-overlay="#section-registration-modal-edit">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#section-registration-alert-edit-modal"
[class.ti-btn-disabled]="!bu2.bu2id||!bu3.bu3id||!bu3.tdesc"
[disabled]="!bu2.bu2id||!bu3.bu3id||!bu3.tdesc">
[class.ti-btn-disabled]="!bu2.bu2id||!bu3.select.bu3id||!bu3.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!bu2.bu2id||!bu3.select.bu3id||!bu3.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
......@@ -351,15 +156,8 @@
ข้อมูลทะเบียนเเผนก
</h3>
<div class="flex justify-end">
<button *ngIf="currentModal=='add'" type="button"
class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal-add">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
<button *ngIf="currentModal=='edit'" type="button"
class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal-edit">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
......@@ -404,30 +202,16 @@
</tr>
</tbody>
<tbody *ngIf="filterBu2Modal().length">
<ng-container *ngIf="currentModal=='add'">
<tr *ngFor="let item of filterBu2Modal() | slice:((bu2Modal.currentPage-1) * bu2Modal.pageSize) : (((bu2Modal.currentPage-1) * bu2Modal.pageSize) + bu2Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu2(item)"
data-hs-overlay="#section-registration-modal-add">
<td class="flex justify-center">
{{((bu2Modal.currentPage-1) * bu2Modal.pageSize)+(i+1)}}
</td>
<td>{{item.bu2id}}</td>
<td>{{item.tdesc}}</td>
<td>{{item.edesc}}</td>
</tr>
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
<tr *ngFor="let item of filterBu2Modal() | slice:((bu2Modal.currentPage-1) * bu2Modal.pageSize) : (((bu2Modal.currentPage-1) * bu2Modal.pageSize) + bu2Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu2(item)"
data-hs-overlay="#section-registration-modal-edit">
<td class="flex justify-center">
{{((bu2Modal.currentPage-1) * bu2Modal.pageSize)+(i+1)}}
</td>
<td>{{item.bu2id}}</td>
<td>{{item.tdesc}}</td>
<td>{{item.edesc}}</td>
</tr>
</ng-container>
<tr *ngFor="let item of filterBu2Modal() | slice:((bu2Modal.currentPage-1) * bu2Modal.pageSize) : (((bu2Modal.currentPage-1) * bu2Modal.pageSize) + bu2Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu2(item)"
data-hs-overlay="#section-registration-modal">
<td class="flex justify-center">
{{((bu2Modal.currentPage-1) * bu2Modal.pageSize)+(i+1)}}
</td>
<td>{{item.bu2id}}</td>
<td>{{item.tdesc}}</td>
<td>{{item.edesc}}</td>
</tr>
</tbody>
</table>
</div>
......@@ -435,14 +219,9 @@
(pageChange)="bu2Modal.currentPage = $event"
(pageSizeChange)="bu2Modal.pageSize = $event;bu2Modal.currentPage = 1"></app-pagination>
<div class="flex justify-end mt-2rem mb-1rem space-x-4">
<button type="button" *ngIf="currentModal=='add'"
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="#section-registration-modal-add">
ย้อนกลับ
</button>
<button type="button" *ngIf="currentModal=='edit'"
<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"
data-hs-overlay="#section-registration-modal-edit">
data-hs-overlay="#section-registration-modal">
ย้อนกลับ
</button>
</div>
......@@ -461,7 +240,7 @@
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal-add">
data-hs-overlay="#section-registration-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
......@@ -475,7 +254,7 @@
<div class="flex justify-end mt-2rem mb-1rem">
<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"
data-hs-overlay="#section-registration-modal-add">
data-hs-overlay="#section-registration-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
......@@ -488,41 +267,6 @@
</div>
</div>
<div id="section-registration-alert-edit-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center">
<div class="max-h-full overflow-hidden ti-modal-content w-full">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
แจ้งเตือน
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#section-registration-modal-edit">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70">
ยืนยันการเเก้ไขข้อมูลหรือไม่
</p>
<div class="flex justify-end mt-2rem mb-1rem">
<button type="button" *ngIf="currentModal=='edit'"
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="#section-registration-modal-edit">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#section-registration-alert-edit-modal" (click)="addBu3()">
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="section-registration-alert-delete-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center">
......@@ -541,10 +285,10 @@
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70">
<ng-container *ngIf="numDataListChecked">
<ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numDataListChecked">
<ng-container *ngIf="!numSelectItem()">
เลือกข้อมูลที่ต้องการลบ
</ng-container>!
</p>
......@@ -557,7 +301,7 @@
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#section-registration-alert-delete-modal" (click)="deleteBu3()"
*ngIf="numDataListChecked">
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
......@@ -17,25 +18,10 @@ interface table {
styleUrls: ['./section-registration.component.scss']
})
export class SectionRegistrationComponent implements OnInit {
bu3List: { check: boolean, data: Bu3Model }[] = []
bu3ListLoading = false
bu3: Bu3Model = new MyBu3Model()
bu3Table: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu3: { loading: boolean, select: Bu3Model, dataList: Bu3Model[] } = { loading: false, select: new MyBu3Model(), dataList: [] }
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
bu3Modal: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu2List: Bu2Model[] = []
bu2: Bu2Model = new MyBu2Model()
bu2Modal: table = {
......@@ -46,9 +32,30 @@ export class SectionRegistrationComponent implements OnInit {
}
currentModal: 'add' | 'edit' | 'delete' = "add"
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
columns: ColumnModel[] = [{
field: "bu3id",
headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['bu3id', '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 bu3Service: Bu3Service,
private bu2Service: Bu2Service,
private toastr: ToastrService,
......@@ -73,7 +80,7 @@ export class SectionRegistrationComponent implements OnInit {
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.bu3ListLoading = true
this.bu3.loading = true
this.fileService.uploadExcel(formData, 'mbu3').subscribe({
next: response => {
if (response.success) {
......@@ -81,11 +88,11 @@ export class SectionRegistrationComponent implements OnInit {
this.getBu3List()
} else {
this.showAlert(response.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
})
}
......@@ -110,80 +117,62 @@ export class SectionRegistrationComponent implements OnInit {
}
getBu3List() {
this.bu3ListLoading = true
this.bu3.loading = true
this.bu3Service.getList().subscribe({
next: response => {
this.bu3List = response.map(x => ({ check: false, data: new MyBu3Model(x) }))
this.bu3ListLoading = false
this.onBu3TableSearchChange()
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.bu3.dataList = response.map(x => {
this.selectedItems.data.set(x.bu3id, false)
return new MyBu3Model(x)
})
this.selectedItems.key = 'bu3id'
this.selectedItems.count = 0
this.bu3.loading = false
this.cdr.detectChanges()
}, error: error => {
this.bu3ListLoading = false
this.bu3.loading = false
this.cdr.detectChanges()
}
})
}
onBu3TableSearchChange() {
this.bu3Table.currentPage = 1
this.bu3Table.page = Array.from({ length: Math.ceil(this.filterBu3Table().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
filterBu3Table() {
return this.bu3List.filter(x => {
const data = x.data
return data.bu3id.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu3Table.search.toLowerCase())
})
}
selectBu3(bu3?: Bu3Model) {
this.bu3 = new MyBu3Model(bu3)
if (bu3) {
this.bu3.select = new MyBu3Model(bu3)
} else if (this.currentModal == 'add') {
this.bu3.select = new MyBu3Model()
} else if (this.currentModal == 'edit') {
this.bu3.select = new MyBu3Model({ bu3id: this.bu3.select.bu3id })
}
this.selectBu2()
if (this.bu3.parent) {
this.bu2Service.getById(this.bu3.parent).subscribe(response => {
if (this.bu3.select.parent) {
this.bu2Service.getById(this.bu3.select.parent).subscribe(response => {
this.bu2 = new MyBu2Model(response)
this.cdr.detectChanges()
})
}
}
// bu3idChange() {
// const bu3 = this.bu3List.find(x => x.bu3id == this.bu3.bu3id)
// this.selectBu3(bu3 || new MyBu3Model({ bu3id: this.bu3.bu3id }))
// }
onBu3ModalSearchChange() {
this.bu3Modal.currentPage = 1
this.bu3Modal.page = Array.from({ length: Math.ceil(this.filterBu3Modal().length / 10) }, (_, i) => i + 1);
}
filterBu3Modal() {
return this.bu3List.filter(x => {
const data = x.data
return data.bu3id.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu3Table.search.toLowerCase())
})
}
addBu3() {
this.bu3ListLoading = true
this.bu3Service.post({ ...this.bu3, parent: this.bu2.bu2id }).subscribe({
this.bu3.loading = true
this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu3List()
} else {
this.showAlert(response.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
})
}
deleteBu3() {
this.bu3ListLoading = true
const body = this.bu3List.filter(x => x.check).map(x => new MyBu3Model(x.data))
this.bu3.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x))
this.bu3Service.delete(body).subscribe({
next: response => {
if (response.success) {
......@@ -191,11 +180,11 @@ export class SectionRegistrationComponent implements OnInit {
this.getBu3List()
} else {
this.showAlert(response.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3ListLoading = false
this.bu3.loading = false
}
})
}
......@@ -230,21 +219,20 @@ export class SectionRegistrationComponent implements OnInit {
})
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.filterBu3Table().forEach(x => x.check = selectAll);
this.dataListCheck();
checkPrimary() {
return this.bu3.dataList.find(x => x.bu3id == this.bu3.select.bu3id)
}
dataListCheck() {
const dataCheck = this.filterBu3Table();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.bu3List.filter(x => x.check).length
this.isDataListChecked = Boolean(this.numDataListChecked)
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).length
return num
}
checkPrimary() {
return this.bu3List.find(x => x.data.bu3id == this.bu3.bu3id)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
}
export const environment = {
production: true,
firebase: {
apiKey: '********************************',
authDomain: '********************************',
projectId: '********************************',
storageBucket: '********************************',
messagingSenderId: '********************************',
appId: '********************************',
measurementId: '********************************',
},
};
baseUrl: window.location.origin + '/api',
}
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