Commit 9fc248ab by Nakarin Luankla

UPDATE ทะเบียนบริษัท > หน่วยธุรกิจ เปลี่ยน modal

parent f267a8cc
...@@ -23,14 +23,14 @@ ...@@ -23,14 +23,14 @@
</div> </div>
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
(click)="currentModal='add';selectBu6();selectBu7()" data-hs-overlay="#sub-department-four-modal"> (click)="currentModal='add';selectBu6();selectBu7();openDialog()" >
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md" <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
(click)="currentModal='delete'" data-hs-overlay="#sub-department-four-alert-delete-modal"> (click)="currentModal='delete';deleteBu7();">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -40,55 +40,25 @@ ...@@ -40,55 +40,25 @@
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu7.dataList" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu7.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#sub-department-four-modal" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectBu7($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';selectBu7($event);openDialog()" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<ng-template #subDepartmentFourModal let-modal>
<h3 mat-dialog-title>
<div id="sub-department-four-modal" class="hs-overlay hidden ti-modal"> {{currentModal=='add'?'เพิ่มข้อมูลทะเบียนส่วนย่อย 4':'แก้ไขข้อมูลทะเบียนส่วนย่อย 4'}}
<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'">
เพิ่มข้อมูลทะเบียนส่วนย่อย 4
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
แก้ไขข้อมูลทะเบียนส่วนย่อย 4
</ng-container>
</h3> </h3>
<div class="flex justify-end"> <div class="w-full flex justify-end mb-1rem">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger" <div class="absolute flex">
data-hs-overlay="#sub-department-four-modal">
<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"> <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)="selectBu6();selectBu7()">
(click)="selectBu6();selectBu7()"> <i class="ti ti-eraser text-base"></i>
<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 Clear
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<div class="ti-modal-body"> <mat-dialog-content>
<label class="ti-form-label ">อยู่ภายใต้หน่วยงาน<span class="text-danger">*</span></label> <label class="ti-form-label ">อยู่ภายใต้หน่วยงาน<span class="text-danger">*</span></label>
<div class="flex"> <div class="flex">
<div class="relative flex rounded-md"> <div class="relative flex rounded-md">
...@@ -101,8 +71,7 @@ ...@@ -101,8 +71,7 @@
<button type="button" class="flex items-center text-red-500" (click)="selectBu6()"> <button type="button" class="flex items-center text-red-500" (click)="selectBu6()">
<i class="ti ti-circle-x cursor-pointer"></i> <i class="ti ti-circle-x cursor-pointer"></i>
</button> </button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70" <button type="button" class="flex items-center text-gray-500 dark:text-white/70" (click)="openDialogBu6()">
data-hs-overlay="#sub-department-four-bu6-table-modal">
<i class="ri-search-line cursor-pointer text-gray"></i> <i class="ri-search-line cursor-pointer text-gray"></i>
</button> </button>
</div> </div>
...@@ -130,39 +99,27 @@ ...@@ -130,39 +99,27 @@
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu7.select.tdesc"> <input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu7.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)]="bu7.select.edesc"> <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu7.select.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" <mat-dialog-actions align="end">
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" <button type="button" mat-button [mat-dialog-close]
data-hs-overlay="#sub-department-four-modal"> 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">
ย้อนกลับ ย้อนกลับ
</button> </button>
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#sub-department-four-alert" <button type="button" class="ti-btn ti-btn-success" mat-button (click)="addBu7();"
[class.ti-btn-disabled]="!bu6.bu6id||!bu7.select.bu7id||!bu7.select.tdesc||(currentModal=='add'&&checkPrimary())" [class.ti-btn-disabled]="!bu6.bu6id||!bu7.select.bu7id||!bu7.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]=" !bu6.bu6id||!bu7.select.bu7id||!bu7.select.tdesc||(currentModal=='add' &&checkPrimary())"> [disabled]=" !bu6.bu6id||!bu7.select.bu7id||!bu7.select.tdesc||(currentModal=='add' &&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="sub-department-four-bu6-table-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out lg:!max-w-4xl lg:w-full m-3 lg:!mx-auto"> <ng-template #subDepartmentFourModalBu6 let-modal>
<div class="max-h-full overflow-hidden ti-modal-content"> <h3 mat-dialog-title>
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
ข้อมูลทะเบียนส่วนย่อย 3 ข้อมูลทะเบียนส่วนย่อย 3
</h3> </h3>
<div class="flex justify-end"> <mat-dialog-content>
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#sub-department-four-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body">
<div class="flex justify-end pb-1rem"> <div class="flex justify-end pb-1rem">
<div class="px-1"> <div class="px-1">
<div class="relative shadow-md"> <div class="relative shadow-md">
...@@ -202,8 +159,7 @@ ...@@ -202,8 +159,7 @@
</tbody> </tbody>
<tbody *ngIf="filterBu6Modal().length"> <tbody *ngIf="filterBu6Modal().length">
<tr *ngFor="let item of filterBu6Modal() | slice:((bu6Modal.currentPage-1) * bu6Modal.pageSize) : (((bu6Modal.currentPage-1) * bu6Modal.pageSize) + bu6Modal.pageSize);let i = index" <tr *ngFor="let item of filterBu6Modal() | slice:((bu6Modal.currentPage-1) * bu6Modal.pageSize) : (((bu6Modal.currentPage-1) * bu6Modal.pageSize) + bu6Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu6(item)" class="cursor-pointer" (click)="selectBu6(item);closeDialogBu6()">
data-hs-overlay="#sub-department-four-modal">
<td class="flex justify-center"> <td class="flex justify-center">
{{((bu6Modal.currentPage-1) * bu6Modal.pageSize)+(i+1)}} {{((bu6Modal.currentPage-1) * bu6Modal.pageSize)+(i+1)}}
</td> </td>
...@@ -217,95 +173,15 @@ ...@@ -217,95 +173,15 @@
<app-pagination [totalItems]="filterBu6Modal().length" [pageSize]="bu6Modal.pageSize" <app-pagination [totalItems]="filterBu6Modal().length" [pageSize]="bu6Modal.pageSize"
(pageChange)="bu6Modal.currentPage = $event" (pageChange)="bu6Modal.currentPage = $event"
(pageSizeChange)="bu6Modal.pageSize = $event;bu6Modal.currentPage = 1"></app-pagination> (pageSizeChange)="bu6Modal.pageSize = $event;bu6Modal.currentPage = 1"></app-pagination>
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" <mat-dialog-actions align="end">
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" <button type="button" mat-button [mat-dialog-close]
data-hs-overlay="#sub-department-four-modal"> 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">
ย้อนกลับ
</button>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-four-alert" 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="#sub-department-four-modal">
<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"
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="#sub-department-four-modal">
ย้อนกลับ ย้อนกลับ
</button> </button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);" </mat-dialog-actions>
data-hs-overlay="#sub-department-four-alert" (click)="addBu7();"> </ng-template>
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-four-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">
<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="#sub-department-four-alert-delete-modal">
<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">
<ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numSelectItem()">
เลือกข้อมูลที่ต้องการลบ
</ng-container>
</p>
<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="#sub-department-four-alert-delete-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#sub-department-four-alert-delete-modal" (click)="deleteBu7();"
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-four-upload-modal" class="hs-overlay hidden ti-modal"> <div id="sub-department-four-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu6Model, MyBu6Model } from 'src/app/shared/model/bu6.model'; import { Bu6Model, MyBu6Model } from 'src/app/shared/model/bu6.model';
...@@ -6,6 +7,7 @@ import { Bu7Model, MyBu7Model } from 'src/app/shared/model/bu7.model'; ...@@ -6,6 +7,7 @@ import { Bu7Model, MyBu7Model } from 'src/app/shared/model/bu7.model';
import { Bu6Service } from 'src/app/shared/services/bu6.service'; import { Bu6Service } from 'src/app/shared/services/bu6.service';
import { Bu7Service } from 'src/app/shared/services/bu7.service'; import { Bu7Service } from 'src/app/shared/services/bu7.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table { interface table {
currentPage: number, currentPage: number,
...@@ -57,17 +59,41 @@ export class SubDepartmentFourComponent implements OnInit { ...@@ -57,17 +59,41 @@ export class SubDepartmentFourComponent implements OnInit {
}; };
search = '' search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("subDepartmentFourModal") subDepartmentFourModal: any;
@ViewChild("subDepartmentFourModalBu6") subDepartmentFourModalBu6: any;
dialogRef: any
dialogRefBu6: any
constructor(private bu7Service: Bu7Service, constructor(private bu7Service: Bu7Service,
private bu6Service: Bu6Service, private bu6Service: Bu6Service,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getBu7List() this.getBu7List()
this.getBu6List() this.getBu6List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentFourModal, {
width: '500px',
})
}
openDialogBu6() {
this.dialogRefBu6 = this.dialog.open(this.subDepartmentFourModalBu6, {
width: '500px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu6() {
this.dialogRefBu6.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -153,23 +179,48 @@ export class SubDepartmentFourComponent implements OnInit { ...@@ -153,23 +179,48 @@ export class SubDepartmentFourComponent implements OnInit {
} }
addBu7() { addBu7() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.bu7.loading = true this.bu7.loading = true
this.bu7Service.post({ ...this.bu7.select, parent: this.bu6.bu6id }).subscribe({ this.bu7Service.post({ ...this.bu7.select, parent: this.bu6.bu6id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu7List() this.getBu7List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu7.loading = false this.bu7.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu7.loading = false this.bu7.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu7() { deleteBu7() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu7.loading = true this.bu7.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu7.dataList.filter(x => selectedKeys.includes(x.bu7id) && this.selectedItems.data.get(x.bu7id)).map(x => new MyBu7Model(x)) const body = this.bu7.dataList.filter(x => selectedKeys.includes(x.bu7id) && this.selectedItems.data.get(x.bu7id)).map(x => new MyBu7Model(x))
...@@ -178,13 +229,18 @@ export class SubDepartmentFourComponent implements OnInit { ...@@ -178,13 +229,18 @@ export class SubDepartmentFourComponent implements OnInit {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu7List() this.getBu7List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu7.loading = false this.bu7.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu7.loading = false this.bu7.loading = false
this.closeDialog()
}
})
} }
}) })
} }
...@@ -213,9 +269,12 @@ export class SubDepartmentFourComponent implements OnInit { ...@@ -213,9 +269,12 @@ export class SubDepartmentFourComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, icon: type,
positionClass: 'toast-top-right', title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
}) })
} }
......
...@@ -23,14 +23,14 @@ ...@@ -23,14 +23,14 @@
</div> </div>
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
(click)="currentModal='add';selectBu5();selectBu6()" data-hs-overlay="#sub-department-three-modal"> (click)="currentModal='add';selectBu5();selectBu6();openDialog()" >
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md" <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
data-hs-overlay="#sub-department-three-alert-delete-modal"> (click)="deleteBu6()">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -40,55 +40,26 @@ ...@@ -40,55 +40,26 @@
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu6.dataList" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu6.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#sub-department-three-modal" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectBu6($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';selectBu6($event);openDialog()" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<ng-template #subDepartmentThreeModal let-modal>
<div id="sub-department-three-modal" class="hs-overlay hidden ti-modal"> <h3 mat-dialog-title>
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]"> {{currentModal=='add'?'เพิ่มข้อมูลทะเบียนส่วนย่อย 3':'แก้ไขข้อมูลทะเบียนส่วนย่อย 3'}}
<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'">
เพิ่มข้อมูลทะเบียนส่วนย่อย 3
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
แก้ไขข้อมูลทะเบียนส่วนย่อย 3
</ng-container>
</h3> </h3>
<div class="flex justify-end"> <div class="w-full flex justify-end mb-1rem">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger" <div class="absolute flex">
data-hs-overlay="#sub-department-three-modal">
<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"> <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)="selectBu5();selectBu6()">
(click)="selectBu5();selectBu6()"> <i class="ti ti-eraser text-base"></i>
<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 Clear
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<div class="ti-modal-body"> <mat-dialog-content>
<label class="ti-form-label ">อยู่ภายใต้หน่วยงาน<span class="text-danger">*</span></label> <label class="ti-form-label ">อยู่ภายใต้หน่วยงาน<span class="text-danger">*</span></label>
<div class="flex"> <div class="flex">
<div class="relative flex rounded-md"> <div class="relative flex rounded-md">
...@@ -101,8 +72,7 @@ ...@@ -101,8 +72,7 @@
<button type="button" class="flex items-center text-red-500" (click)="selectBu5()"> <button type="button" class="flex items-center text-red-500" (click)="selectBu5()">
<i class="ti ti-circle-x cursor-pointer"></i> <i class="ti ti-circle-x cursor-pointer"></i>
</button> </button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70" <button type="button" class="flex items-center text-gray-500 dark:text-white/70" (click)="openDialogBu5()">
data-hs-overlay="#sub-department-three-bu5-table-modal">
<i class="ri-search-line cursor-pointer text-gray"></i> <i class="ri-search-line cursor-pointer text-gray"></i>
</button> </button>
</div> </div>
...@@ -129,119 +99,26 @@ ...@@ -129,119 +99,26 @@
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu6.select.tdesc"> <input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu6.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วนย่อย3 (อังกฤษ)</label> <label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วนย่อย3 (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu6.select.edesc"> <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu6.select.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" <mat-dialog-actions align="end">
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" <button type="button" mat-button [mat-dialog-close]
data-hs-overlay="#sub-department-three-modal"> 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">
ย้อนกลับ ย้อนกลับ
</button> </button>
<button type="button" class="ti-btn ti-btn-success" <button type="button" class="ti-btn ti-btn-success" mat-button (click)="addBu6();"
data-hs-overlay="#sub-department-three-alert-modal"
[class.ti-btn-disabled]="!bu5.bu5id||!bu6.select.bu6id||!bu6.select.tdesc||(currentModal=='add'&&checkPrimary())" [class.ti-btn-disabled]="!bu5.bu5id||!bu6.select.bu6id||!bu6.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!bu5.bu5id||!bu6.select.bu6id||!bu6.select.tdesc||(currentModal=='add'&&checkPrimary())"> [disabled]="!bu5.bu5id||!bu6.select.bu6id||!bu6.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="sub-department-three-alert-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="#sub-department-three-modal">
<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"
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="#sub-department-three-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#sub-department-three-alert-modal" (click)="addBu6();">
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-three-alert-delete-modal" class="hs-overlay hidden ti-modal"> <ng-template #subDepartmentThreeModalBu5 let-modal>
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center"> <h3 mat-dialog-title>
<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="#sub-department-three-alert-delete-modal">
<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">
<ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numSelectItem()">
เลือกข้อมูลที่ต้องการลบ
</ng-container>
</p>
<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="#sub-department-three-alert-delete-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#sub-department-three-alert-delete-modal" (click)="deleteBu6()"
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-three-bu5-table-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out lg:!max-w-4xl lg:w-full m-3 lg:!mx-auto">
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
ข้อมูลทะเบียนส่วนย่อย 2 ข้อมูลทะเบียนส่วนย่อย 2
</h3> </h3>
<div class="flex justify-end"> <mat-dialog-content>
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#sub-department-three-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body">
<div class="flex justify-end pb-1rem"> <div class="flex justify-end pb-1rem">
<div class="px-1"> <div class="px-1">
<div class="relative shadow-md"> <div class="relative shadow-md">
...@@ -281,8 +158,7 @@ ...@@ -281,8 +158,7 @@
</tbody> </tbody>
<tbody *ngIf="filterBu5Modal().length"> <tbody *ngIf="filterBu5Modal().length">
<tr *ngFor="let item of filterBu5Modal() | slice:((bu5Modal.currentPage-1) * bu5Modal.pageSize) : (((bu5Modal.currentPage-1) * bu5Modal.pageSize) + bu5Modal.pageSize);let i = index" <tr *ngFor="let item of filterBu5Modal() | slice:((bu5Modal.currentPage-1) * bu5Modal.pageSize) : (((bu5Modal.currentPage-1) * bu5Modal.pageSize) + bu5Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu5(item)" class="cursor-pointer" (click)="selectBu5(item);closeDialogBu5()">
data-hs-overlay="#sub-department-three-modal">
<td class="flex justify-center"> <td class="flex justify-center">
{{((bu5Modal.currentPage-1) * bu5Modal.pageSize)+(i+1)}} {{((bu5Modal.currentPage-1) * bu5Modal.pageSize)+(i+1)}}
</td> </td>
...@@ -296,17 +172,17 @@ ...@@ -296,17 +172,17 @@
<app-pagination [totalItems]="filterBu5Modal().length" [pageSize]="bu5Modal.pageSize" <app-pagination [totalItems]="filterBu5Modal().length" [pageSize]="bu5Modal.pageSize"
(pageChange)="bu5Modal.currentPage = $event" (pageChange)="bu5Modal.currentPage = $event"
(pageSizeChange)="bu5Modal.pageSize = $event;bu5Modal.currentPage = 1"></app-pagination> (pageSizeChange)="bu5Modal.pageSize = $event;bu5Modal.currentPage = 1"></app-pagination>
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" <mat-dialog-actions align="end">
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" <button type="button" mat-button [mat-dialog-close]
data-hs-overlay="#sub-department-three-modal"> 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">
ย้อนกลับ ย้อนกลับ
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="sub-department-three-upload-modal" class="hs-overlay hidden ti-modal"> <div id="sub-department-three-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model'; import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model';
...@@ -6,6 +7,7 @@ import { Bu6Model, MyBu6Model } from 'src/app/shared/model/bu6.model'; ...@@ -6,6 +7,7 @@ import { Bu6Model, MyBu6Model } from 'src/app/shared/model/bu6.model';
import { Bu5Service } from 'src/app/shared/services/bu5.service'; import { Bu5Service } from 'src/app/shared/services/bu5.service';
import { Bu6Service } from 'src/app/shared/services/bu6.service'; import { Bu6Service } from 'src/app/shared/services/bu6.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table { interface table {
currentPage: number, currentPage: number,
...@@ -58,17 +60,38 @@ export class SubDepartmentThreeComponent implements OnInit { ...@@ -58,17 +60,38 @@ export class SubDepartmentThreeComponent implements OnInit {
}; };
search = '' search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("subDepartmentThreeModal") subDepartmentThreeModal: any;
@ViewChild("subDepartmentThreeModalBu5") subDepartmentThreeModalBu5: any;
dialogRef: any
dialogRefBu5: any
constructor(private bu6Service: Bu6Service, constructor(private bu6Service: Bu6Service,
private bu5Service: Bu5Service, private bu5Service: Bu5Service,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getBu6List() this.getBu6List()
this.getBu5List() this.getBu5List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentThreeModal, {
width: '500px',
})
}
openDialogBu5() {
this.dialogRefBu5 = this.dialog.open(this.subDepartmentThreeModalBu5, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu5() {
this.dialogRefBu5.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -155,23 +178,50 @@ export class SubDepartmentThreeComponent implements OnInit { ...@@ -155,23 +178,50 @@ export class SubDepartmentThreeComponent implements OnInit {
} }
addBu6() { addBu6() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.bu6.loading = true this.bu6.loading = true
this.bu6Service.post({ ...this.bu6.select, parent: this.bu5.bu5id }).subscribe({ this.bu6Service.post({ ...this.bu6.select, parent: this.bu5.bu5id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu6List() this.getBu6List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu6.loading = false this.bu6.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu6.loading = false this.bu6.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu6() { deleteBu6() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu6.loading = true this.bu6.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu6.dataList.filter(x => selectedKeys.includes(x.bu6id) && this.selectedItems.data.get(x.bu6id)).map(x => new MyBu6Model(x)) const body = this.bu6.dataList.filter(x => selectedKeys.includes(x.bu6id) && this.selectedItems.data.get(x.bu6id)).map(x => new MyBu6Model(x))
...@@ -190,6 +240,8 @@ export class SubDepartmentThreeComponent implements OnInit { ...@@ -190,6 +240,8 @@ export class SubDepartmentThreeComponent implements OnInit {
} }
}) })
} }
})
}
getBu5List() { getBu5List() {
this.bu5Service.getList().subscribe(response => { this.bu5Service.getList().subscribe(response => {
...@@ -215,9 +267,12 @@ export class SubDepartmentThreeComponent implements OnInit { ...@@ -215,9 +267,12 @@ export class SubDepartmentThreeComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, icon: type,
positionClass: 'toast-top-right', title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
}) })
} }
......
...@@ -23,14 +23,13 @@ ...@@ -23,14 +23,13 @@
</div> </div>
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
(click)="currentModal='add';selectBu4();selectBu5()" data-hs-overlay="#sub-department-two-modal"> (click)="currentModal='add';selectBu4();selectBu5();openDialog()">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md" <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md" (click)="deleteBu5()">
data-hs-overlay="#sub-department-two-alert-delete-modal">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -39,55 +38,27 @@ ...@@ -39,55 +38,27 @@
</div> </div>
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu5.dataList" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu5.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#sub-department-two-modal" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectBu5($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';selectBu5($event);openDialog()" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<div id="sub-department-two-modal" class="hs-overlay hidden ti-modal"> <ng-template #subDepartmentTwoModal let-modal>
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]"> <h3 mat-dialog-title>
<div class="max-h-full overflow-hidden ti-modal-content"> {{currentModal=='add'?'เพิ่มข้อมูลทะเบียนส่วนย่อย 2':'แก้ไขข้อมูลทะเบียนส่วนย่อย 2'}}
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
<ng-container *ngIf="currentModal=='add'">
เพิ่มข้อมูลทะเบียนส่วนย่อย 2
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
แก้ไขข้อมูลทะเบียนส่วนย่อย 2
</ng-container>
</h3> </h3>
<div class="flex justify-end"> <div class="w-full flex justify-end mb-1rem">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger" <div class="absolute flex">
data-hs-overlay="#sub-department-two-modal">
<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"> <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)="selectBu4();selectBu5()">
(click)="selectBu4();selectBu5()"> <i class="ti ti-eraser text-base"></i>
<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 Clear
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<div class="ti-modal-body"> <mat-dialog-content>
<label class="ti-form-label">อยู่ภายใต้หน่วยงาน<span class="text-danger">*</span></label> <label class="ti-form-label">อยู่ภายใต้หน่วยงาน<span class="text-danger">*</span></label>
<div class="flex"> <div class="flex">
<div class="relative flex rounded-md"> <div class="relative flex rounded-md">
...@@ -100,8 +71,7 @@ ...@@ -100,8 +71,7 @@
<button type="button" class="flex items-center text-red-500" (click)="selectBu4()"> <button type="button" class="flex items-center text-red-500" (click)="selectBu4()">
<i class="ti ti-circle-x cursor-pointer"></i> <i class="ti ti-circle-x cursor-pointer"></i>
</button> </button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70" <button type="button" class="flex items-center text-gray-500 dark:text-white/70" (click)="openDialogBu4()">
data-hs-overlay="#sub-department-two-bu4-table-modal">
<i class="ri-search-line cursor-pointer text-gray"></i> <i class="ri-search-line cursor-pointer text-gray"></i>
</button> </button>
</div> </div>
...@@ -128,41 +98,25 @@ ...@@ -128,41 +98,25 @@
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu5.select.tdesc"> <input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu5.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วนย่อย2 (อังกฤษ)</label> <label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วนย่อย2 (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu5.select.edesc"> <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu5.select.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" <mat-dialog-actions align="end">
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" <button type="button" mat-button [mat-dialog-close]
data-hs-overlay="#sub-department-two-modal"> 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">
ย้อนกลับ ย้อนกลับ
</button> </button>
<button class="ti-btn ti-btn-success" type="button" <button type="button" class="ti-btn ti-btn-success" mat-button (click)="addBu5();"
data-hs-overlay="#sub-department-two-alert-modal"
[class.ti-btn-disabled]="!bu4.bu4id||!bu5.select.bu5id||!bu5.select.tdesc||(currentModal=='add'&&checkPrimary())" [class.ti-btn-disabled]="!bu4.bu4id||!bu5.select.bu5id||!bu5.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!bu4.bu4id||!bu5.select.bu5id||!bu5.select.tdesc||(currentModal=='add'&&checkPrimary())"> [disabled]="!bu4.bu4id||!bu5.select.bu5id||!bu5.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="sub-department-two-bu4-table-modal" class="hs-overlay hidden ti-modal"> <ng-template #subDepartmentTwoModalBu4 let-modal>
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out lg:!max-w-4xl lg:w-full m-3 lg:!mx-auto"> <h3 mat-dialog-title>
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
ข้อมูลทะเบียนส่วนย่อย 1 ข้อมูลทะเบียนส่วนย่อย 1
</h3> </h3>
<div class="flex justify-end"> <mat-dialog-content>
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#sub-department-two-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body">
<div class="flex justify-end pb-1rem"> <div class="flex justify-end pb-1rem">
<div class="px-1"> <div class="px-1">
<div class="relative shadow-md"> <div class="relative shadow-md">
...@@ -202,8 +156,7 @@ ...@@ -202,8 +156,7 @@
</tbody> </tbody>
<tbody *ngIf="filterBu4Modal().length"> <tbody *ngIf="filterBu4Modal().length">
<tr *ngFor="let item of filterBu4Modal() | slice:((bu4Modal.currentPage-1) * bu4Modal.pageSize) : (((bu4Modal.currentPage-1) * bu4Modal.pageSize) + bu4Modal.pageSize);let i = index" <tr *ngFor="let item of filterBu4Modal() | slice:((bu4Modal.currentPage-1) * bu4Modal.pageSize) : (((bu4Modal.currentPage-1) * bu4Modal.pageSize) + bu4Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu4(item)" class="cursor-pointer" (click)="selectBu4(item);closeDialogBu4()">
data-hs-overlay="#sub-department-two-modal">
<td class="flex justify-center"> <td class="flex justify-center">
{{((bu4Modal.currentPage-1) * bu4Modal.pageSize)+(i+1)}} {{((bu4Modal.currentPage-1) * bu4Modal.pageSize)+(i+1)}}
</td> </td>
...@@ -217,93 +170,16 @@ ...@@ -217,93 +170,16 @@
<app-pagination [totalItems]="filterBu4Modal().length" [pageSize]="bu4Modal.pageSize" <app-pagination [totalItems]="filterBu4Modal().length" [pageSize]="bu4Modal.pageSize"
(pageChange)="bu4Modal.currentPage = $event" (pageChange)="bu4Modal.currentPage = $event"
(pageSizeChange)="bu4Modal.pageSize = $event;bu4Modal.currentPage = 1"></app-pagination> (pageSizeChange)="bu4Modal.pageSize = $event;bu4Modal.currentPage = 1"></app-pagination>
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" <mat-dialog-actions align="end">
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" <button type="button" mat-button [mat-dialog-close]
data-hs-overlay="#sub-department-two-modal"> 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">
ย้อนกลับ ย้อนกลับ
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="sub-department-two-alert-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="#sub-department-two-modal">
<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"
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="#sub-department-two-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#sub-department-two-alert-modal" (click)="addBu5()">
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-two-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">
<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="#sub-department-two-alert-delete-modal">
<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">
<ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numSelectItem()">
เลือกข้อมูลที่ต้องการลบ
</ng-container>
</p>
<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="#sub-department-two-alert-delete-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#sub-department-two-alert-delete-modal" (click)="deleteBu5()"
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-two-upload-modal" class="hs-overlay hidden ti-modal"> <div id="sub-department-two-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild, } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model'; import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
...@@ -6,6 +7,7 @@ import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model'; ...@@ -6,6 +7,7 @@ import { Bu5Model, MyBu5Model } from 'src/app/shared/model/bu5.model';
import { Bu4Service } from 'src/app/shared/services/bu4.service'; import { Bu4Service } from 'src/app/shared/services/bu4.service';
import { Bu5Service } from 'src/app/shared/services/bu5.service'; import { Bu5Service } from 'src/app/shared/services/bu5.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table { interface table {
currentPage: number, currentPage: number,
page: number[], page: number[],
...@@ -56,17 +58,39 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -56,17 +58,39 @@ export class SubDepartmentTwoComponent implements OnInit {
}; };
search = '' search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("subDepartmentTwoModal") subDepartmentTwoModal: any;
@ViewChild("subDepartmentTwoModalBu4") subDepartmentTwoModalBu4: any;
dialogRef: any
dialogRefBu4: any
constructor(private bu5Service: Bu5Service, constructor(private bu5Service: Bu5Service,
private bu4Service: Bu4Service, private bu4Service: Bu4Service,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getBu5List() this.getBu5List()
this.getBu4List() this.getBu4List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentTwoModal, {
width: '500px',
})
}
openDialogBu4() {
this.dialogRefBu4 = this.dialog.open(this.subDepartmentTwoModalBu4, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu4() {
this.dialogRefBu4.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -153,23 +177,47 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -153,23 +177,47 @@ export class SubDepartmentTwoComponent implements OnInit {
} }
addBu5() { addBu5() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.bu5.loading = true this.bu5.loading = true
this.bu5Service.post({ ...this.bu5.select, parent: this.bu4.bu4id }).subscribe({ this.bu5Service.post({ ...this.bu5.select, parent: this.bu4.bu4id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu5List() this.getBu5List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu5.loading = false this.bu5.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu5.loading = false this.bu5.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu5() { deleteBu5() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
this.bu5.loading = true this.bu5.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu5.dataList.filter(x => selectedKeys.includes(x.bu5id) && this.selectedItems.data.get(x.bu5id)).map(x => new MyBu5Model(x)) const body = this.bu5.dataList.filter(x => selectedKeys.includes(x.bu5id) && this.selectedItems.data.get(x.bu5id)).map(x => new MyBu5Model(x))
...@@ -187,6 +235,7 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -187,6 +235,7 @@ export class SubDepartmentTwoComponent implements OnInit {
this.bu5.loading = false this.bu5.loading = false
} }
}) })
})
} }
getBu4List() { getBu4List() {
...@@ -213,9 +262,12 @@ export class SubDepartmentTwoComponent implements OnInit { ...@@ -213,9 +262,12 @@ export class SubDepartmentTwoComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, icon: type,
positionClass: 'toast-top-right', title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
}) })
} }
......
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