Commit 9a7ebd7c887ccc78b1891641adc021ba8055294b
Exists in
master
and in
1 other branch
Merge branch 'master' of http://git.focasoftware.com/angular/autoservicio
Showing
4 changed files
Show diff stats
src/app/components/home/home.component.html
... | ... | @@ -16,25 +16,25 @@ |
16 | 16 | </div> |
17 | 17 | |
18 | 18 | <!-- INFO DE BIENVENIDA --> |
19 | - <div class="row w-100"> | |
20 | - <div class="col-4 offset-2"> | |
19 | + <div class="row h-50 w-100"> | |
20 | + <div class="col-4 offset-2 my-auto"> | |
21 | 21 | |
22 | 22 | <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel"> |
23 | 23 | <div class="carousel-inner"> |
24 | 24 | <div class="carousel-item active"> |
25 | 25 | <img |
26 | 26 | src="{{apiUrl}}/imagenes/coca1.jpg" |
27 | - class="d-block rounded-sm shadow w-100"> | |
27 | + class="d-block rounded-sm shadow w-75 mx-auto"> | |
28 | 28 | </div> |
29 | 29 | <div class="carousel-item"> |
30 | 30 | <img |
31 | 31 | src="{{apiUrl}}/imagenes/coca2.jpg" |
32 | - class="d-block rounded-sm shadow w-100"> | |
32 | + class="d-block rounded-sm shadow w-75 mx-auto"> | |
33 | 33 | </div> |
34 | 34 | <div class="carousel-item"> |
35 | 35 | <img |
36 | 36 | src="{{apiUrl}}/imagenes/coca3.jpg" |
37 | - class="d-block rounded-sm shadow w-100"> | |
37 | + class="d-block rounded-sm shadow w-75 mx-auto"> | |
38 | 38 | </div> |
39 | 39 | </div> |
40 | 40 | </div> |
src/app/components/inicio/inicio.component.ts
... | ... | @@ -65,9 +65,9 @@ export class InicioComponent implements OnInit { |
65 | 65 | if (res.length === 0) { |
66 | 66 | //Si no tiene promociones la cargará al carrito despues de un tiempo |
67 | 67 | // setTimeout(() => { |
68 | - this.productoAcargar.cantidad = 1; | |
69 | - this.productoService.productos.push(this.productoAcargar); | |
70 | - this.productoAcargar = this.productoService.productoAcargar = undefined; | |
68 | + this.productoAcargar.cantidad = 1; | |
69 | + this.productoService.productos.push(this.productoAcargar); | |
70 | + this.productoAcargar = this.productoService.productoAcargar = undefined; | |
71 | 71 | // }, 2000) |
72 | 72 | } else { |
73 | 73 | |
... | ... | @@ -77,12 +77,8 @@ export class InicioComponent implements OnInit { |
77 | 77 | }, error => { console.error(error); }) |
78 | 78 | } |
79 | 79 | |
80 | - showPopover() { | |
81 | - | |
82 | - this.popoverDirective.show(); | |
83 | - } | |
84 | - | |
85 | 80 | getProductos() { |
81 | + | |
86 | 82 | this.productoService.getAll() |
87 | 83 | .subscribe((productos: Producto[]) => { |
88 | 84 | this.productos = productos; |
... | ... | @@ -96,8 +92,9 @@ export class InicioComponent implements OnInit { |
96 | 92 | } |
97 | 93 | |
98 | 94 | confirmarProducto() { |
99 | - this.promoAcargar.cantidad = 1; | |
100 | - this.productoService.productos.push(this.promoAcargar); | |
95 | + var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; | |
96 | + producto.cantidad = 1; | |
97 | + this.productoService.productos.push(producto); | |
101 | 98 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; |
102 | 99 | this.promociones = []; |
103 | 100 | this.popoverDirective.hide(); |
... | ... | @@ -128,37 +125,48 @@ export class InicioComponent implements OnInit { |
128 | 125 | |
129 | 126 | promoSeleccionada($event: Producto) { |
130 | 127 | |
131 | - this.promoAcargar = $event; | |
132 | - this.promoAcargar.tieneSinonimos = true; | |
133 | - if (this.promoAcargar.tieneSinonimos) { | |
134 | - var sector = this.promoAcargar.CodSec; | |
135 | - var codigo = this.promoAcargar.CodArt; | |
136 | - this.productoService.getPromocionSinonimos(sector, codigo) | |
137 | - .subscribe((res: Sinonimo[]) => { | |
128 | + if ($event.tieneSinonimos) { | |
129 | + | |
130 | + this.productoService.getProductoById($event.id) | |
131 | + .subscribe((res : Producto) => { | |
132 | + | |
133 | + $event.imagenes = res.imagenes; | |
134 | + this.promoAcargar = $event; | |
135 | + this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); | |
136 | + }, | |
137 | + error => { console.log(error); }) | |
138 | + | |
139 | + | |
140 | + } else if (this.popoverDirective) { | |
141 | + this.popoverDirective.hide(); | |
142 | + } | |
143 | + } | |
144 | + | |
145 | + getSinonimos(sector, codigo) { | |
146 | + | |
147 | + this.productoService.getPromocionSinonimos(sector, codigo) | |
148 | + .subscribe((res: Sinonimo[]) => { | |
138 | 149 | |
139 | - res.forEach(sinonimo => { | |
150 | + res.forEach(sinonimo => { | |
140 | 151 | |
141 | - sinonimo.productos.forEach(productoSinonimo => { | |
152 | + sinonimo.productos.forEach(productoSinonimo => { | |
142 | 153 | |
143 | - this.promoAcargar.productos.forEach(productoPromo => { | |
154 | + this.promoAcargar.productos.forEach(productoPromo => { | |
144 | 155 | |
145 | - if (productoSinonimo.id === productoPromo.id) { | |
146 | - sinonimo.cantidad = productoPromo.cantidad; | |
147 | - sinonimo.productoPadre = productoPromo.id; | |
148 | - } | |
149 | - }) | |
156 | + if (productoSinonimo.id === productoPromo.id) { | |
157 | + sinonimo.cantidad = productoPromo.cantidad; | |
158 | + sinonimo.productoPadre = productoPromo.id; | |
159 | + } | |
150 | 160 | }) |
151 | 161 | }) |
152 | - | |
153 | - this.sinonimos = res; | |
154 | - if (res.length > 0) | |
155 | - this.showPopover(); | |
156 | - else | |
157 | - this.popoverDirective.hide(); | |
158 | 162 | }) |
159 | - } else { | |
160 | - this.popoverDirective.hide(); | |
161 | - } | |
163 | + | |
164 | + this.sinonimos = res; | |
165 | + if (res.length > 0) | |
166 | + this.popoverDirective.show(); | |
167 | + else | |
168 | + this.popoverDirective.hide(); | |
169 | + }) | |
162 | 170 | } |
163 | 171 | |
164 | 172 | productosPersonalizados($event: Producto[]) { |
src/app/components/pago/pago.component.ts
... | ... | @@ -27,6 +27,7 @@ export class PagoComponent implements OnInit { |
27 | 27 | ) { } |
28 | 28 | |
29 | 29 | ngOnInit() { |
30 | + | |
30 | 31 | this.productos = this.productoService.productos; |
31 | 32 | } |
32 | 33 | |
... | ... | @@ -37,12 +38,13 @@ export class PagoComponent implements OnInit { |
37 | 38 | |
38 | 39 | this.productoService.pagar() |
39 | 40 | .subscribe(() => { |
41 | + | |
40 | 42 | // alert('Compra finalizada'); |
41 | 43 | this.compraConQRfinalizada = true; |
42 | 44 | setTimeout(() => { |
43 | 45 | |
44 | 46 | this.router.navigate(['mensaje-final']); |
45 | - }, 1000); | |
47 | + }, 3000); | |
46 | 48 | }, err => { |
47 | 49 | console.log(err); |
48 | 50 | alert('algo salió mal'); |
src/app/services/producto.service.ts
... | ... | @@ -16,6 +16,11 @@ export class ProductoService { |
16 | 16 | |
17 | 17 | constructor(private http: HttpClient) { } |
18 | 18 | |
19 | + getProductoById(id): Observable<any> { | |
20 | + | |
21 | + return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); | |
22 | + } | |
23 | + | |
19 | 24 | getAll(): Observable<any> { |
20 | 25 | |
21 | 26 | return this.http.get(`${appSettings.apiUrl}/articulos`); |