Commit da27feb175c65cf5d00cfaa3ae99373d13ee7c84
1 parent
f1d3943fe0
Exists in
master
and in
1 other branch
Arreglo en promos sin imagen, arreglo para abrir popover cuando se selecciona un…
…a promo sin sinonimo.
Showing
2 changed files
with
71 additions
and
66 deletions
Show diff stats
src/app/components/inicio/inicio.component.html
... | ... | @@ -72,7 +72,7 @@ |
72 | 72 | *ngIf="promociones.length > 0 && sinonimos.length === 0" |
73 | 73 | [popover]="popoverDirective" |
74 | 74 | [popoverContent]="promociones" |
75 | - (promoSeleccionada)="promoSeleccionada($event)" | |
75 | + (promoSeleccionada)="promoSeleccionada($event, false)" | |
76 | 76 | class="text-white rounded-sm border-0"> |
77 | 77 | </app-popover-promos> |
78 | 78 | <app-popover-sinonimos |
src/app/components/inicio/inicio.component.ts
1 | -import { Component, OnInit, ViewChild, HostListener } from '@angular/core'; | |
1 | +import { Component, OnInit, ViewChild, HostListener, AfterViewInit } from '@angular/core'; | |
2 | 2 | import { PopoverDirective } from 'ngx-bootstrap'; |
3 | 3 | import { appSettings } from 'src/etc/AppSettings'; |
4 | 4 | import { Router } from '@angular/router'; |
... | ... | @@ -11,7 +11,7 @@ import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
11 | 11 | templateUrl: './inicio.component.html', |
12 | 12 | styleUrls: ['./inicio.component.scss'] |
13 | 13 | }) |
14 | -export class InicioComponent implements OnInit { | |
14 | +export class InicioComponent implements OnInit, AfterViewInit { | |
15 | 15 | |
16 | 16 | private tienePromo = false; |
17 | 17 | private productoEsPromo = false; |
... | ... | @@ -38,20 +38,36 @@ export class InicioComponent implements OnInit { |
38 | 38 | |
39 | 39 | constructor( |
40 | 40 | private router: Router, |
41 | - private productoService: ProductoService) { } | |
41 | + private productoService: ProductoService | |
42 | + ) { } | |
42 | 43 | |
43 | 44 | ngOnInit() { |
44 | 45 | |
45 | 46 | this.productoAcargar = this.productoService.productoAcargar; |
46 | - if (this.productoAcargar) { | |
47 | + this.getProductos(); | |
48 | + } | |
49 | + | |
50 | + ngAfterViewInit() { | |
51 | + | |
52 | + setTimeout(() => { | |
53 | + if (!this.productoAcargar) return; | |
54 | + | |
47 | 55 | if (this.productoAcargar.PRO) { |
48 | 56 | this.promociones.push(this.productoAcargar); |
49 | - this.promoSeleccionada(this.productoAcargar); | |
57 | + this.promoSeleccionada(this.productoAcargar, true); | |
50 | 58 | } |
51 | - else | |
59 | + else { | |
52 | 60 | this.getPromociones(); |
53 | - } | |
54 | - this.getProductos(); | |
61 | + } | |
62 | + }) | |
63 | + } | |
64 | + | |
65 | + getProductos() { | |
66 | + | |
67 | + this.productoService.getAll() | |
68 | + .subscribe((productos: Producto[]) => { | |
69 | + this.productos = productos; | |
70 | + }); | |
55 | 71 | } |
56 | 72 | |
57 | 73 | getPromociones() { |
... | ... | @@ -62,12 +78,10 @@ export class InicioComponent implements OnInit { |
62 | 78 | .subscribe((res: Producto[]) => { |
63 | 79 | |
64 | 80 | if (res.length === 0) { |
65 | - //Si no tiene promociones la cargarรก al carrito despues de un tiempo | |
66 | - // setTimeout(() => { | |
81 | + | |
67 | 82 | this.productoAcargar.cantidad = 1; |
68 | 83 | this.productoService.productos.push(this.productoAcargar); |
69 | 84 | this.productoAcargar = this.productoService.productoAcargar = undefined; |
70 | - // }, 2000) | |
71 | 85 | } else { |
72 | 86 | |
73 | 87 | this.promociones = res; |
... | ... | @@ -76,21 +90,8 @@ export class InicioComponent implements OnInit { |
76 | 90 | }, error => { console.error(error); }) |
77 | 91 | } |
78 | 92 | |
79 | - getProductos() { | |
80 | - | |
81 | - this.productoService.getAll() | |
82 | - .subscribe((productos: Producto[]) => { | |
83 | - this.productos = productos; | |
84 | - }); | |
85 | - } | |
86 | - | |
87 | - irBusquedaProductos(value) { | |
88 | - | |
89 | - this.productoService.mostrar = value; | |
90 | - this.router.navigate(['busqueda-productos']); | |
91 | - } | |
92 | - | |
93 | 93 | confirmarProducto() { |
94 | + | |
94 | 95 | var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; |
95 | 96 | producto.cantidad = 1; |
96 | 97 | this.productoService.productos.push(producto); |
... | ... | @@ -99,46 +100,24 @@ export class InicioComponent implements OnInit { |
99 | 100 | this.popoverDirective.hide(); |
100 | 101 | } |
101 | 102 | |
102 | - deshacerCarga() { | |
103 | + promoSeleccionada($event: Producto, showPopover: boolean) { | |
103 | 104 | |
104 | - if (this.sinonimos.length > 0) { | |
105 | - this.sinonimos = []; | |
106 | - this.popoverDirective.hide(); | |
107 | - } | |
105 | + this.productoService.getProductoById($event.id) | |
106 | + .subscribe((res: Producto) => { | |
107 | + | |
108 | + $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; | |
109 | + this.promoAcargar = $event; | |
108 | 110 | |
109 | - if (this.promoAcargar) { | |
110 | - this.promoAcargar = undefined; | |
111 | - if (this.productoAcargar.PRO) { | |
112 | - this.productoAcargar = undefined; | |
113 | - this.promociones = []; | |
114 | - this.popoverDirective.hide(); | |
115 | - } else { | |
116 | - this.popoverDirective.show(); | |
117 | - } | |
118 | - } else { | |
119 | - this.productoAcargar = undefined; | |
120 | - this.promociones = []; | |
121 | - this.popoverDirective.hide(); | |
122 | - } | |
123 | - } | |
124 | - | |
125 | - promoSeleccionada($event: Producto) { | |
126 | - | |
127 | - if ($event.tieneSinonimos) { | |
128 | - | |
129 | - this.productoService.getProductoById($event.id) | |
130 | - .subscribe((res: Producto) => { | |
131 | - | |
132 | - $event.imagenes = res.imagenes; | |
133 | - this.promoAcargar = $event; | |
111 | + if ($event.tieneSinonimos) { | |
134 | 112 | this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); |
135 | - }, | |
136 | - error => { console.log(error); }) | |
137 | - | |
113 | + } else if (showPopover) { | |
114 | + this.popoverDirective.show(); | |
115 | + } else { | |
116 | + this.popoverDirective.hide(); | |
117 | + } | |
138 | 118 | |
139 | - } else if (this.popoverDirective) { | |
140 | - this.popoverDirective.hide(); | |
141 | - } | |
119 | + }, | |
120 | + error => { console.log(error); }) | |
142 | 121 | } |
143 | 122 | |
144 | 123 | getSinonimos(sector, codigo) { |
... | ... | @@ -161,10 +140,7 @@ export class InicioComponent implements OnInit { |
161 | 140 | }) |
162 | 141 | |
163 | 142 | this.sinonimos = res; |
164 | - if (res.length > 0) | |
165 | - this.popoverDirective.show(); | |
166 | - else | |
167 | - this.popoverDirective.hide(); | |
143 | + (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); | |
168 | 144 | }) |
169 | 145 | } |
170 | 146 | |
... | ... | @@ -198,4 +174,33 @@ export class InicioComponent implements OnInit { |
198 | 174 | |
199 | 175 | } |
200 | 176 | |
177 | + irBusquedaProductos(value) { | |
178 | + | |
179 | + this.productoService.mostrar = value; | |
180 | + this.router.navigate(['busqueda-productos']); | |
181 | + } | |
182 | + | |
183 | + deshacerCarga() { | |
184 | + | |
185 | + if (this.sinonimos.length > 0) { | |
186 | + this.sinonimos = []; | |
187 | + this.popoverDirective.hide(); | |
188 | + } | |
189 | + | |
190 | + if (this.promoAcargar) { | |
191 | + this.promoAcargar = undefined; | |
192 | + if (this.productoAcargar.PRO) { | |
193 | + this.productoAcargar = undefined; | |
194 | + this.promociones = []; | |
195 | + this.popoverDirective.hide(); | |
196 | + } else { | |
197 | + this.popoverDirective.show(); | |
198 | + } | |
199 | + } else { | |
200 | + this.productoAcargar = undefined; | |
201 | + this.promociones = []; | |
202 | + this.popoverDirective.hide(); | |
203 | + } | |
204 | + } | |
205 | + | |
201 | 206 | } |