From 5dcd31ce9a0cc3a1377341fe3b0dd7bcce624f7d Mon Sep 17 00:00:00 2001 From: mpuebla Date: Mon, 19 Aug 2019 15:12:56 -0300 Subject: [PATCH] Agregada logica para manejar la cantidad de los sinonimos. --- src/app/components/inicio/inicio.component.ts | 18 +++++----- .../popover-sinonimos.component.html | 40 +++++++++++----------- .../popover-sinonimos.component.ts | 25 +++++++++++++- src/app/wrappers/producto.ts | 1 + src/app/wrappers/sinonimo.ts | 2 ++ 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/app/components/inicio/inicio.component.ts b/src/app/components/inicio/inicio.component.ts index 4fc11fe..cc5f749 100644 --- a/src/app/components/inicio/inicio.component.ts +++ b/src/app/components/inicio/inicio.component.ts @@ -117,15 +117,17 @@ export class InicioComponent implements OnInit { var codigo = this.promoAcargar.codigo; this.productoService.getPromocionSinonimos(sector, codigo) .subscribe((res: Sinonimo[]) => { + res.forEach(resSinonimo => { - resSinonimo.productos.forEach(productoSinonimo => { - this.promoAcargar.productos.forEach(productoPromo => { - if (productoPromo.id === productoSinonimo.id) { - productoSinonimo.esPadre = true; - } - }); - - }) + + this.promoAcargar.productos.forEach(productoPromo => { + + if (productoPromo.idSinonimo === resSinonimo.ID_SIN) { + resSinonimo.cantidad = productoPromo.cantidad; + resSinonimo.productoPadre = productoPromo.id; + } + }); + }) this.sinonimos = res; this.showPopover(); diff --git a/src/app/components/popover-sinonimos/popover-sinonimos.component.html b/src/app/components/popover-sinonimos/popover-sinonimos.component.html index b158ad0..859c8db 100644 --- a/src/app/components/popover-sinonimos/popover-sinonimos.component.html +++ b/src/app/components/popover-sinonimos/popover-sinonimos.component.html @@ -10,41 +10,41 @@
-
+

- Elija una opción + Elija una opción - Cantidad Restante {{cantidadRestanteSinonimos[i]}}

-
-
- - -
+
+

+ {{producto.DetArt}} +

-
- -
- {{producto.cantidad}} +
+ + {{producto.cantidad}} +
-
diff --git a/src/app/components/popover-sinonimos/popover-sinonimos.component.ts b/src/app/components/popover-sinonimos/popover-sinonimos.component.ts index 78dadb6..cb169d3 100644 --- a/src/app/components/popover-sinonimos/popover-sinonimos.component.ts +++ b/src/app/components/popover-sinonimos/popover-sinonimos.component.ts @@ -16,13 +16,21 @@ export class PopoverSinonimosComponent implements OnInit { @Output() sinonimoSeleccionado = new EventEmitter(); sinonimo: Sinonimo; + private cantidadRestanteSinonimos: number[] = []; + constructor() { } ngOnInit() { //Seteo en la variable a emitir el sinonimo que sea padre this.popoverContent.forEach(sinonimo => { - // this.sinonimo = sinonimo.esPadre ? sinonimo : undefined; + + this.cantidadRestanteSinonimos.push(0); + this.sinonimo = sinonimo.productoPadre ? sinonimo : undefined; + sinonimo.productos.forEach(producto => { + + producto.cantidad = (producto.id === sinonimo.productoPadre) ? sinonimo.cantidad : 0; + }) }) } @@ -37,4 +45,19 @@ export class PopoverSinonimosComponent implements OnInit { this.sinonimo = sinonimo; } + sumarCantidad(producto: Producto, i: number) { + + if (this.cantidadRestanteSinonimos[i] === 0) return; + producto.cantidad++; + this.cantidadRestanteSinonimos[i]--; + } + + restarCantidad(producto: Producto, i: number) { + + if (this.cantidadRestanteSinonimos[i] === this.popoverContent[i].cantidad) return; + if (producto.cantidad === 0) return; + producto.cantidad--; + this.cantidadRestanteSinonimos[i]++; + } + } diff --git a/src/app/wrappers/producto.ts b/src/app/wrappers/producto.ts index de4c338..c248021 100644 --- a/src/app/wrappers/producto.ts +++ b/src/app/wrappers/producto.ts @@ -92,4 +92,5 @@ export interface Producto { showCargarProducto?: boolean; esPadre?: boolean; codigoBarra: string; + idSinonimo?: number; } diff --git a/src/app/wrappers/sinonimo.ts b/src/app/wrappers/sinonimo.ts index 2c93f4e..901b683 100644 --- a/src/app/wrappers/sinonimo.ts +++ b/src/app/wrappers/sinonimo.ts @@ -5,4 +5,6 @@ export interface Sinonimo { ID_SIN: number, descripcion: string, productos: Producto[], + productoPadre?: number; + cantidad? : number; } -- 1.9.1