Commit 704b8da76c17bd3b1a879938527d19279bf15ec8
1 parent
5af4c21439
Exists in
master
and in
1 other branch
Arreglo en busqueda de productos.
Showing
1 changed file
with
2 additions
and
1 deletions
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.ts
| 1 | import { Component, OnInit, APP_BOOTSTRAP_LISTENER } from '@angular/core'; | 1 | import { Component, OnInit, APP_BOOTSTRAP_LISTENER } 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 { appSettings } from 'src/etc/AppSettings'; | 4 | import { appSettings } from 'src/etc/AppSettings'; |
| 5 | import { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
| 6 | 6 | ||
| 7 | @Component({ | 7 | @Component({ |
| 8 | selector: 'app-busqueda-productos', | 8 | selector: 'app-busqueda-productos', |
| 9 | templateUrl: './busqueda-productos.component.html', | 9 | templateUrl: './busqueda-productos.component.html', |
| 10 | styleUrls: ['./busqueda-productos.component.scss'] | 10 | styleUrls: ['./busqueda-productos.component.scss'] |
| 11 | }) | 11 | }) |
| 12 | export class BusquedaProductosComponent implements OnInit { | 12 | export class BusquedaProductosComponent implements OnInit { |
| 13 | 13 | ||
| 14 | private productos: Producto[] = []; | 14 | private productos: Producto[] = []; |
| 15 | private auxProductos: Producto[] = []; | 15 | private auxProductos: Producto[] = []; |
| 16 | private searchTerm: string = ''; | 16 | private searchTerm: string = ''; |
| 17 | private showSpinner: boolean = true; | 17 | private showSpinner: boolean = true; |
| 18 | private categoria: Categorias = Categorias.todos; | 18 | private categoria: Categorias = Categorias.todos; |
| 19 | private apiUrl: string = appSettings.apiUrl; | 19 | private apiUrl: string = appSettings.apiUrl; |
| 20 | private showBtnCargarProducto: boolean = false; | 20 | private showBtnCargarProducto: boolean = false; |
| 21 | 21 | ||
| 22 | constructor( | 22 | constructor( |
| 23 | private productoService: ProductoService, | 23 | private productoService: ProductoService, |
| 24 | private router: Router) { } | 24 | private router: Router) { } |
| 25 | 25 | ||
| 26 | ngOnInit() { | 26 | ngOnInit() { |
| 27 | 27 | ||
| 28 | this.productoService.productoAcargar = undefined; | ||
| 28 | this.productoService.getAll() | 29 | this.productoService.getAll() |
| 29 | .subscribe((data: Producto[]) => { | 30 | .subscribe((data: Producto[]) => { |
| 30 | 31 | ||
| 31 | this.auxProductos = this.productos = data; | 32 | this.auxProductos = this.productos = data; |
| 32 | }, (error) => { | 33 | }, (error) => { |
| 33 | this.showSpinner = false; | 34 | this.showSpinner = false; |
| 34 | console.error(error); | 35 | console.error(error); |
| 35 | }); | 36 | }); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | filterItems() { | 39 | filterItems() { |
| 39 | 40 | ||
| 40 | this.auxProductos = this.productos.filter(x => { | 41 | this.auxProductos = this.productos.filter(x => { |
| 41 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) | 42 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) |
| 42 | }); | 43 | }); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | agregarAlCarrito(producto: Producto) { | 46 | agregarAlCarrito(producto: Producto) { |
| 46 | 47 | ||
| 47 | producto.cantidad = 1; | 48 | producto.cantidad = 1; |
| 48 | this.productoService.productos.push(producto); | 49 | this.productoService.productos.push(producto); |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | private mostrarBotonCargar(producto: Producto) { | 52 | private mostrarBotonCargar(producto: Producto) { |
| 52 | 53 | ||
| 53 | for (let i = 0; i < this.auxProductos.length; i++) { | 54 | for (let i = 0; i < this.auxProductos.length; i++) { |
| 54 | if (this.auxProductos[i].id !== producto.id) | 55 | if (this.auxProductos[i].id !== producto.id) |
| 55 | this.auxProductos[i].showCargarProducto = false; | 56 | this.auxProductos[i].showCargarProducto = false; |
| 56 | else if (producto.showCargarProducto) return; | 57 | else if (producto.showCargarProducto) return; |
| 57 | } | 58 | } |
| 58 | producto.showCargarProducto = !producto.showCargarProducto | 59 | producto.showCargarProducto = !producto.showCargarProducto |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | private elegirProducto(producto: Producto) { | 62 | private elegirProducto(producto: Producto) { |
| 62 | 63 | ||
| 63 | this.productoService.productoAcargar = producto; | 64 | this.productoService.productoAcargar = producto; |
| 64 | this.router.navigate(['inicio']); | 65 | this.router.navigate(['inicio']); |
| 65 | } | 66 | } |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | enum Categorias { | 69 | enum Categorias { |
| 69 | promosCombos = 1, | 70 | promosCombos = 1, |
| 70 | todos = 2, | 71 | todos = 2, |
| 71 | bebidas = 3, | 72 | bebidas = 3, |
| 72 | sandwicheria = 4, | 73 | sandwicheria = 4, |
| 73 | panaderia = 5, | 74 | panaderia = 5, |
| 74 | golosinas = 6, | 75 | golosinas = 6, |
| 75 | tabaqueria = 7, | 76 | tabaqueria = 7, |
| 76 | } | 77 | } |
| 77 | 78 |