Commit 0fdf58e2929e4fbe4560afe87a05801343230ad9
1 parent
b98fa43e30
Exists in
master
and in
1 other branch
Agregadas llaves.
Showing
1 changed file
with
5 additions
and
3 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 verCategorias: boolean = true; | 20 | private verCategorias: boolean = true; |
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.verCategorias = this.productoService.verCategoriasProductos; | 31 | this.verCategorias = this.productoService.verCategoriasProductos; |
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 | this.categoriaActive = this.verCategorias ? 0 : categorias[0].id; | 36 | this.categoriaActive = this.verCategorias ? 0 : categorias[0].id; |
37 | }); | 37 | }); |
38 | 38 | ||
39 | this.productoService.productoAcargar = undefined; | 39 | this.productoService.productoAcargar = undefined; |
40 | this.productoService.getAll() | 40 | this.productoService.getAll() |
41 | .subscribe((data: Producto[]) => { | 41 | .subscribe((data: Producto[]) => { |
42 | 42 | ||
43 | this.productos = data; | 43 | this.productos = data; |
44 | this.filterItems(); | 44 | this.filterItems(); |
45 | }, (error) => { | 45 | }, (error) => { |
46 | this.showSpinner = false; | 46 | this.showSpinner = false; |
47 | console.error(error); | 47 | console.error(error); |
48 | }); | 48 | }); |
49 | } | 49 | } |
50 | 50 | ||
51 | filterItems() { | 51 | filterItems() { |
52 | 52 | ||
53 | this.auxProductos = this.productos.filter(x => { | 53 | this.auxProductos = this.productos.filter(x => { |
54 | if (this.categoriaActive === 0) | 54 | if (this.categoriaActive === 0){ |
55 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) | 55 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) |
56 | else | 56 | } |
57 | else{ | ||
57 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 58 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
58 | x.categoria_selfservice === this.categoriaActive; | 59 | x.categoria_selfservice === this.categoriaActive; |
60 | } | ||
59 | }); | 61 | }); |
60 | } | 62 | } |
61 | 63 | ||
62 | agregarAlCarrito(producto: Producto) { | 64 | agregarAlCarrito(producto: Producto) { |
63 | 65 | ||
64 | producto.cantidad = 1; | 66 | producto.cantidad = 1; |
65 | this.productoService.productos.push(producto); | 67 | this.productoService.productos.push(producto); |
66 | } | 68 | } |
67 | 69 | ||
68 | lostBlur() { | 70 | lostBlur() { |
69 | this.blurFocus.emit(); | 71 | this.blurFocus.emit(); |
70 | } | 72 | } |
71 | 73 | ||
72 | private elegirProducto(producto: Producto) { | 74 | private elegirProducto(producto: Producto) { |
73 | 75 | ||
74 | if (producto.PRO) { | 76 | if (producto.PRO) { |
75 | 77 | ||
76 | let imagenes = producto.imagenes; | 78 | let imagenes = producto.imagenes; |
77 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | 79 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) |
78 | .subscribe(res => { | 80 | .subscribe(res => { |
79 | 81 | ||
80 | this.productoService.productoAcargar = res[0]; | 82 | this.productoService.productoAcargar = res[0]; |
81 | this.productoService.productoAcargar.imagenes = imagenes; | 83 | this.productoService.productoAcargar.imagenes = imagenes; |
82 | this.router.navigate(['inicio']); | 84 | this.router.navigate(['inicio']); |
83 | }, | 85 | }, |
84 | error => { console.error(error); } | 86 | error => { console.error(error); } |
85 | ); | 87 | ); |
86 | } else { | 88 | } else { |
87 | 89 | ||
88 | this.productoService.productoAcargar = producto; | 90 | this.productoService.productoAcargar = producto; |
89 | this.router.navigate(['inicio']); | 91 | this.router.navigate(['inicio']); |
90 | } | 92 | } |
91 | 93 | ||
92 | } | 94 | } |
93 | } | 95 | } |
94 | 96 |