parent
10ad10d922
commit
00a47756b2
@ -108,6 +108,7 @@ export class ProductModalComponent implements OnInit {
|
||||
return
|
||||
}
|
||||
}
|
||||
this.cartService.changeTerminal(this.config.data.selectedTerminal)
|
||||
this.cartService.addToCart(this.cartProduct);
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import { GetTerminalsService } from 'src/app/services/get-terminals.service';
|
||||
export class UserDataOrderComponent implements OnInit, OnDestroy {
|
||||
|
||||
@Output() orderSubmitted = new EventEmitter<number>();
|
||||
@Output() userNotFound = new EventEmitter<null>();
|
||||
readonly cities = environment.cities;
|
||||
public paymentMethods!: PaymentMethod[];
|
||||
public loading = false;
|
||||
@ -229,6 +230,9 @@ export class UserDataOrderComponent implements OnInit, OnDestroy {
|
||||
|
||||
private async _createUserDataForm(): Promise<FormGroup> {
|
||||
this.order = await this.orderService.getOrder(true);
|
||||
if (this.order.userData?.errorCode === "Customer_CustomerNotFound") {
|
||||
this.userNotFound.emit(null)
|
||||
}
|
||||
this.userData = Object.assign({}, this.userData, this.order.userData);
|
||||
this.userData.city = this.cities[0];
|
||||
this.userData.phone = this.order.phone;
|
||||
|
||||
@ -252,7 +252,8 @@ export interface UserData {
|
||||
city: string;
|
||||
phone: string | null;
|
||||
selectedTerminal: ITerminal | null;
|
||||
name: string
|
||||
name: string;
|
||||
errorCode?: string;
|
||||
}
|
||||
|
||||
export interface ITerminal {
|
||||
|
||||
@ -6,7 +6,7 @@ import { environment } from "src/environments/environment";
|
||||
|
||||
export interface OrderInfo {
|
||||
products: OrderProduct[];
|
||||
userData?: UserData;
|
||||
userData: UserData | null;
|
||||
deliveryData?: DeliveryData;
|
||||
phone: string;
|
||||
token: string | undefined;
|
||||
@ -16,7 +16,7 @@ export interface OrderInfo {
|
||||
export class Order {
|
||||
|
||||
public products: OrderProduct[];
|
||||
public userData?: UserData;
|
||||
public userData!: UserData | null;
|
||||
public deliveryData?: DeliveryData;
|
||||
public phone: string;
|
||||
public token: string | undefined;
|
||||
|
||||
@ -15,6 +15,9 @@
|
||||
</div>
|
||||
<div class="card-container__content">
|
||||
<div class="info">
|
||||
<div *ngIf="!accountData && !loadingBonuses" class="info__row">
|
||||
Пользователь не найден, обратитесь к руководству
|
||||
</div>
|
||||
<div *ngIf="accountData" class="info__row">
|
||||
<span class="key">Имя</span>
|
||||
<span class="value" *ngIf="userName.length">{{
|
||||
|
||||
@ -11,6 +11,7 @@ import { CookiesService } from 'src/app/services/cookies.service';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { WpJsonService } from 'src/app/services/wp-json.service';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bonus-program',
|
||||
@ -36,6 +37,7 @@ export class BonusProgramComponent implements OnInit {
|
||||
@Inject(DOCUMENT) private document: Document,
|
||||
private http: HttpClient,
|
||||
private wpJsonService: WpJsonService,
|
||||
private _snackBar: MatSnackBar
|
||||
) { }
|
||||
|
||||
|
||||
@ -55,6 +57,11 @@ export class BonusProgramComponent implements OnInit {
|
||||
this.loadingBonuses = true;
|
||||
this.wpJsonService.getCustomerInfo(environment.systemId, token, environment.icardProxy).subscribe({
|
||||
next: (res) => {
|
||||
if (res.customer_info.errorCode === 'Customer_CustomerNotFound') {
|
||||
// this._snackBar.open('Пользователь не найден в системе! Обратитесь к руководству', 'Ок')
|
||||
this.loadingBonuses = false;
|
||||
return
|
||||
}
|
||||
this.userName = res.customer_info.name
|
||||
this.accountData = {
|
||||
CardNumber: res.customer_info.cards[0]?.Number || '',
|
||||
|
||||
@ -46,6 +46,10 @@ export class OrdersComponent implements OnInit {
|
||||
const customerInfo = (await lastValueFrom(
|
||||
this.wpJsonService.getCustomerInfo(environment.systemId, token, environment.icardProxy)
|
||||
))
|
||||
if (customerInfo.customer_info.errorCode === 'Customer_CustomerNotFound') {
|
||||
this.ordersLoadingStatus = false;
|
||||
return
|
||||
}
|
||||
const purchases: Purchase[] = (await lastValueFrom(
|
||||
this.wpJsonService.getTransactions(environment.systemId, token, environment.icardProxy, 30)
|
||||
))[customerInfo.customer_info.id];
|
||||
|
||||
@ -154,47 +154,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p-toast
|
||||
position="bottom-center"
|
||||
key="c"
|
||||
(onClose)="onReject()"
|
||||
[baseZIndex]="5000"
|
||||
>
|
||||
<ng-template let-message pTemplate="message">
|
||||
<div class="flex flex-column" style="flex: 1">
|
||||
<div class="text-center">
|
||||
<i class="pi pi-exclamation-triangle" style="font-size: 3rem"></i>
|
||||
<h4>{{ message.summary }}</h4>
|
||||
<p style="font-weight: 600">{{ message.detail }}</p>
|
||||
</div>
|
||||
<div class="grid p-fluid">
|
||||
<div class="col-6">
|
||||
<button
|
||||
type="button"
|
||||
pButton
|
||||
(click)="onConfirm()"
|
||||
label="Да"
|
||||
class="p-button-success"
|
||||
></button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button
|
||||
type="button"
|
||||
pButton
|
||||
(click)="onReject()"
|
||||
label="Нет"
|
||||
class="p-button-secondary"
|
||||
></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-toast>
|
||||
</div>
|
||||
|
||||
<app-user-data-order
|
||||
*ngIf="orderConfirmed"
|
||||
(orderSubmitted)="orderSubmitted($event)"
|
||||
(userNotFound)="userNotFound($event)"
|
||||
></app-user-data-order>
|
||||
|
||||
<div #loadingEl *ngIf="loading && !orderConfirmed">
|
||||
|
||||
@ -72,10 +72,19 @@ export class CartComponent implements OnInit {
|
||||
async loadCart(): Promise<void> {
|
||||
this.loading = true;
|
||||
this.order = await this.orderService.getOrder(true);
|
||||
if (this.order?.userData?.errorCode === 'Customer_CustomerNotFound') {
|
||||
this.userNotFound()
|
||||
return
|
||||
}
|
||||
if (this.order) this.price = this.order.price;
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
userNotFound(event: null = null) {
|
||||
this.visibleSidebar = false
|
||||
this._snackBar.open('Пользователь не найден в системе! Обратитесь к руководству', 'Ок')
|
||||
}
|
||||
|
||||
removeFromCart(event: Event, guid: string): void {
|
||||
event.preventDefault();
|
||||
this.orderService.removeFromCart(guid);
|
||||
@ -125,17 +134,5 @@ export class CartComponent implements OnInit {
|
||||
this.visibleSidebar = false;
|
||||
}
|
||||
});
|
||||
// this.messageService.add({ key: 'c', sticky: true, severity: 'warn', summary: 'Вы уверены, что хотите очистить корзину?' });
|
||||
}
|
||||
|
||||
onReject() {
|
||||
this.messageService.clear('c');
|
||||
}
|
||||
|
||||
onConfirm() {
|
||||
this.cartService.clearCart();
|
||||
this.loadCart();
|
||||
this.visibleSidebar = false;
|
||||
this.messageService.clear('c');
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
</div>
|
||||
<div class="products-container__items">
|
||||
<div
|
||||
*ngFor="let product of filterByGroup(group)"
|
||||
*ngFor="let product of filterByGroup(group); trackBy: trackProducts"
|
||||
(click)="addToCart($event, product)"
|
||||
class="products-container__item"
|
||||
#currentCategoryList
|
||||
@ -72,7 +72,7 @@
|
||||
<ng-container *ngIf="selectedGroup && selectedGroup.label !== 'Все'">
|
||||
<div class="products-container__items">
|
||||
<div
|
||||
*ngFor="let product of filterByGroup()"
|
||||
*ngFor="let product of filterByGroup(); trackBy: trackProducts"
|
||||
(click)="addToCart($event, product)"
|
||||
class="products-container__item"
|
||||
#currentCategoryList
|
||||
|
||||
@ -141,6 +141,7 @@ export class ProductsComponent implements OnInit {
|
||||
product: product,
|
||||
modifiersGroups: this.modifiersGroups,
|
||||
modifiers: this.modifiers,
|
||||
selectedTerminal: this.selectedTerminal
|
||||
},
|
||||
baseZIndex: 10000,
|
||||
autoZIndex: true,
|
||||
@ -182,4 +183,8 @@ export class ProductsComponent implements OnInit {
|
||||
});
|
||||
this.currentPage = 0;
|
||||
}
|
||||
|
||||
trackProducts(index: number, product: Product) {
|
||||
return product.id
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +52,20 @@ export class OrderService {
|
||||
// RpcService.authService,
|
||||
// true
|
||||
// );
|
||||
const terminal =
|
||||
JSON.parse(
|
||||
this.cookiesService.getItem('selectedTerminal') || 'null'
|
||||
) || this.cartService.selectedTerminal$;
|
||||
if (!token.length) {
|
||||
this.order = new Order({
|
||||
products: products,
|
||||
userData: null,
|
||||
phone: '',
|
||||
token: token,
|
||||
terminal_id: terminal.id,
|
||||
});
|
||||
return this.order;
|
||||
}
|
||||
const additionalInfo = this.wpJsonService.getCustomerInfo(
|
||||
environment.systemId,
|
||||
token,
|
||||
@ -70,12 +84,8 @@ export class OrderService {
|
||||
const info = await lastValueFrom(
|
||||
forkJoin([additionalInfo, tokenData, products])
|
||||
);
|
||||
const customer_info = info[0]?.customer_info
|
||||
const customer_info = info[0]?.customer_info;
|
||||
|
||||
const terminal =
|
||||
JSON.parse(
|
||||
this.cookiesService.getItem('selectedTerminal') || 'null'
|
||||
) || this.cartService.selectedTerminal$;
|
||||
this.order = new Order({
|
||||
products: products,
|
||||
userData: customer_info,
|
||||
@ -92,12 +102,14 @@ export class OrderService {
|
||||
|
||||
async getProducts(cart: Cart): Promise<OrderProduct[]> {
|
||||
const terminal =
|
||||
JSON.parse(this.cookiesService.getItem('selectedTerminal') || 'null') ||
|
||||
this.cartService.selectedTerminal$;
|
||||
JSON.parse(this.cookiesService.getItem('selectedTerminal') || 'null');
|
||||
const products: OrderProduct[] = [];
|
||||
if (!terminal) {
|
||||
return products
|
||||
}
|
||||
const allData = await lastValueFrom(
|
||||
this.wpJsonService.getAllData(`${terminal.label}${terminal.id}`)
|
||||
);
|
||||
const products: OrderProduct[] = [];
|
||||
for (let i = 0; i < cart.products.length; i++) {
|
||||
const productSub = allData.products.find(
|
||||
(product: any) => product.id === cart.products[i].id
|
||||
|
||||
Loading…
Reference in New Issue
Block a user