diff --git a/src/app/components/inicio/inicio.component.html b/src/app/components/inicio/inicio.component.html index 60f5242..16182b7 100644 --- a/src/app/components/inicio/inicio.component.html +++ b/src/app/components/inicio/inicio.component.html @@ -8,12 +8,12 @@ -
Promociones
@@ -24,21 +24,16 @@Conozca las ofertas del momento.
Ordenar
@@ -63,14 +58,14 @@Cargar Productos
@@ -95,11 +89,50 @@ barras o QR frente al scanner.Galletas Oreo x117 grs Chocolate.
-COD. 12121222
+{{productoAcargar.DetArt}}
+{{productoAcargar.DetArt}}
+{{productoAcargar.PreVen | currency}}
+Buscar Productos
diff --git a/src/app/components/inicio/inicio.component.ts b/src/app/components/inicio/inicio.component.ts index 068c5d9..9012dfa 100644 --- a/src/app/components/inicio/inicio.component.ts +++ b/src/app/components/inicio/inicio.component.ts @@ -1,7 +1,10 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { Router } from '@angular/router'; import { PopoverDirective } from 'ngx-bootstrap'; import { appSettings } from 'src/etc/AppSettings'; +import { Producto } from 'src/app/wrappers/producto'; +import { ProductoService } from 'src/app/services/producto.service'; +import { Router } from '@angular/router'; +import { Promocion } from 'src/app/wrappers/promocion'; @Component({ @@ -12,14 +15,43 @@ import { appSettings } from 'src/etc/AppSettings'; export class InicioComponent implements OnInit { @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; - apiUrl : string = appSettings.apiUrl + private productoAcargar: Producto; + private tienePromo = false; + + popoverContent: Promocion[] = [] + apiUrl: string = appSettings.apiUrl - constructor(private router: Router) { } + constructor( + private router: Router, + private productoService: ProductoService) { } ngOnInit() { + + this.productoAcargar = this.productoService.productoAcargar; + if (this.productoAcargar) { + var sector = this.productoAcargar.CodSec; + var codigo = this.productoAcargar.CodArt; + this.productoService.getPromocion(sector, codigo) + .subscribe((promociones: Promocion[]) => { + + if (promociones.length === 0) { + //Si no tiene promociones la cargará al carrito despues de un tiempo + setTimeout(() => { + this.productoService.productos.push(this.productoAcargar); + this.productoAcargar = undefined; + this.tienePromo = false; + }, 2000) + } else { + + this.popoverContent = promociones; + this.tienePromo = true; + this.popoverDirective.show(); + } + }, error => { console.error(error); }) + } } - open() { + showPopover() { this.popoverDirective.show(); } @@ -28,4 +60,11 @@ export class InicioComponent implements OnInit { this.router.navigate([pageUrl]); } + deshacerCarga() { + + this.productoAcargar = undefined; + this.tienePromo = false; + this.popoverDirective.hide(); + } + }