diff --git a/src/app/components/inicio/inicio.component.html b/src/app/components/inicio/inicio.component.html index 05d7d56..307be7a 100644 --- a/src/app/components/inicio/inicio.component.html +++ b/src/app/components/inicio/inicio.component.html @@ -72,7 +72,7 @@ *ngIf="promociones.length > 0 && sinonimos.length === 0" [popover]="popoverDirective" [popoverContent]="promociones" - (promoSeleccionada)="promoSeleccionada($event)" + (promoSeleccionada)="promoSeleccionada($event, false)" class="text-white rounded-sm border-0"> { + if (!this.productoAcargar) return; + if (this.productoAcargar.PRO) { this.promociones.push(this.productoAcargar); - this.promoSeleccionada(this.productoAcargar); + this.promoSeleccionada(this.productoAcargar, true); } - else + else { this.getPromociones(); - } - this.getProductos(); + } + }) + } + + getProductos() { + + this.productoService.getAll() + .subscribe((productos: Producto[]) => { + this.productos = productos; + }); } getPromociones() { @@ -62,12 +78,10 @@ export class InicioComponent implements OnInit { .subscribe((res: Producto[]) => { if (res.length === 0) { - //Si no tiene promociones la cargará al carrito despues de un tiempo - // setTimeout(() => { + this.productoAcargar.cantidad = 1; this.productoService.productos.push(this.productoAcargar); this.productoAcargar = this.productoService.productoAcargar = undefined; - // }, 2000) } else { this.promociones = res; @@ -76,21 +90,8 @@ export class InicioComponent implements OnInit { }, error => { console.error(error); }) } - getProductos() { - - this.productoService.getAll() - .subscribe((productos: Producto[]) => { - this.productos = productos; - }); - } - - irBusquedaProductos(value) { - - this.productoService.mostrar = value; - this.router.navigate(['busqueda-productos']); - } - confirmarProducto() { + var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; producto.cantidad = 1; this.productoService.productos.push(producto); @@ -99,46 +100,24 @@ export class InicioComponent implements OnInit { this.popoverDirective.hide(); } - deshacerCarga() { + promoSeleccionada($event: Producto, showPopover: boolean) { - if (this.sinonimos.length > 0) { - this.sinonimos = []; - this.popoverDirective.hide(); - } + this.productoService.getProductoById($event.id) + .subscribe((res: Producto) => { + + $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; + this.promoAcargar = $event; - if (this.promoAcargar) { - this.promoAcargar = undefined; - if (this.productoAcargar.PRO) { - this.productoAcargar = undefined; - this.promociones = []; - this.popoverDirective.hide(); - } else { - this.popoverDirective.show(); - } - } else { - this.productoAcargar = undefined; - this.promociones = []; - this.popoverDirective.hide(); - } - } - - promoSeleccionada($event: Producto) { - - if ($event.tieneSinonimos) { - - this.productoService.getProductoById($event.id) - .subscribe((res: Producto) => { - - $event.imagenes = res.imagenes; - this.promoAcargar = $event; + if ($event.tieneSinonimos) { this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); - }, - error => { console.log(error); }) - + } else if (showPopover) { + this.popoverDirective.show(); + } else { + this.popoverDirective.hide(); + } - } else if (this.popoverDirective) { - this.popoverDirective.hide(); - } + }, + error => { console.log(error); }) } getSinonimos(sector, codigo) { @@ -161,10 +140,7 @@ export class InicioComponent implements OnInit { }) this.sinonimos = res; - if (res.length > 0) - this.popoverDirective.show(); - else - this.popoverDirective.hide(); + (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); }) } @@ -198,4 +174,33 @@ export class InicioComponent implements OnInit { } + irBusquedaProductos(value) { + + this.productoService.mostrar = value; + this.router.navigate(['busqueda-productos']); + } + + deshacerCarga() { + + if (this.sinonimos.length > 0) { + this.sinonimos = []; + this.popoverDirective.hide(); + } + + if (this.promoAcargar) { + this.promoAcargar = undefined; + if (this.productoAcargar.PRO) { + this.productoAcargar = undefined; + this.promociones = []; + this.popoverDirective.hide(); + } else { + this.popoverDirective.show(); + } + } else { + this.productoAcargar = undefined; + this.promociones = []; + this.popoverDirective.hide(); + } + } + }