Commit 9fc248ab by Nakarin Luankla

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

parent f267a8cc
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: 'ยืนยัน',
}) })
} }
......
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: 'ยืนยัน',
}) })
} }
......
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