Commit 9b7d69c1 by Nakarin Luankla

แก้ model bu1-4

parent b4ff8dbf
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</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';selectBu1();selectBu2()" data-hs-overlay="#department-list-modal"> (click)="currentModal='add';selectBu1();selectBu2();openDialog();">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</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';selectBu1()" data-hs-overlay="#department-list-alert-delete-modal"> (click)="currentModal='delete';deleteBu2()" >
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -52,63 +52,27 @@ ...@@ -52,63 +52,27 @@
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu2List" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu2List"
[columns]="columns" [modalName]="'#department-list-modal'" [selectedItems]="selectedItems" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectBu2($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';selectBu2($event);openDialog()" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<ng-template #departmentListModal let-modal>
<div id="department-list-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'?'เพิ่มข้อมูลทะเบียนเเผนก':'แก้ไขข้อมูลทะเบียนเเผนก'}}
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
เพิ่มข้อมูลทะเบียนเเผนก
</h3>
<h3 class="text-xxl font-bold text-primary" *ngIf="currentModal=='add'">
เพิ่มข้อมูลทะเบียนเเผนก
</h3>
<h3 class="text-xxl font-bold text-primary" *ngIf="currentModal=='edit'">
แก้ไขข้อมูลทะเบียนเเผนก
</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="#department-list-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)="selectBu1();selectBu2()">
(click)="selectBu1();selectBu2()"> <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 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"> <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">
<input type="text" id="hs-leading-button-add-on-with-icon-and-button" <input type="text" id="hs-leading-button-add-on-with-icon-and-button"
...@@ -120,8 +84,7 @@ ...@@ -120,8 +84,7 @@
<button type="button" class="flex items-center text-red-500" (click)="selectBu1()"> <button type="button" class="flex items-center text-red-500" (click)="selectBu1()">
<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)="openBu1Dialog()">
data-hs-overlay="#department-list-bu1-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>
...@@ -146,46 +109,24 @@ ...@@ -146,46 +109,24 @@
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu2.tdesc"> <input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu2.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)]="bu2.edesc"> <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu2.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="#department-list-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" data-hs-overlay="#department-list-alert-modal" <button type="button" class="ti-btn ti-btn-success" mat-button [class.ti-btn-disabled]="!bu1.bu1id||!bu2.bu2id||!bu2.tdesc||(currentModal=='add'&&checkPrimary())" (click)="addBu2()"
[class.ti-btn-disabled]="!bu1.bu1id||!bu2.bu2id||!bu2.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!bu1.bu1id||!bu2.bu2id||!bu2.tdesc||(currentModal=='add'&&checkPrimary())"> [disabled]="!bu1.bu1id||!bu2.bu2id||!bu2.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="department-list-bu1-table-modal" class="hs-overlay hidden ti-modal"> <ng-template #departmentListBu1Modal 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">
ข้อมูลทะเบียนฝ่าย ข้อมูลทะเบียนฝ่าย
</h3> </h3>
<div class="flex justify-end"> <mat-dialog-content>
<button *ngIf="currentModal=='add'" type="button"
class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#department-list-modal">
<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="#department-list-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">
<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">
...@@ -224,22 +165,8 @@ ...@@ -224,22 +165,8 @@
</tr> </tr>
</tbody> </tbody>
<tbody *ngIf="filterBu1Modal().length"> <tbody *ngIf="filterBu1Modal().length">
<ng-container *ngIf="currentModal=='add'">
<tr *ngFor="let item of filterBu1Modal() | slice:((bu1Modal.currentPage-1) * bu1Modal.pageSize) : (((bu1Modal.currentPage-1) * bu1Modal.pageSize) + bu1Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu1(item)"
data-hs-overlay="#department-list-modal">
<td class="flex justify-center">
{{((bu1Modal.currentPage-1) * bu1Modal.pageSize)+(i+1)}}
</td>
<td>{{item.bu1id}}</td>
<td>{{item.tdesc}}</td>
<td>{{item.edesc}}</td>
</tr>
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
<tr *ngFor="let item of filterBu1Modal() | slice:((bu1Modal.currentPage-1) * bu1Modal.pageSize) : (((bu1Modal.currentPage-1) * bu1Modal.pageSize) + bu1Modal.pageSize);let i = index" <tr *ngFor="let item of filterBu1Modal() | slice:((bu1Modal.currentPage-1) * bu1Modal.pageSize) : (((bu1Modal.currentPage-1) * bu1Modal.pageSize) + bu1Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu1(item)" class="cursor-pointer" (click)="selectBu1(item);closeBu1Dialog()" >
data-hs-overlay="#department-list-modal-edit">
<td class="flex justify-center"> <td class="flex justify-center">
{{((bu1Modal.currentPage-1) * bu1Modal.pageSize)+(i+1)}} {{((bu1Modal.currentPage-1) * bu1Modal.pageSize)+(i+1)}}
</td> </td>
...@@ -247,142 +174,21 @@ ...@@ -247,142 +174,21 @@
<td>{{item.tdesc}}</td> <td>{{item.tdesc}}</td>
<td>{{item.edesc}}</td> <td>{{item.edesc}}</td>
</tr> </tr>
</ng-container>
</tbody> </tbody>
</table> </table>
</div> </div>
<app-pagination [totalItems]="filterBu1Modal().length" [pageSize]="bu1Modal.pageSize" <app-pagination [totalItems]="filterBu1Modal().length" [pageSize]="bu1Modal.pageSize"
(pageChange)="bu1Modal.currentPage = $event" (pageChange)="bu1Modal.currentPage = $event"
(pageSizeChange)="bu1Modal.pageSize = $event;bu1Modal.currentPage = 1"></app-pagination> (pageSizeChange)="bu1Modal.pageSize = $event;bu1Modal.currentPage = 1"></app-pagination>
<div class="flex justify-end mt-2rem mb-1rem space-x-4"> </mat-dialog-content>
<button type="button" *ngIf="currentModal=='add'" <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="#department-list-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 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="#department-list-modal-edit">
ย้อนกลับ
</button>
</div>
</div>
</div>
</div>
</div>
<div id="department-list-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="#department-list-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="#department-list-modal">
ย้อนกลับ ย้อนกลับ
</button> </button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);" </mat-dialog-actions>
data-hs-overlay="#department-list-alert-modal" (click)="addBu2()"> </ng-template>
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="department-list-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="#department-list-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"
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="#department-list-modal-edit">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#department-list-alert-edit-modal" (click)="addBu2()">
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="department-list-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="#department-list-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
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="#department-list-alert-delete-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#department-list-alert-delete-modal" (click)="deleteBu2()"
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="department-list-upload-modal" class="hs-overlay hidden ti-modal"> <div id="department-list-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 { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model'; import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
...@@ -6,6 +7,7 @@ import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model'; ...@@ -6,6 +7,7 @@ import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service'; import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { Bu2Service } from 'src/app/shared/services/bu2.service'; import { Bu2Service } from 'src/app/shared/services/bu2.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[],
...@@ -70,18 +72,38 @@ export class DepartmentListComponent implements OnInit { ...@@ -70,18 +72,38 @@ export class DepartmentListComponent implements OnInit {
pageSize: 10 pageSize: 10
} }
currentModal: 'add' | 'edit' | 'delete' = "add" currentModal: 'add' | 'edit' | 'delete' = "add"
@ViewChild("departmentListModal") departmentListModal: any;
@ViewChild("departmentListBu1Modal") departmentListBu1Modal: any;
dialogRef: any
dialogRefBu1: any
constructor(private bu2Service: Bu2Service, constructor(private bu2Service: Bu2Service,
private bu1Service: Bu1Service, private bu1Service: Bu1Service,
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.getBu2List() this.getBu2List()
this.getBu1List() this.getBu1List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.departmentListModal, {
width: '500px',
})
}
openBu1Dialog() {
this.dialogRefBu1 = this.dialog.open(this.departmentListBu1Modal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeBu1Dialog() {
this.dialogRefBu1.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 || "กรุณาเลือกไฟล์"
...@@ -185,45 +207,80 @@ export class DepartmentListComponent implements OnInit { ...@@ -185,45 +207,80 @@ export class DepartmentListComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
confirmButtonText: 'ตกลง',
});
} }
addBu2() { addBu2() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.bu2ListLoading = true this.bu2ListLoading = true
this.bu2Service.post({ ...this.bu2, parent: this.bu1.bu1id }).subscribe({ this.bu2Service.post({ ...this.bu2, parent: this.bu1.bu1id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu2List() this.getBu2List()
this.closeDialog();
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu2ListLoading = false this.bu2ListLoading = false
this.closeDialog();
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu2ListLoading = false this.bu2ListLoading = false
this.closeDialog();
} }
}) })
} }
});
}
deleteBu2() { deleteBu2() {
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.bu2ListLoading = true this.bu2ListLoading = true
// const body = this.bu2List.filter(x => x.check).map(x => new MyBu2Model(x.data)) const selectedKeys = Array.from(this.selectedItems.data.keys());
// this.bu2Service.delete(body).subscribe({ const body = this.bu2List.filter(x => selectedKeys.includes(x.bu2id) && this.selectedItems.data.get(x.bu2id)).map(x => new MyBu2Model(x))
// next: response => { this.bu2Service.delete(body).subscribe({
// if (response.success) { next: response => {
// this.showAlert(response.message, 'success') if (response.success) {
// this.getBu2List() this.showAlert(response.message, 'success')
// } else { this.getBu2List()
// this.showAlert(response.message, 'error') } else {
// this.bu2ListLoading = false this.showAlert(response.message, 'error')
// } this.bu2ListLoading = false
// }, error: error => { }
// this.showAlert(error.message, 'error') }, error: error => {
// this.bu2ListLoading = false this.showAlert(error.message, 'error')
// } this.bu2ListLoading = false
// }) }
})
}
});
} }
......
...@@ -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';selectBu2();selectBu3()" data-hs-overlay="#section-registration-modal"> (click)="currentModal='add';selectBu2();selectBu3();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="#section-registration-alert-delete-modal"> (click)="currentModal='delete';deleteBu3()" >
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -41,55 +41,27 @@ ...@@ -41,55 +41,27 @@
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu3.dataList" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu3.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#section-registration-modal" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectBu3($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';selectBu3($event);openDialog()" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<ng-template #sectionRegistrationModal let-modal>
<div id="section-registration-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'?'เพิ่มข้อมูลทะเบียนส่วน':'แก้ไขข้อมูลทะเบียนส่วน'}}
<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> </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="#section-registration-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)="selectBu2();selectBu3()"> (click)="selectBu2();selectBu3()">
<svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00" <i class="ti ti-eraser text-base"></i>
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">
...@@ -102,15 +74,14 @@ ...@@ -102,15 +74,14 @@
<button type="button" class="flex items-center text-red-500" (click)="selectBu2()"> <button type="button" class="flex items-center text-red-500" (click)="selectBu2()">
<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)="openDialogBu2()">
data-hs-overlay="#section-registration-bu2-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>
</div> </div>
<div class="flex rounded-md w-1/2 pl-1rem"> <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" <input type="text" id="input-label" class="ti-form-input w-full pr-10 bg-input-readonly" readonly
readonly [value]="bu2.tdesc"> [value]="bu2.tdesc">
</div> </div>
</div> </div>
<label class="ti-form-label mt-2rem">ส่วน <label class="ti-form-label mt-2rem">ส่วน
...@@ -130,40 +101,24 @@ ...@@ -130,40 +101,24 @@
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu3.select.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> <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.select.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"> </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="#section-registration-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)="addBu3()"
data-hs-overlay="#section-registration-alert-modal"
[class.ti-btn-disabled]="!bu2.bu2id||!bu3.select.bu3id||!bu3.select.tdesc||(currentModal=='add'&&checkPrimary())" [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())"> [disabled]="!bu2.bu2id||!bu3.select.bu3id||!bu3.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="section-registration-bu2-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 #sectionRegistrationModalBu2 let-modal>
<div class="max-h-full overflow-hidden ti-modal-content"> <h3 mat-dialog-title>ข้อมูลทะเบียนเเผนก</h3>
<div class="ti-modal-header"> <mat-dialog-content>
<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">
<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">
...@@ -203,8 +158,7 @@ ...@@ -203,8 +158,7 @@
</tbody> </tbody>
<tbody *ngIf="filterBu2Modal().length"> <tbody *ngIf="filterBu2Modal().length">
<tr *ngFor="let item of filterBu2Modal() | slice:((bu2Modal.currentPage-1) * bu2Modal.pageSize) : (((bu2Modal.currentPage-1) * bu2Modal.pageSize) + bu2Modal.pageSize);let i = index" <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)" class="cursor-pointer" (click)="selectBu2(item);closeDialogBu2()">
data-hs-overlay="#section-registration-modal">
<td class="flex justify-center"> <td class="flex justify-center">
{{((bu2Modal.currentPage-1) * bu2Modal.pageSize)+(i+1)}} {{((bu2Modal.currentPage-1) * bu2Modal.pageSize)+(i+1)}}
</td> </td>
...@@ -218,97 +172,16 @@ ...@@ -218,97 +172,16 @@
<app-pagination [totalItems]="filterBu2Modal().length" [pageSize]="bu2Modal.pageSize" <app-pagination [totalItems]="filterBu2Modal().length" [pageSize]="bu2Modal.pageSize"
(pageChange)="bu2Modal.currentPage = $event" (pageChange)="bu2Modal.currentPage = $event"
(pageSizeChange)="bu2Modal.pageSize = $event;bu2Modal.currentPage = 1"></app-pagination> (pageSizeChange)="bu2Modal.pageSize = $event;bu2Modal.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="#section-registration-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="section-registration-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="#section-registration-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="#section-registration-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#section-registration-alert-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">
<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-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="#section-registration-alert-delete-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#section-registration-alert-delete-modal" (click)="deleteBu3()"
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="section-registration-upload-modal" class="hs-overlay hidden ti-modal"> <div id="section-registration-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 { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model'; import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
...@@ -6,6 +7,7 @@ import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model'; ...@@ -6,6 +7,7 @@ import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu2Service } from 'src/app/shared/services/bu2.service'; import { Bu2Service } from 'src/app/shared/services/bu2.service';
import { Bu3Service } from 'src/app/shared/services/bu3.service'; import { Bu3Service } from 'src/app/shared/services/bu3.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,38 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -56,17 +58,38 @@ export class SectionRegistrationComponent 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("sectionRegistrationModal") sectionRegistrationModal: any;
@ViewChild("sectionRegistrationModalBu2") sectionRegistrationModalBu2: any;
dialogRef: any
dialogRefBu2: any
constructor(private bu3Service: Bu3Service, constructor(private bu3Service: Bu3Service,
private bu2Service: Bu2Service, private bu2Service: Bu2Service,
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.getBu3List() this.getBu3List()
this.getBu2List() this.getBu2List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.sectionRegistrationModal, {
width: '500px',
})
}
openDialogBu2() {
this.dialogRefBu2 = this.dialog.open(this.sectionRegistrationModalBu2, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu2() {
this.dialogRefBu2.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;
...@@ -154,23 +177,48 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -154,23 +177,48 @@ export class SectionRegistrationComponent implements OnInit {
} }
addBu3() { addBu3() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu3.loading = true this.bu3.loading = true
this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({ this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu3List() this.getBu3List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu3.loading = false this.bu3.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu3.loading = false this.bu3.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu3() { deleteBu3() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu3.loading = true this.bu3.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); 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)) const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x))
...@@ -189,6 +237,8 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -189,6 +237,8 @@ export class SectionRegistrationComponent implements OnInit {
} }
}) })
} }
})
}
getBu2List() { getBu2List() {
this.bu2Service.getList().subscribe(response => { this.bu2Service.getList().subscribe(response => {
...@@ -214,10 +264,12 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -214,10 +264,12 @@ export class SectionRegistrationComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
confirmButtonText: 'ตกลง',
});
} }
checkPrimary() { checkPrimary() {
......
...@@ -22,14 +22,13 @@ ...@@ -22,14 +22,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';selectBu3();selectBu4()" data-hs-overlay="#sub-department-one-modal"> (click)="currentModal='add';selectBu3();selectBu4();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)="deleteBu4()">
data-hs-overlay="#sub-department-one-alert-delete-modal">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -39,56 +38,26 @@ ...@@ -39,56 +38,26 @@
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu4.dataList" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="bu4.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#sub-department-one-modal" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectBu4($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';selectBu4($event);openDialog()" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<ng-template #subDepartmentOneModal let-modal>
<h3 mat-dialog-title>
<div id="sub-department-one-modal" class="hs-overlay hidden ti-modal"> {{currentModal=='add'?'เพิ่มข้อมูลทะเบียนส่วนย่อย 1':'แก้ไขข้อมูลทะเบียนส่วนย่อย 1'}}
<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'">
เพิ่มข้อมูลทะเบียนส่วนย่อย 1
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
แก้ไขข้อมูลทะเบียนส่วนย่อย 1
</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-one-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)="selectBu3();selectBu4()">
(click)="selectBu3();selectBu4()"> <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 +70,7 @@ ...@@ -101,8 +70,7 @@
<button type="button" class="flex items-center text-red-500" (click)="selectBu3()"> <button type="button" class="flex items-center text-red-500" (click)="selectBu3()">
<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)="openDialogBu3()">
data-hs-overlay="#sub-department-one-bu3-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,41 +97,25 @@ ...@@ -129,41 +97,25 @@
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu4.select.tdesc"> <input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="bu4.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วนย่อย1 (อังกฤษ)</label> <label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดส่วนย่อย1 (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu4.select.edesc"> <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="bu4.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-one-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)="addBu4()"
data-hs-overlay="#sub-department-one-alert-modal"
[class.ti-btn-disabled]="!bu3.bu3id||!bu4.select.bu4id||!bu4.select.tdesc||(currentModal=='add'&&checkPrimary())" [class.ti-btn-disabled]="!bu3.bu3id||!bu4.select.bu4id||!bu4.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!bu3.bu3id||!bu4.select.bu4id||!bu4.select.tdesc||(currentModal=='add'&&checkPrimary())"> [disabled]="!bu3.bu3id||!bu4.select.bu4id||!bu4.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </mat-dialog-actions>
</div> </ng-template>
</div>
</div>
</div>
<div id="sub-department-one-bu3-table-modal" class="hs-overlay hidden ti-modal"> <ng-template #subDepartmentOneBu3TableModal 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">
ข้อมูลทะเบียนส่วน ข้อมูลทะเบียนส่วน
</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-one-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">
...@@ -203,8 +155,7 @@ ...@@ -203,8 +155,7 @@
</tbody> </tbody>
<tbody *ngIf="filterBu3Modal().length"> <tbody *ngIf="filterBu3Modal().length">
<tr *ngFor="let item of filterBu3Modal() | slice:((bu3Modal.currentPage-1) * bu3Modal.pageSize) : (((bu3Modal.currentPage-1) * bu3Modal.pageSize) + bu3Modal.pageSize);let i = index" <tr *ngFor="let item of filterBu3Modal() | slice:((bu3Modal.currentPage-1) * bu3Modal.pageSize) : (((bu3Modal.currentPage-1) * bu3Modal.pageSize) + bu3Modal.pageSize);let i = index"
class="cursor-pointer" (click)="selectBu3(item)" class="cursor-pointer" (click)="selectBu3(item);closeDialogBu3()">
data-hs-overlay="#sub-department-one-modal">
<td class="flex justify-center"> <td class="flex justify-center">
{{((bu3Modal.currentPage-1) * bu3Modal.pageSize)+(i+1)}} {{((bu3Modal.currentPage-1) * bu3Modal.pageSize)+(i+1)}}
</td> </td>
...@@ -218,97 +169,17 @@ ...@@ -218,97 +169,17 @@
<app-pagination [totalItems]="filterBu3Modal().length" [pageSize]="bu3Modal.pageSize" <app-pagination [totalItems]="filterBu3Modal().length" [pageSize]="bu3Modal.pageSize"
(pageChange)="bu3Modal.currentPage = $event" (pageChange)="bu3Modal.currentPage = $event"
(pageSizeChange)="bu3Modal.pageSize = $event;bu3Modal.currentPage = 1"></app-pagination> (pageSizeChange)="bu3Modal.pageSize = $event;bu3Modal.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-one-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-one-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-one-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-one-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#sub-department-one-alert-modal" (click)="addBu4()">
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-one-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-one-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-one-alert-delete-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#sub-department-one-alert-delete-modal" (click)="deleteBu4();"
*ngIf="numSelectItem()">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="sub-department-one-upload-modal" class="hs-overlay hidden ti-modal"> <div id="sub-department-one-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 { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { MatDialog } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model'; import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model'; import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
import { Bu3Service } from 'src/app/shared/services/bu3.service'; import { Bu3Service } from 'src/app/shared/services/bu3.service';
import { Bu4Service } from 'src/app/shared/services/bu4.service'; import { Bu4Service } from 'src/app/shared/services/bu4.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[],
...@@ -63,11 +65,17 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -63,11 +65,17 @@ export class SubDepartmentOneComponent 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("subDepartmentOneModal") subDepartmentOneModal: any;
@ViewChild("subDepartmentOneBu3TableModal") subDepartmentOneBu3TableModal: any;
dialogRef: any
dialogRefBu3: any
constructor(private bu4Service: Bu4Service, constructor(private bu4Service: Bu4Service,
private bu3Service: Bu3Service, private bu3Service: Bu3Service,
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 {
...@@ -75,6 +83,23 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -75,6 +83,23 @@ export class SubDepartmentOneComponent implements OnInit {
this.getBu3List() this.getBu3List()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentOneModal, {
width: '500px',
})
}
openDialogBu3() {
this.dialogRefBu3 = this.dialog.open(this.subDepartmentOneBu3TableModal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu3() {
this.dialogRefBu3.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 || "กรุณาเลือกไฟล์"
...@@ -160,23 +185,48 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -160,23 +185,48 @@ export class SubDepartmentOneComponent implements OnInit {
} }
addBu4() { addBu4() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu4.loading = true this.bu4.loading = true
this.bu4Service.post({ ...this.bu4.select, parent: this.bu3.bu3id }).subscribe({ this.bu4Service.post({ ...this.bu4.select, parent: this.bu3.bu3id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu4List() this.getBu4List()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu4.loading = false this.bu4.loading = false
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu4.loading = false this.bu4.loading = false
this.closeDialog()
}
})
} }
}) })
} }
deleteBu4() { deleteBu4() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu4.loading = true this.bu4.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x)) const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x))
...@@ -195,6 +245,8 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -195,6 +245,8 @@ export class SubDepartmentOneComponent implements OnInit {
} }
}) })
} }
})
}
getBu3List() { getBu3List() {
this.bu3Service.getList().subscribe(response => { this.bu3Service.getList().subscribe(response => {
...@@ -220,10 +272,12 @@ export class SubDepartmentOneComponent implements OnInit { ...@@ -220,10 +272,12 @@ export class SubDepartmentOneComponent implements OnInit {
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
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