diff --git a/src/app/sales/cart-sales/cart-sales.component.html b/src/app/sales/cart-sales/cart-sales.component.html index 85ed134..dd22b55 100644 --- a/src/app/sales/cart-sales/cart-sales.component.html +++ b/src/app/sales/cart-sales/cart-sales.component.html @@ -1,5 +1,11 @@
+
+
+ +
Carregando dados do pedido...
+
+
- @@ -933,7 +939,7 @@ message="{{ messageConfirmation }}" textButtonConfirmation="{{ textButtonConfirmation }}" textButtonCancel="{{ textButtonCancel }}" (resultEvent)="confirmChangePaymentPlan($event)"> - diff --git a/src/app/sales/cart-sales/cart-sales.component.scss b/src/app/sales/cart-sales/cart-sales.component.scss index 221a9cd..c5aebd6 100644 --- a/src/app/sales/cart-sales/cart-sales.component.scss +++ b/src/app/sales/cart-sales/cart-sales.component.scss @@ -991,6 +991,26 @@ kendo-treeview:hover { } } +.loading-overlay { + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + background-color: rgba(255, 255, 255, 0.7); + z-index: 9999; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; +} + +.loading-content { + text-align: center; + font-weight: 600; + color: #2d2e83; +} + /* Responsividade para desktops maiores (largura > 1200px) */ @media (min-width: 1200px) { .card-resume { diff --git a/src/app/sales/cart-sales/cart-sales.component.ts b/src/app/sales/cart-sales/cart-sales.component.ts index 178a38a..1791e80 100644 --- a/src/app/sales/cart-sales/cart-sales.component.ts +++ b/src/app/sales/cart-sales/cart-sales.component.ts @@ -278,7 +278,7 @@ export class CartSalesComponent ) { } ngOnChanges(changes: SimpleChanges): void { - this.loadShopping(); + //this.loadShopping(); } ngAfterViewInit(): void { } @@ -326,18 +326,9 @@ export class CartSalesComponent } } - loadShopping() { - this.shoppingSubscription = this.shopping$.subscribe((data) => { - this.shopping = data; - if (this.shopping !== null) { - this.totalWeight = data.totpeso; - this.loadFormOrder(); - } - }); - } - getTaxValue() { const taxDelivery = JSON.parse(localStorage.getItem('taxDelivery')); + if (!this.formResumeOrder) return 0; const taxValue = Number.parseFloat( this.formResumeOrder.get('taxValue').value ); @@ -345,18 +336,24 @@ export class CartSalesComponent return taxDelivery != null ? taxDelivery.taxValue : taxValue; } - loadFormOrder() { - this.subscriptionShopping = this.shopping$.subscribe((data) => { - const taxDelivery = JSON.parse(localStorage.getItem('taxDelivery')); - this.formResumeOrder = this.fb.group({ - taxValue: [ - taxDelivery.taxValue > 0 ? taxDelivery.taxValue.toFixed(2) : '0', - ], - discount: [data.vldesconto > 0 ? data.vldesconto.toFixed(2) : '0,00'], - carrierId: [taxDelivery.carrierId], - deliveryTaxId: [taxDelivery.deliveryTaxId], + loadFormOrder(data?: Shopping) { + if (!data && this.shopping) { + data = this.shopping; + } + if (!data) return; + + const taxDelivery = JSON.parse(localStorage.getItem('taxDelivery')); + if (this.formResumeOrder) { + this.formResumeOrder.patchValue({ + taxValue: + taxDelivery != null && taxDelivery.taxValue > 0 + ? taxDelivery.taxValue.toFixed(2) + : '0', + discount: data.vldesconto > 0 ? data.vldesconto.toFixed(2) : '0,00', + carrierId: taxDelivery != null ? taxDelivery.carrierId : 0, + deliveryTaxId: taxDelivery != null ? taxDelivery.deliveryTaxId : 0, }); - }); + } } ngOnInit(): void { @@ -449,6 +446,7 @@ export class CartSalesComponent taxValue: new FormControl(this.cartData.taxValue.toFixed(2), []), discount: new FormControl(this.cartData.discountValue.toFixed(2), []), carrierId: new FormControl(this.cartData.carrierId, []), + deliveryTaxId: new FormControl(0, []), }); this.formPayment = this.fb.group({ invoiceStore: new FormControl(null), @@ -499,7 +497,7 @@ export class CartSalesComponent this.shopping = data; if (this.shopping !== null) { this.totalWeight = data.totpeso; - this.loadFormOrder(); + this.loadFormOrder(data); } }); @@ -1432,10 +1430,10 @@ export class CartSalesComponent let carrierId = 0; if (taxValue >= 0) { deliveryTaxId = Number.parseFloat( - this.formResumeOrder.get('deliveryTaxId').value + this.formResumeOrder.get('deliveryTaxId') ? this.formResumeOrder.get('deliveryTaxId').value : 0 ); carrierId = Number.parseFloat( - this.formResumeOrder.get('carrierId').value + this.formResumeOrder.get('carrierId') ? this.formResumeOrder.get('carrierId').value : 0 ); } const order: OrderDeliveryTax = { @@ -1446,7 +1444,6 @@ export class CartSalesComponent }; localStorage.setItem('taxDelivery', JSON.stringify(order)); this.loadFormOrder(); - this.loadShopping(); /* this.store.dispatch(new UpdateDeliveryTaxAction(order)); this.updating$.subscribe((update) => { @@ -2146,10 +2143,10 @@ export class CartSalesComponent ); let percentOrder = (discountValue / orderValue) * 100; console.log('Percentual do pedido: ' + percentOrder); - if (this.percentSeller < percentOrder) { - this.openedAuthUser = true; - return; - } + // if (this.percentSeller < percentOrder) { + // this.openedAuthUser = true; + // return; + // } if (discountValue <= 0.01) { percentOrder = 0; } @@ -2159,8 +2156,9 @@ export class CartSalesComponent idUserAuth: this.authService.getUser(), }; this.store.dispatch(new ApplyDiscountOrderAction(order)); - this.store.dispatch(new LoadShoppingAction(this.shoppingService.getCart())); + // this.store.dispatch(new LoadShoppingAction(this.shoppingService.getCart())); // Reloader moved to Effect this.loadFormOrder(); + this.calculateTaxDelivery(true); } applyDiscountOrder() { @@ -2249,6 +2247,7 @@ export class CartSalesComponent this.showInformation = true; return; } + this.loadFormOrder(); } calcDiscountOrderValue() { @@ -2591,6 +2590,7 @@ export class CartSalesComponent priorityDelivery: priorityDelivery, }; + console.log('dataDeliveryTax', JSON.stringify(dataDeliveryTax)); this.shoppingService.calculateDeliveryTax(dataDeliveryTax).subscribe( (result) => { this.dataDeliveryTax = result; diff --git a/src/app/sales/components/discount-item-sales/discount-item-sales.component.ts b/src/app/sales/components/discount-item-sales/discount-item-sales.component.ts index 81a2878..9c781e7 100644 --- a/src/app/sales/components/discount-item-sales/discount-item-sales.component.ts +++ b/src/app/sales/components/discount-item-sales/discount-item-sales.component.ts @@ -3,7 +3,7 @@ import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Store } from '@ngrx/store'; import { ActionsLayout } from '@progress/kendo-angular-dialog'; import { Observable, Subscription } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { catchError, map } from 'rxjs/operators'; import { AuthService } from 'src/app/auth/services/auth.service'; import { ResultApi } from 'src/app/models/result-api.model'; import { UserAuth } from 'src/app/models/user-auth.model'; @@ -55,7 +55,7 @@ export class DiscountItemSalesComponent implements OnInit { constructor( private fb: FormBuilder, private authService: AuthService, - private store: Store, ) { + private store: Store,) { this.formDiscountItem = this.fb.group({ description: [''], @@ -96,7 +96,7 @@ export class DiscountItemSalesComponent implements OnInit { calcPercentDiscount() { const discountValue = this.formDiscountItem.get('discountValue').value; - const percent = Number.parseFloat(( discountValue / this.shoppingItem.listPrice ).toFixed(2)) * 100; + const percent = Number.parseFloat((discountValue / this.shoppingItem.listPrice).toFixed(2)) * 100; const salePrice = Number.parseFloat((this.shoppingItem.listPrice - discountValue).toFixed(2)); this.formDiscountItem.patchValue({ discount: percent, @@ -107,29 +107,27 @@ export class DiscountItemSalesComponent implements OnInit { async confirmDiscount() { let discount = Number.parseFloat(this.formDiscountItem.get('discount').value); + console.log('discount', discount); const discountValue = Number.parseFloat(this.formDiscountItem.get('discountValue').value); const salePrice = Number.parseFloat((this.shoppingItem.listPrice - discountValue).toFixed(2)); - if (this.percentSeller < discount) { - this.openedAuthUser = true; - return; - } + // if (this.percentSeller < discount) { + // this.openedAuthUser = true; + // return; + // } + if (discountValue <= 0.01) { discount = 0; } - this.shoppingItem.discount = discount; - this.shoppingItem.discountValue = discountValue; - this.shoppingItem.price = salePrice; - this.shoppingItem.userDiscount = this.authService.getUser(); - this.store.dispatch(new UpdatePriceItemAction(this.shoppingItem)); - this.updating$.pipe( - map((updating) => { - if (!updating) { - this.resultEvent.emit(true); - } - }) - ); + console.log('shoppingItem', JSON.stringify(this.shoppingItem)); + const updateItem = { ...this.shoppingItem }; + updateItem.discount = discount; + updateItem.discountValue = discountValue; + updateItem.price = salePrice; + updateItem.userDiscount = this.authService.getUser(); + this.store.dispatch(new UpdatePriceItemAction(updateItem)); + this.resultEvent.emit(true); } async returnAuthUser(userAuth: any) { @@ -149,13 +147,7 @@ export class DiscountItemSalesComponent implements OnInit { updateItem.price = salePrice; updateItem.userDiscount = userAuth.id; this.store.dispatch(new UpdatePriceItemAction(updateItem)); - this.updating$.subscribe( - (updating) => { - if (!updating) { - this.resultEvent.emit(true); - } - } - ); + this.resultEvent.emit(true); } else { console.log('Não localizou o id.'); } diff --git a/src/app/sales/components/discount-order/discount-order.component.html b/src/app/sales/components/discount-order/discount-order.component.html index 6cb08a3..eddb029 100644 --- a/src/app/sales/components/discount-order/discount-order.component.html +++ b/src/app/sales/components/discount-order/discount-order.component.html @@ -1,48 +1,33 @@
- Dados do pedido + Dados do pedido xxx
@@ -51,7 +36,7 @@
@@ -60,12 +45,7 @@
- +