This commit is contained in:
2023-10-19 03:05:50 +07:00
parent 480cbefd74
commit 4476d9d2dc
16 changed files with 404 additions and 53 deletions

View File

@@ -1 +1,4 @@
<app-list [kycList]="kyc$ | async"></app-list>
<app-list
(edit)="edit($event)"
[kycList]="kyc$ | async">
</app-list>

View File

@@ -1,6 +1,11 @@
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { ChangeDetectorRef, Component } from '@angular/core';
import { Observable, catchError, switchMap, tap, throwError } from 'rxjs';
import { IDialogConfig, CDialogConfig } from 'src/app/@common/interface/Dialog';
import { EAction, EText } from 'src/app/@config/app';
import { KycService } from 'src/app/core/service/common/kyc.service';
import { DialogComponent } from '../../presenter/dialog/dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { AppService } from 'src/app/app.service';
@Component({
selector: 'app-kyc',
@@ -8,10 +13,34 @@ import { KycService } from 'src/app/core/service/common/kyc.service';
styleUrls: ['./kyc.container.scss']
})
export class KycContainer {
dialogConfig: IDialogConfig = CDialogConfig
kyc$ = new Observable();
constructor(
private kycService: KycService
private kycService: KycService,
private dialog: MatDialog,
private appService: AppService,
private cdr: ChangeDetectorRef
) {
this.kyc$ = this.kycService.getAll();
}
edit(uid){
this.dialogConfig.data.action = EAction.UPDATE;
this.dialogConfig.data.ids = uid
const dialogRef = this.dialog.open(DialogComponent,this.dialogConfig);
const edit$ = dialogRef.afterClosed().pipe(
switchMap((res) => {
if(res === 'success'){
return this.kyc$ = this.kycService.getAll().pipe(
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
return throwError(() => err)
}),
tap(() => this.cdr.detectChanges())
)
}
})
);
return edit$.subscribe();
}
}

View File

@@ -5,6 +5,7 @@ import { KycRouter } from "./router/router";
import { KycContainer } from "./container/kyc/kyc.container";
import { NgModule } from "@angular/core";
import { ListComponent } from "./presenter/list/list.component";
import { DialogComponent } from './presenter/dialog/dialog.component';
const routes: Routes = [
@@ -24,7 +25,8 @@ const routes: Routes = [
declarations: [
KycRouter,
KycContainer,
ListComponent
ListComponent,
DialogComponent
],
imports: [
AppSharedModule,

View File

@@ -0,0 +1,91 @@
<form [formGroup]="form" class="dialog-main form-dialog" autocomplete="off">
<div class="dialog-main">
<div class="dialog-header flex justify-between">
<h2>More Detail</h2>
<mat-icon mat-dialog-close class="cursor-pointer">clear</mat-icon>
</div>
<div class="dialog-body">
<div class="grid grid-cols-12 gap-4 md:gap-2 ">
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">เลขประจำตัวประชาชน</mat-label>
<mat-form-field class="col-span-7">
<input matInput required formControlName="id_card" readonly type="text">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">คำนำหน้าชื่อ</mat-label>
<mat-form-field class="col-span-7">
<input matInput required formControlName="prefix_name" readonly type="text">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">ชื่อ</mat-label>
<mat-form-field class="col-span-7">
<input matInput required formControlName="first_name" readonly type="text">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">นามสกุล</mat-label>
<mat-form-field class="col-span-7">
<input matInput required formControlName="last_name" readonly type="text">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">เกิดวันที่</mat-label>
<mat-form-field class="col-span-7">
<input matInput formControlName="birth_date" [matDatepicker]="birthdate" readonly />
<mat-datepicker-toggle [for]="birthdate" disabled matSuffix></mat-datepicker-toggle>
<mat-datepicker #birthdate></mat-datepicker>
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">วันบัตรหมดอายุ</mat-label>
<mat-form-field class="col-span-7">
<input matInput formControlName="exp_date" [matDatepicker]="expdate" readonly />
<mat-datepicker-toggle [for]="expdate" disabled matSuffix></mat-datepicker-toggle>
<mat-datepicker #expdate></mat-datepicker>
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">เลขหลังบัตร</mat-label>
<mat-form-field class="col-span-7">
<input matInput required formControlName="code_back_card" readonly type="text">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
</div>
</div>
<div class="dialog-footer">
<button type="submit" mat-raised-button class="btn btn-green" (click)="status(true)" [disabled]="form.invalid">Approve</button>
<button type="button" class="btn btn-red" (click)="status(false)">Reject</button>
</div>
</div>
</form>
<!-- <pre>{{form.getRawValue() | json}}</pre> -->

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DialogComponent } from './dialog.component';
describe('DialogComponent', () => {
let component: DialogComponent;
let fixture: ComponentFixture<DialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DialogComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(DialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,90 @@
import { Location } from '@angular/common';
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Router, ActivatedRoute } from '@angular/router';
import { tap, catchError, throwError } from 'rxjs';
import { IDialogConfigData } from 'src/app/@common/interface/Dialog';
import { EAction, EText } from 'src/app/@config/app';
import { AppService } from 'src/app/app.service';
import { BaseForm } from 'src/app/core/base/base-form';
import { KycService } from 'src/app/core/service/common/kyc.service';
@Component({
selector: 'app-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.scss']
})
export class DialogComponent extends BaseForm implements OnInit {
constructor(
public dialogRef: MatDialogRef<DialogComponent>,
@Inject(MAT_DIALOG_DATA) public dialog: IDialogConfigData,
public router: Router,
public activatedRoute: ActivatedRoute,
public fb: FormBuilder,
public location: Location,
public kycService: KycService,
public appService: AppService,
public cdr: ChangeDetectorRef
) {
super(router, activatedRoute, fb, location)
}
ngOnInit(): void {
if (this.dialog.action === EAction.UPDATE){
this.state = 'edit';
this.getData();
}
}
createForm(): FormGroup<any> {
return this.fb.group({
kyc_uid: null,
id_card: null,
code_back_card: null,
exp_date: null,
prefix_name: null,
first_name: null,
last_name: null,
birth_date: [null],
phone: [null],
email: null,
image_front_url: [null],
image_back_url: [null],
is_pass: null,
status_id: [null],
created_by: null,
created_datetime: null,
updated_by: null,
updated_datetime: null,
owner_agency_uid: null
})
}
getData() {
if (!this.dialog.ids) this.appService.message(EAction.INFO, EText.NO_DATA);
return this.kycService.get(this.dialog.ids).pipe(
tap((res) => this.form.patchValue(res)),
tap(() => this.cdr.detectChanges()),
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
return throwError(() => err)
})
).subscribe()
}
status(isApprove: boolean){
const form = this.form.getRawValue();
form.is_pass = isApprove;
const save$ = this.kycService.update2(form)
return save$.pipe(
tap(() => this.appService.message(EAction.SUCCESS, EText.UPDATE)),
tap(() => this.dialogRef.close('success')),
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
return throwError(() => err)
})
).subscribe()
}
}

