Commit 090f3d65fe5c51b8744afd1a1451a9102e88265e
1 parent
1bc34d717d
Exists in
master
and in
1 other branch
Usado detalle largo en filtro.
Showing
1 changed file
with
2 additions
and
2 deletions
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.ts
1 | import { Component, OnInit, EventEmitter } from '@angular/core'; | 1 | import { Component, OnInit, EventEmitter } from '@angular/core'; |
2 | import { ProductoService } from 'src/app/services/producto.service'; | 2 | import { ProductoService } from 'src/app/services/producto.service'; |
3 | import { Producto } from 'src/app/wrappers/producto'; | 3 | import { Producto } from 'src/app/wrappers/producto'; |
4 | import { Categoria } from 'src/app/wrappers/categoria'; | 4 | import { Categoria } from 'src/app/wrappers/categoria'; |
5 | import { appSettings } from 'src/etc/AppSettings'; | 5 | import { appSettings } from 'src/etc/AppSettings'; |
6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: 'app-busqueda-productos', | 9 | selector: 'app-busqueda-productos', |
10 | templateUrl: './busqueda-productos.component.html', | 10 | templateUrl: './busqueda-productos.component.html', |
11 | styleUrls: ['./busqueda-productos.component.scss'] | 11 | styleUrls: ['./busqueda-productos.component.scss'] |
12 | }) | 12 | }) |
13 | export class BusquedaProductosComponent implements OnInit { | 13 | export class BusquedaProductosComponent implements OnInit { |
14 | 14 | ||
15 | private productos: Producto[] = []; | 15 | private productos: Producto[] = []; |
16 | private auxProductos: Producto[] = []; | 16 | private auxProductos: Producto[] = []; |
17 | private searchTerm: string = ''; | 17 | private searchTerm: string = ''; |
18 | private categoriaActive: number = null; | 18 | private categoriaActive: number = null; |
19 | private showSpinner: boolean = true; | 19 | private showSpinner: boolean = true; |
20 | private queMostrar: string = 'todo'; | 20 | private queMostrar: string = 'todo'; |
21 | private apiUrl: string = appSettings.apiUrl; | 21 | private apiUrl: string = appSettings.apiUrl; |
22 | private categorias: Categoria[] = []; | 22 | private categorias: Categoria[] = []; |
23 | private blurFocus = new EventEmitter(); | 23 | private blurFocus = new EventEmitter(); |
24 | 24 | ||
25 | constructor( | 25 | constructor( |
26 | private productoService: ProductoService, | 26 | private productoService: ProductoService, |
27 | private router: Router) { } | 27 | private router: Router) { } |
28 | 28 | ||
29 | ngOnInit() { | 29 | ngOnInit() { |
30 | 30 | ||
31 | this.queMostrar = this.productoService.mostrar; | 31 | this.queMostrar = this.productoService.mostrar; |
32 | 32 | ||
33 | this.productoService.getCategorias() | 33 | this.productoService.getCategorias() |
34 | .subscribe((categorias: Categoria[]) => { | 34 | .subscribe((categorias: Categoria[]) => { |
35 | this.categorias = categorias; | 35 | this.categorias = categorias; |
36 | 36 | ||
37 | switch (this.queMostrar) { | 37 | switch (this.queMostrar) { |
38 | case 'todos': | 38 | case 'todos': |
39 | this.categoriaActive = 1; | 39 | this.categoriaActive = 1; |
40 | break; | 40 | break; |
41 | case 'promociones': | 41 | case 'promociones': |
42 | this.categoriaActive = 1; | 42 | this.categoriaActive = 1; |
43 | break; | 43 | break; |
44 | case 'ordenar': | 44 | case 'ordenar': |
45 | 45 | ||
46 | this.categorias = this.categorias.filter((categoria: Categoria) => { | 46 | this.categorias = this.categorias.filter((categoria: Categoria) => { |
47 | return categoria.ES_PEDIDO; | 47 | return categoria.ES_PEDIDO; |
48 | }); | 48 | }); |
49 | 49 | ||
50 | this.categoriaActive = this.categorias[0].id; | 50 | this.categoriaActive = this.categorias[0].id; |
51 | 51 | ||
52 | break; | 52 | break; |
53 | default: | 53 | default: |
54 | break; | 54 | break; |
55 | } | 55 | } |
56 | 56 | ||
57 | }); | 57 | }); |
58 | 58 | ||
59 | this.productoService.productoAcargar = undefined; | 59 | this.productoService.productoAcargar = undefined; |
60 | this.productoService.getAll() | 60 | this.productoService.getAll() |
61 | .subscribe((data: Producto[]) => { | 61 | .subscribe((data: Producto[]) => { |
62 | 62 | ||
63 | this.productos = data; | 63 | this.productos = data; |
64 | this.filterItems(); | 64 | this.filterItems(); |
65 | }, (error) => { | 65 | }, (error) => { |
66 | this.showSpinner = false; | 66 | this.showSpinner = false; |
67 | console.error(error); | 67 | console.error(error); |
68 | }); | 68 | }); |
69 | } | 69 | } |
70 | 70 | ||
71 | filterItems() { | 71 | filterItems() { |
72 | 72 | ||
73 | this.auxProductos = this.productos.filter(x => { | 73 | this.auxProductos = this.productos.filter(x => { |
74 | if (this.categoriaActive === 0) { | 74 | if (this.categoriaActive === 0) { |
75 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) | 75 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) |
76 | } | 76 | } |
77 | else { | 77 | else { |
78 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 78 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
79 | x.categoria_selfservice === this.categoriaActive; | 79 | x.categoria_selfservice === this.categoriaActive; |
80 | } | 80 | } |
81 | }); | 81 | }); |
82 | } | 82 | } |
83 | 83 | ||
84 | agregarAlCarrito(producto: Producto) { | 84 | agregarAlCarrito(producto: Producto) { |
85 | 85 | ||
86 | producto.cantidad = 1; | 86 | producto.cantidad = 1; |
87 | this.productoService.productos.push(producto); | 87 | this.productoService.productos.push(producto); |
88 | } | 88 | } |
89 | 89 | ||
90 | lostBlur() { | 90 | lostBlur() { |
91 | this.blurFocus.emit(); | 91 | this.blurFocus.emit(); |
92 | } | 92 | } |
93 | 93 | ||
94 | private elegirProducto(producto: Producto) { | 94 | private elegirProducto(producto: Producto) { |
95 | 95 | ||
96 | if (producto.PRO) { | 96 | if (producto.PRO) { |
97 | 97 | ||
98 | let imagenes = producto.imagenes; | 98 | let imagenes = producto.imagenes; |
99 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | 99 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) |
100 | .subscribe(res => { | 100 | .subscribe(res => { |
101 | 101 | ||
102 | this.productoService.productoAcargar = res[0]; | 102 | this.productoService.productoAcargar = res[0]; |
103 | this.productoService.productoAcargar.imagenes = imagenes; | 103 | this.productoService.productoAcargar.imagenes = imagenes; |
104 | this.router.navigate(['inicio']); | 104 | this.router.navigate(['inicio']); |
105 | }, | 105 | }, |
106 | error => { console.error(error); } | 106 | error => { console.error(error); } |
107 | ); | 107 | ); |
108 | } else { | 108 | } else { |
109 | 109 | ||
110 | this.productoService.productoAcargar = producto; | 110 | this.productoService.productoAcargar = producto; |
111 | this.router.navigate(['inicio']); | 111 | this.router.navigate(['inicio']); |
112 | } | 112 | } |
113 | 113 | ||
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 |