Commit a84978cc8a53ec5a3ed295e9f9e21f63ea4f5f45
1 parent
7ca1d4c52d
Exists in
master
and in
1 other branch
Borrado de import sin uso.
Showing
1 changed file
with
1 additions
and
2 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 } 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 apiUrl: string = appSettings.apiUrl; | 20 | private apiUrl: string = appSettings.apiUrl; |
| 21 | private showBtnCargarProducto: boolean = false; | 21 | private showBtnCargarProducto: boolean = false; |
| 22 | private categorias: Categoria[] = []; | 22 | private categorias: Categoria[] = []; |
| 23 | 23 | ||
| 24 | constructor( | 24 | constructor( |
| 25 | private productoService: ProductoService, | 25 | private productoService: ProductoService, |
| 26 | private router: Router) { } | 26 | private router: Router) { } |
| 27 | 27 | ||
| 28 | ngOnInit() { | 28 | ngOnInit() { |
| 29 | 29 | ||
| 30 | this.productoService.getCategorias() | 30 | this.productoService.getCategorias() |
| 31 | .subscribe((categorias: Categoria[]) => { | 31 | .subscribe((categorias: Categoria[]) => { |
| 32 | this.categorias = categorias; | 32 | this.categorias = categorias; |
| 33 | this.categoriaActive = categorias[0].id; | 33 | this.categoriaActive = categorias[0].id; |
| 34 | }); | 34 | }); |
| 35 | 35 | ||
| 36 | this.productoService.productoAcargar = undefined; | 36 | this.productoService.productoAcargar = undefined; |
| 37 | this.productoService.getAll() | 37 | this.productoService.getAll() |
| 38 | .subscribe((data: Producto[]) => { | 38 | .subscribe((data: Producto[]) => { |
| 39 | 39 | ||
| 40 | this.auxProductos = this.productos = data; | 40 | this.auxProductos = this.productos = data; |
| 41 | }, (error) => { | 41 | }, (error) => { |
| 42 | this.showSpinner = false; | 42 | this.showSpinner = false; |
| 43 | console.error(error); | 43 | console.error(error); |
| 44 | }); | 44 | }); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | filterItems() { | 47 | filterItems() { |
| 48 | 48 | ||
| 49 | this.auxProductos = this.productos.filter(x => { | 49 | this.auxProductos = this.productos.filter(x => { |
| 50 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 50 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
| 51 | x.categoria_selfservice == this.categoriaActive; | 51 | x.categoria_selfservice == this.categoriaActive; |
| 52 | }); | 52 | }); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | agregarAlCarrito(producto: Producto) { | 55 | agregarAlCarrito(producto: Producto) { |
| 56 | 56 | ||
| 57 | producto.cantidad = 1; | 57 | producto.cantidad = 1; |
| 58 | this.productoService.productos.push(producto); | 58 | this.productoService.productos.push(producto); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | private mostrarBotonCargar(producto: Producto) { | 61 | private mostrarBotonCargar(producto: Producto) { |
| 62 | 62 | ||
| 63 | for (let i = 0; i < this.auxProductos.length; i++) { | 63 | for (let i = 0; i < this.auxProductos.length; i++) { |
| 64 | if (this.auxProductos[i].id !== producto.id) | 64 | if (this.auxProductos[i].id !== producto.id) |
| 65 | this.auxProductos[i].showCargarProducto = false; | 65 | this.auxProductos[i].showCargarProducto = false; |
| 66 | else if (producto.showCargarProducto) return; | 66 | else if (producto.showCargarProducto) return; |
| 67 | } | 67 | } |
| 68 | producto.showCargarProducto = !producto.showCargarProducto | 68 | producto.showCargarProducto = !producto.showCargarProducto |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | private elegirProducto(producto: Producto) { | 71 | private elegirProducto(producto: Producto) { |
| 72 | 72 | ||
| 73 | this.productoService.productoAcargar = producto; | 73 | this.productoService.productoAcargar = producto; |
| 74 | this.router.navigate(['inicio']); | 74 | this.router.navigate(['inicio']); |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | |||
| 78 | 77 |