View File

@@ -5,13 +5,13 @@
<div class="col-span-3 md:col-span-5 md:order-2">
<mat-form-field>
<i matTextPrefix class="bi bi-search"></i>
<input matInput placeholder="เลขบัตรประชาชน/เลขหลังบัตร">
<input matInput placeholder="เลขบัตรประชาชน/เลขหลังบัตร" [(ngModel)]="query.card" (ngModelChange)="onFilterCard($event)">
</mat-form-field>
</div>
<div class="col-span-5 md:col-span-7 md:order-2">
<mat-form-field>
<i matTextPrefix class="bi bi-search"></i>
<input matInput placeholder="ชื่อ-นามสกุล">
<input matInput placeholder="ชื่อ-นามสกุล" [(ngModel)]="query.name" (ngModelChange)="onFilterName($event)">
</mat-form-field>
</div>
</div>
@@ -24,80 +24,81 @@
<tr mat-row *matRowDef="let row; columns: ['1','2','3','4','5','6','7','8','9','10','11','12'];"></tr>
<ng-container matColumnDef="1">
<th mat-header-cell *matHeaderCellDef class="tac" mat-sort-header>ลำดับ</th>
<td mat-cell *matCellDef="let item" width="150" class="tac">{{item.code}}</td>
<th mat-header-cell *matHeaderCellDef class="tac">ลำดับ</th>
<td mat-cell *matCellDef="let item; let i = index;" width="150" class="tac">{{getIndex(i)}}</td>
</ng-container>
<ng-container matColumnDef="2">
<th mat-header-cell *matHeaderCellDef class="tal">เลขบัตรประชาชน</th>
<td mat-cell *matCellDef="let item" class="" style="min-width: 200px;">
{{item.name }}
<th mat-header-cell *matHeaderCellDef class="tac">เลขบัตรประชาชน</th>
<td mat-cell *matCellDef="let item" class="tac" style="min-width: 200px;">
{{item.id_card}}
</td>
</ng-container>
<ng-container matColumnDef="3">
<th mat-header-cell *matHeaderCellDef class="tal" mat-sort-header>เลขหลังบัตร</th>
<td mat-cell *matCellDef="let item" class="">{{item?.masterProductBrand.name }}</td>
<th mat-header-cell *matHeaderCellDef class="tac">เลขหลังบัตร</th>
<td mat-cell *matCellDef="let item" class="tac">{{item.code_back_card}}</td>
</ng-container>
<ng-container matColumnDef="4">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">วันหมดอายุ</th>
<td mat-cell *matCellDef="let item" class="">{{item.size }}</td>
<td mat-cell *matCellDef="let item" class="">{{item.exp_date | thaidate}}</td>
</ng-container>
<ng-container matColumnDef="5">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">คำนำหน้า</th>
<td mat-cell *matCellDef="let item" class="">{{item.weight }}</td>
<th mat-header-cell *matHeaderCellDef class="tac" width="150">คำนำหน้า</th>
<td mat-cell *matCellDef="let item" class="tac">{{item.prefix_name}}</td>
</ng-container>
<ng-container matColumnDef="6">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">ชื่อ</th>
<td mat-cell *matCellDef="let item" class="">{{item.color }}</td>
<td mat-cell *matCellDef="let item" class="">{{item.first_name}}</td>
</ng-container>
<ng-container matColumnDef="7">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">นามสกุล</th>
<td mat-cell *matCellDef="let item" class="">{{item.year }}</td>
<td mat-cell *matCellDef="let item" class="">{{item.last_name}}</td>
</ng-container>
<ng-container matColumnDef="8">
<th mat-header-cell *matHeaderCellDef class="tal" width="150" mat-sort-header>วัน เดือน ปีเกิด</th>
<th mat-header-cell *matHeaderCellDef class="tal" width="150">วัน เดือน ปีเกิด</th>
<td mat-cell *matCellDef="let item" class="">
<div class="b-color-orange"> {{item.price | number : '1.2-2'}}</div>
<div> {{item.birth_date | thaidate}}</div>
</td>
</ng-container>
<ng-container matColumnDef="9">
<th mat-header-cell *matHeaderCellDef class="tal" width="150" mat-sort-header>เบอร์โทรศัพท์</th>
<th mat-header-cell *matHeaderCellDef class="tal" width="150">เบอร์โทรศัพท์</th>
<td mat-cell *matCellDef="let item" class="">
<div class="b-color-green"> {{item.latestPrice | number : '1.2-2' }}</div>
<div> {{item.phone}}</div>
</td>
</ng-container>
<ng-container matColumnDef="10">
<th mat-header-cell *matHeaderCellDef width="80">E-mail</th>
<td mat-cell *matCellDef="let item">
<th mat-header-cell *matHeaderCellDef class="tac" width="150">E-mail</th>
<td mat-cell *matCellDef="let item" class="tac">
<div> {{item.email}}</div>
</td>
</ng-container>
<ng-container matColumnDef="11">
<th mat-header-cell *matHeaderCellDef class="tac" width="150">More Detail</th>
<td mat-cell *matCellDef="let item" class="tac">
<div class="action flex justify-center">
<div class="item">
<i class="bi bi-file-earmark-text icon-doc"></i>
<div class="item cursor-pointer">
<i class="bi bi-pencil-square icon-edit mr-2" (click)="onEdit(item.kyc_uid)"></i>
</div>
</div>
</td>
</ng-container>
<ng-container matColumnDef="11">
<th mat-header-cell *matHeaderCellDef class="tal" width="150" mat-sort-header>More Detail</th>
<td mat-cell *matCellDef="let item" class="">
<div class="b-color-green"> {{item.latestPrice | number : '1.2-2' }}</div>
</td>
</ng-container>
<ng-container matColumnDef="12">
<th mat-header-cell *matHeaderCellDef class="tal" width="150" mat-sort-header>สถานะ</th>
<td mat-cell *matCellDef="let item" class="">
<div class="b-color-green"> {{item.latestPrice | number : '1.2-2' }}</div>
<th mat-header-cell *matHeaderCellDef class="tac" width="150">สถานะ</th>
<td mat-cell *matCellDef="let item" class="tac">
<div *ngIf="item.is_pass" class="status status-active">Approve</div>
<div *ngIf="!item.is_pass" class="status status-disabled">Reject</div>
</td>
</ng-container>
</table>
</div>
<!-- <div *ngIf="dataSourceCount === 0" class="no-data"></div> -->
<mat-paginator [pageSizeOptions]="[5,10,20]" showFirstLastButtons (page)="getData($event)"></mat-paginator>
<mat-paginator [pageSizeOptions]="[5,10,20]" showFirstLastButtons></mat-paginator>
</div>
</div>

View File

@@ -1,17 +1,52 @@
import { Component, Input } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Subject, debounceTime, distinctUntilChanged } from 'rxjs';
import { BaseList } from 'src/app/core/base/base-list';
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.scss']
})
export class ListComponent {
export class ListComponent extends BaseList implements OnChanges {
@Input() kycList: any = [];
@Output() edit = new EventEmitter();
@Output() search = new EventEmitter();
query = {
name: null,
card: null
}
name: string;
filterCard: Subject<string> = new Subject<string>();
constructor() {
super()
this.filterCard.pipe(
debounceTime(500),
distinctUntilChanged()
).subscribe(() => this.onSearch())
}
getData(event: any) {
ngOnChanges(): void {
this.kycList = this.updateMatTable(this.kycList? this.kycList:[])
}
onEdit(uid){
this.edit.emit(uid)
}
onFilterCard($event) {
// this.filterCard.next($event);
const filterValue = this.query.card;
this.kycList.filter = filterValue.trim().toLowerCase();
}
onFilterName($event){
const filterValue = this.query.name;
this.kycList.filter = filterValue.trim().toLowerCase();
}
onSearch(){
const filterValue = this.query.card;
this.kycList.filter = filterValue.trim().toLowerCase();
}
}