From cc5b1e4ba933aa344d642d35134f94ac9ee8c2e4 Mon Sep 17 00:00:00 2001 From: gofnnp Date: Thu, 1 Jun 2023 10:09:57 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#14250=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=B5=D0=BD=D1=8E=D1=85=D1=83,=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2,=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular/package.json | 2 +- angular/proxy.confi.json | 15 +- angular/src/app/app.constants.ts | 16 +- angular/src/app/app.module.ts | 2 + angular/src/app/interface/data.ts | 2 + .../app/pages/account/account.component.html | 58 +------- .../app/pages/account/account.component.ts | 9 ++ .../account/orders/orders.component.html | 2 +- .../account/orders/orders.component.scss | 5 + .../pages/account/orders/orders.component.ts | 121 +++++++++++---- .../purcahses/purcahses.component.html | 140 ++++++++++++++++++ .../purcahses/purcahses.component.scss | 91 ++++++++++++ .../purcahses/purcahses.component.spec.ts | 23 +++ .../account/purcahses/purcahses.component.ts | 57 +++++++ .../app/pages/products/products.component.ts | 1 + angular/src/app/services/order.service.ts | 2 +- angular/src/app/services/wp-json.service.ts | 5 + .../src/app/state/profile/profile.effects.ts | 6 +- angular/src/environments/environment.prod.ts | 2 +- angular/src/environments/environment.ts | 2 +- 20 files changed, 459 insertions(+), 102 deletions(-) create mode 100644 angular/src/app/pages/account/purcahses/purcahses.component.html create mode 100644 angular/src/app/pages/account/purcahses/purcahses.component.scss create mode 100644 angular/src/app/pages/account/purcahses/purcahses.component.spec.ts create mode 100644 angular/src/app/pages/account/purcahses/purcahses.component.ts diff --git a/angular/package.json b/angular/package.json index c314dfc..592e492 100644 --- a/angular/package.json +++ b/angular/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "scripts": { "ng": "ng", - "start": "ng serve --host 192.168.0.14", + "start": "ng serve --host 192.168.0.14 --verbose", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test" diff --git a/angular/proxy.confi.json b/angular/proxy.confi.json index d5a8fdc..848b83a 100644 --- a/angular/proxy.confi.json +++ b/angular/proxy.confi.json @@ -1,13 +1,4 @@ { - "/api": { - "target": "https://apple-push-notifications.it-retail.tech/apns/api", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "changeOrigin": true, - "logLevel": "debug" - }, "/icard-proxy": { "target": "https://sakura.lk.crm4retail.ru/api/icard-proxy", "secure": false, @@ -26,11 +17,11 @@ "changeOrigin": true, "logLevel": "debug" }, - "/it-retail": { - "target": "https://sakura.lk.crm4retail.ru/it-retail", + "/api/orders": { + "target": "https://sakura.lk.crm4retail.ru/api/orders", "secure": false, "pathRewrite": { - "^/it-retail": "" + "^/api/orders": "" }, "changeOrigin": true, "logLevel": "debug" diff --git a/angular/src/app/app.constants.ts b/angular/src/app/app.constants.ts index 3cc2229..0df510e 100644 --- a/angular/src/app/app.constants.ts +++ b/angular/src/app/app.constants.ts @@ -37,13 +37,27 @@ export const PageListWithBonus: Page[] = [ resName: 'bonus-program', onSideBar: false, }, + { + code: PageCode.Transactions, + name: 'Чеки', + description: '', + resName: 'transactions', + onSideBar: true, + }, { code: PageCode.Orders, - name: 'Ваши чеки', + name: 'Заказы', description: '', resName: 'orders', onSideBar: true, }, + { + code: PageCode.Logout, + name: 'Выйти', + description: '', + resName: 'logout', + onSideBar: true, + }, // { // code: PageCode.UserData, // name: 'Заполнить анкету', diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.ts index 859050e..ef1df65 100644 --- a/angular/src/app/app.module.ts +++ b/angular/src/app/app.module.ts @@ -80,6 +80,7 @@ import {MatNativeDateModule} from '@angular/material/core'; import { profileReducer } from './state/profile/profile.reducer'; import { ProfileEffects } from './state/profile/profile.effects'; import { CustomerInfoInterceptor } from './interceptors/customer-info.interceptor'; +import { PurcahsesComponent } from './pages/account/purcahses/purcahses.component'; const routes: Routes = [ { path: '', redirectTo: 'products', pathMatch: 'full' }, @@ -120,6 +121,7 @@ const routes: Routes = [ SnackBarComponent, PurchaseInfoComponent, DateFilterComponent, + PurcahsesComponent, ], imports: [ BrowserModule, diff --git a/angular/src/app/interface/data.ts b/angular/src/app/interface/data.ts index 0c34541..7137c37 100644 --- a/angular/src/app/interface/data.ts +++ b/angular/src/app/interface/data.ts @@ -6,6 +6,8 @@ export enum PageCode { Orders, RefSystem, UserData, + Transactions, + Logout } export enum MainPageCode { diff --git a/angular/src/app/pages/account/account.component.html b/angular/src/app/pages/account/account.component.html index 424be70..74a6d65 100644 --- a/angular/src/app/pages/account/account.component.html +++ b/angular/src/app/pages/account/account.component.html @@ -11,67 +11,21 @@ [currentPage]="currentPage" (deauthorization)="changePage(pageList[0])" > - - - +
- + + + + diff --git a/angular/src/app/pages/account/account.component.ts b/angular/src/app/pages/account/account.component.ts index 5ba9aa1..934c903 100644 --- a/angular/src/app/pages/account/account.component.ts +++ b/angular/src/app/pages/account/account.component.ts @@ -13,6 +13,7 @@ import { lastValueFrom } from 'rxjs'; import { CartService } from 'src/app/services/cart.service'; import { Store } from '@ngrx/store'; import { getProfile, getTransactions, getTransactionsInfo } from 'src/app/state/profile/profile.actions'; +import { MatTabChangeEvent } from '@angular/material/tabs'; @Component({ selector: 'app-account', @@ -24,6 +25,7 @@ export class AccountComponent implements OnInit { @Output() setUserDataOrderPage = new EventEmitter(); @ViewChild('menu', { static: true}) menu!: ElementRef; public refSystemId: string = ''; + public selectedTabPage: number = 1 constructor( private cookiesService: CookiesService, @@ -225,6 +227,13 @@ export class AccountComponent implements OnInit { this.messageService.clear('c') } + changeTabPage(event: MatTabChangeEvent) { + if (event.index === 2) { + this.selectedTabPage = 1 + this.logout() + } + } + logout(event?: MouseEvent) { if (event) { event.preventDefault() diff --git a/angular/src/app/pages/account/orders/orders.component.html b/angular/src/app/pages/account/orders/orders.component.html index 510f2b5..01fe8ab 100644 --- a/angular/src/app/pages/account/orders/orders.component.html +++ b/angular/src/app/pages/account/orders/orders.component.html @@ -101,7 +101,7 @@ > Показать больше

-

+

Данные не найдены

{ - if (transactions && transactionsInfo) { - this.purchases = transactions - .map((purchase) => { - return { - ...purchase, - more_info: - transactionsInfo.find( - (purchaseInfo: PurchaseInfo) => - Number(purchaseInfo.number) === purchase.orderNumber - ) || null, - }; - }) - .filter((purchase: Purchase) => - [ - 'PayFromWallet', - 'CancelPayFromWallet', - 'RefillWallet', - ].includes(purchase.transactionType) - ); + this.transactionsState$.subscribe({ + next: (transactions) => { + // console.log(transactions); + + if (transactions) { + this.purchases = transactions.filter((purchase: Purchase) => + ['PayFromWallet', 'CancelPayFromWallet', 'RefillWallet'].includes( + purchase.transactionType + ) + ); + + this.ordersLoadingStatus = false + this.transactionsInfoState$.subscribe({ + next: (transactionsInfo) => { + if (transactionsInfo) { + this.purchases.map((purchase) => { + return { + ...purchase, + more_info: + transactionsInfo.find( + (purchaseInfo: PurchaseInfo) => + Number(purchaseInfo.number) === purchase.orderNumber + ) || null, + }; + }); + } + }, + }); + } + }, + }); - this.ordersLoadingStatus = false; - this.dateFilter({ filterType: this.defaultFilterType }); - } - }, - }); + // combineLatest([this.transactionsState$, this.transactionsInfoState$]) + // .pipe(distinctUntilChanged()) + // .subscribe({ + // next: ([transactions, transactionsInfo]) => { + // console.log('####: ', transactions); + // console.log('####I: ', transactionsInfo); + + // if (transactions && transactionsInfo) { + // this.purchases = transactions + // .map((purchase) => { + // return { + // ...purchase, + // more_info: + // transactionsInfo.find( + // (purchaseInfo: PurchaseInfo) => + // Number(purchaseInfo.number) === purchase.orderNumber + // ) || null, + // }; + // }) + // .filter((purchase: Purchase) => + // [ + // 'PayFromWallet', + // 'CancelPayFromWallet', + // 'RefillWallet', + // ].includes(purchase.transactionType) + // ); + // } else if (transactions && !transactionsInfo) { + // this.purchases = transactions.filter((purchase: Purchase) => + // ['PayFromWallet', 'CancelPayFromWallet', 'RefillWallet'].includes( + // purchase.transactionType + // ) + // ); + // this._snackBar.open( + // 'Произошла ошибка получения подробностей по транзакциям', + // '', + // { + // duration: 3500, + // } + // ); + // } else { + // this._snackBar.open( + // 'Произошла ошибка получения данных по транзакциям', + // '', + // { + // duration: 3500, + // } + // ); + // } + // this.ordersLoadingStatus = false; + // console.log(this.purchases); + + // this.dateFilter({ filterType: this.defaultFilterType }); + // }, + // error: (err) => { + // console.error('Error: ', err); + // this.ordersLoadingStatus = false; + // }, + // }); } getMoreOrders() { diff --git a/angular/src/app/pages/account/purcahses/purcahses.component.html b/angular/src/app/pages/account/purcahses/purcahses.component.html new file mode 100644 index 0000000..becac90 --- /dev/null +++ b/angular/src/app/pages/account/purcahses/purcahses.component.html @@ -0,0 +1,140 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/angular/src/app/pages/account/purcahses/purcahses.component.scss b/angular/src/app/pages/account/purcahses/purcahses.component.scss new file mode 100644 index 0000000..b8bf8b7 --- /dev/null +++ b/angular/src/app/pages/account/purcahses/purcahses.component.scss @@ -0,0 +1,91 @@ +.show-more-orders { + text-align: center; + cursor: pointer; + color: var(--orange-main); + margin-top: 16px; + } + .not-found-data { + text-align: center; + color: var(--orange-main); + margin-top: 16px; + } + .woocommerce-MyAccount-content { + max-width: 400px; + margin-left: calc(50vw - 200px); + } + .woocommerce-orders-table { + // border: 2px solid #dee2e6; + border-bottom: 0; + border-radius: 0.25rem; + border-collapse: separate; + text-align: left; + margin-top: 8px; + width: 100%; + // max-width: 400px; + margin-left: auto; + margin-right: auto; + thead { + display: none; + } + .woocommerce-orders-table { + &__cell { + padding: 0.7rem 1.5rem; + border-bottom: 2px solid #dee2e6; + text-align: right !important; + display: block; + min-height: 46px; + &::before { + content: attr(data-title) ": "; + font-weight: 700; + float: left; + } + } + &__row { + display: block; + &:nth-child(even) { + background: #ebebeb; + } + } + // &__cell-order-actions::before { + // display: none; + // } + &__cell-order-actions { + &.red-color { + color: #ed0000; + } + &.green-color { + color: #00a700; + } + } + &__cell-order-number a { + text-decoration: none; + color: #009688; + } + } + + .woocommerce-button { + display: inline-block; + color: #ffffff; + background-color: #009688; + padding: 13px; + border-radius: 4px; + text-decoration: none; + width: 100%; + text-align: center; + } + } + + :host { + .orders { + h2 { + font-style: normal; + font-weight: 700; + font-size: 20px; + line-height: 24px; + max-width: 400px; + margin: 0 auto; + width: 100%; + } + } + } + \ No newline at end of file diff --git a/angular/src/app/pages/account/purcahses/purcahses.component.spec.ts b/angular/src/app/pages/account/purcahses/purcahses.component.spec.ts new file mode 100644 index 0000000..26dfc4b --- /dev/null +++ b/angular/src/app/pages/account/purcahses/purcahses.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PurcahsesComponent } from './purcahses.component'; + +describe('PurcahsesComponent', () => { + let component: PurcahsesComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PurcahsesComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(PurcahsesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/angular/src/app/pages/account/purcahses/purcahses.component.ts b/angular/src/app/pages/account/purcahses/purcahses.component.ts new file mode 100644 index 0000000..3da534a --- /dev/null +++ b/angular/src/app/pages/account/purcahses/purcahses.component.ts @@ -0,0 +1,57 @@ +import { Component, OnInit } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import moment from 'moment'; +import { orderStatuses } from 'src/app/app.constants'; +import { PurchaseInfoComponent } from 'src/app/components/purchase-info/purchase-info.component'; +import { PurchaseInfo } from 'src/app/interface/data'; +import { WpJsonService } from 'src/app/services/wp-json.service'; +import { environment } from 'src/environments/environment'; + +@Component({ + selector: 'app-purcahses', + templateUrl: './purcahses.component.html', + styleUrls: ['./purcahses.component.scss'], +}) +export class PurcahsesComponent implements OnInit { + public purchases: any; + readonly moment = moment; + public orderStatuses = orderStatuses; + public loading = true; + + constructor(private wpJsonService: WpJsonService, public dialog: MatDialog) {} + + ngOnInit(): void { + this.wpJsonService.getUserOrders(environment.webhookItRetail).subscribe({ + next: (value) => { + this.purchases = value.result.map((purchase: any) => { + purchase.orderAmount = purchase.data.products.reduce( + (previous: any, current: any) => { + return previous + Number(current.amount); + }, + 0 + ); + purchase.more_info = { + date: purchase.created_datetime, + goods_list: purchase.data.products.map((product: any) => { + return { + name: product.name, + price: product.price, + quantity: product.quantity, + }; + }), + number: purchase.public_id, + sum: purchase.orderAmount, + }; + return purchase; + }); + this.loading = false; + }, + }); + } + + showPurchaseInfo(purchaseInfo: PurchaseInfo) { + const dialogRef = this.dialog.open(PurchaseInfoComponent, { + data: { purchaseInfo }, + }); + } +} diff --git a/angular/src/app/pages/products/products.component.ts b/angular/src/app/pages/products/products.component.ts index c0f7c9e..38af509 100644 --- a/angular/src/app/pages/products/products.component.ts +++ b/angular/src/app/pages/products/products.component.ts @@ -10,6 +10,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { MatBottomSheet } from '@angular/material/bottom-sheet'; import { TerminalListComponent } from 'src/app/components/terminal-list/terminal-list.component'; import { GetTerminalsService } from 'src/app/services/get-terminals.service'; +import { environment } from 'src/environments/environment'; @Component({ selector: 'app-products', diff --git a/angular/src/app/services/order.service.ts b/angular/src/app/services/order.service.ts index 11b8910..1d0f0de 100644 --- a/angular/src/app/services/order.service.ts +++ b/angular/src/app/services/order.service.ts @@ -167,7 +167,7 @@ export class OrderService { submit(): Observable { return this.wpJsonService - .createOrder(this.order.toJson(), environment.webhookItRetail) + .createOrder(this.order.toJson(), `${environment.webhookItRetail}handlers/tillda/115eaf95-bb44-4cfc-851a-fec5325b45ff`) .pipe( tap({ next: (_) => { diff --git a/angular/src/app/services/wp-json.service.ts b/angular/src/app/services/wp-json.service.ts index c4ee336..68fb9fb 100644 --- a/angular/src/app/services/wp-json.service.ts +++ b/angular/src/app/services/wp-json.service.ts @@ -70,12 +70,17 @@ export class WpJsonService { return this._request(`/static/settings.json`, 'GET', null, false) } + getUserOrders(url: string): Observable { + return this._request(`/api/user/orders`, 'GET', null, true, url) + } + _request(path: string, method: string, body?: any, auth = false, baseUrl?: string): Observable { const token = decodeURI(this.cookiesService.getItem('token') ?? ''); let headers = new HttpHeaders(); headers = headers.set('Content-Type', 'application/json'); let urlToken = ''; if (token && token !== 'undefined' && auth) { + headers = headers.set('Authorization', `Bearer ${token}`) urlToken = '?token=' + token; } this.body = body; diff --git a/angular/src/app/state/profile/profile.effects.ts b/angular/src/app/state/profile/profile.effects.ts index 1d75ef1..c3bce2e 100644 --- a/angular/src/app/state/profile/profile.effects.ts +++ b/angular/src/app/state/profile/profile.effects.ts @@ -33,7 +33,7 @@ export class ProfileEffects { throw new Error('Пользователь не найден в системе! Обратитесь к руководству') } if ('Error' in value) { - throw new Error('Ошибка получения данных'); + throw new Error('Ошибка получения данных пользователя'); } return { getSuccessResponse: value, @@ -68,7 +68,7 @@ export class ProfileEffects { throw new Error('Пользователь не найден в системе! Обратитесь к руководству') } if ('Error' in value) { - throw new Error('Ошибка получения данных'); + throw new Error('Ошибка получения данных по транзакциям'); } return { getSuccessResponse: { @@ -105,7 +105,7 @@ export class ProfileEffects { throw new Error('Пользователь не найден в системе! Обратитесь к руководству') } if ('Error' in value) { - throw new Error('Ошибка получения данных'); + throw new Error('Ошибка получения данных подробностей по транзакциям'); } return { getSuccessResponse: { diff --git a/angular/src/environments/environment.prod.ts b/angular/src/environments/environment.prod.ts index 8c7af68..3203eda 100644 --- a/angular/src/environments/environment.prod.ts +++ b/angular/src/environments/environment.prod.ts @@ -20,7 +20,7 @@ export const environment = { version: packageJson.version, appleWalletEndpoint: 'https://apple-push-notifications.it-retail.tech/apns/api', appleWalletSecret: 'Token F5mbzEERAznGKVbB6l', - webhookItRetail: 'https://sakura.lk.crm4retail.ru/api/orders/handlers/tillda/115eaf95-bb44-4cfc-851a-fec5325b45ff', + webhookItRetail: 'https://sakura.lk.crm4retail.ru/api/orders/', icardProxy: 'https://sakura.lk.crm4retail.ru/api/icard-proxy/', clientName: 'sakura', cities: ['Менделеевск'], diff --git a/angular/src/environments/environment.ts b/angular/src/environments/environment.ts index 8e50c00..54486bb 100644 --- a/angular/src/environments/environment.ts +++ b/angular/src/environments/environment.ts @@ -20,7 +20,7 @@ export const environment = { version: packageJson.version, appleWalletEndpoint: 'http://192.168.0.179:4200/apns/api', appleWalletSecret: 'Token F5mbzEERAznGKVbB6l', - webhookItRetail: 'http://192.168.0.14:4200/it-retail/handlers/tillda/1eb3fb56-3c4c-43b7-9a04-ce532ab7548f', + webhookItRetail: 'http://192.168.0.14:4200/api/orders', icardProxy: 'http://192.168.0.14:4200/icard-proxy/', clientName: 'sakura', cities: ['Менделеевск'],