This commit is contained in:
gofnnp 2023-05-02 11:39:19 +04:00
parent af60b55e94
commit 42b46bc478
3 changed files with 48 additions and 17 deletions

View File

@ -52,6 +52,7 @@ import {
MatBottomSheetModule, MatBottomSheetModule,
MatBottomSheetRef, MatBottomSheetRef,
} from '@angular/material/bottom-sheet'; } from '@angular/material/bottom-sheet';
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -109,6 +110,7 @@ import {
MatInputModule, MatInputModule,
MatSnackBarModule, MatSnackBarModule,
MatBottomSheetModule, MatBottomSheetModule,
MatProgressSpinnerModule
], ],
providers: [ providers: [
DialogService, DialogService,

View File

@ -8,16 +8,21 @@
<div class="guest-card"> <div class="guest-card">
<div class="guest-card__qr" (click)="qrCodeClick()"> <div class="guest-card__qr" (click)="qrCodeClick()">
<qr-code <qr-code
*ngIf="user; else spinner"
[value]="user?.customer_info?.phone.substr(2) || 'Данные не найдены'" [value]="user?.customer_info?.phone.substr(2) || 'Данные не найдены'"
[margin]="0" [margin]="0"
[size]="qrCodeSize" [size]="qrCodeSize"
errorCorrectionLevel="M" errorCorrectionLevel="M"
></qr-code> ></qr-code>
</div> </div>
<div class="guest-card__user-description"> <div class="guest-card__user-description">
За период с 11.01.2023 по 31.03.2023 вам начислено Текущий баланс бонусов:
<span>360 бонусов</span> <span *ngIf="user">
{{
getBalanceAmount(user?.customer_info?.walletBalances)
}}
бонусов</span
>
</div> </div>
<app-accordion header="Условия начисления бонусов"> <app-accordion header="Условия начисления бонусов">
<p> <p>
@ -151,3 +156,7 @@
> >
</div> </div>
</ng-template> </ng-template>
<ng-template #spinner>
<mat-spinner></mat-spinner>
</ng-template>

View File

@ -8,9 +8,7 @@ import { WpJsonService } from 'src/app/services/wp-json.service';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import moment from 'moment'; import moment from 'moment';
interface Moment extends moment.Moment { interface Moment extends moment.Moment {}
}
@Component({ @Component({
selector: 'app-guest-card', selector: 'app-guest-card',
@ -33,10 +31,14 @@ export class GuestCardComponent implements OnInit {
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
const token = this.cookiesService.getItem('token') const token = this.cookiesService.getItem('token');
this.customerInfo = this.wpJsonService.getCustomerInfo(environment.systemId, token || '', environment.icardProxy) this.customerInfo = this.wpJsonService.getCustomerInfo(
this.purchases = this.getPurchases() environment.systemId,
// this.purchases.subscribe((value) => console.log(value)); token || '',
environment.icardProxy
);
this.purchases = this.getPurchases();
this.purchases.subscribe((value) => console.log(value));
} }
qrCodeClick() { qrCodeClick() {
@ -49,20 +51,38 @@ export class GuestCardComponent implements OnInit {
} }
logout() { logout() {
const bottomSheet = this._bottomSheet.open(ExitComponent) const bottomSheet = this._bottomSheet.open(ExitComponent);
bottomSheet.afterDismissed().subscribe({ bottomSheet.afterDismissed().subscribe({
next: (val) => { next: (val) => {
if (val) { if (val) {
this.deleteToken(); this.deleteToken();
this.router.navigate(['/login']); this.router.navigate(['/login']);
} }
} },
}) });
} }
getPurchases(start: Date | Moment = moment().startOf('month'), end: Date | Moment = moment()): Observable<any> { getPurchases(
const token = this.cookiesService.getItem('token') start: Date | Moment = moment().startOf('month'),
const delta = moment(end).diff(moment(start), 'days') end: Date | Moment = moment()
return this.wpJsonService.getTransactionsInfo(environment.systemId, token ?? '', environment.icardProxy) ): Observable<any> {
const token = this.cookiesService.getItem('token');
const delta = moment(end).diff(moment(start), 'days');
return this.wpJsonService.getTransactionsInfo(
environment.systemId,
token ?? '',
environment.icardProxy
);
}
getBalanceAmount(loyaltyPrograms: any[]) {
console.log(loyaltyPrograms);
return loyaltyPrograms.reduce(
(accumulator, currentValue) => {
return accumulator + currentValue.balance
},
0
);
} }
} }