Commit 01f3e07a6f7c47bdddba57b4da8c1b998cd02aed

Authored by Eric Fernandez
1 parent d5898928bc
Exists in master and in 1 other branch validar_pve

interface categoría2

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 { Categoria } from 'src/app/wrappers/categoria';
4 import { appSettings } from 'src/etc/AppSettings'; 5 import { appSettings } from 'src/etc/AppSettings';
5 import { Router } from '@angular/router'; 6 import { Router } from '@angular/router';
6 7
7 @Component({ 8 @Component({
8 selector: 'app-busqueda-productos', 9 selector: 'app-busqueda-productos',
9 templateUrl: './busqueda-productos.component.html', 10 templateUrl: './busqueda-productos.component.html',
10 styleUrls: ['./busqueda-productos.component.scss'] 11 styleUrls: ['./busqueda-productos.component.scss']
11 }) 12 })
12 export class BusquedaProductosComponent implements OnInit { 13 export class BusquedaProductosComponent implements OnInit {
13 14
14 private productos: Producto[] = []; 15 private productos: Producto[] = [];
15 private auxProductos: Producto[] = []; 16 private auxProductos: Producto[] = [];
16 private searchTerm: string = ''; 17 private searchTerm: string = '';
17 private categoriaActive: number = null; 18 private categoriaActive: number = null;
18 private showSpinner: boolean = true; 19 private showSpinner: boolean = true;
19 private apiUrl: string = appSettings.apiUrl; 20 private apiUrl: string = appSettings.apiUrl;
20 private showBtnCargarProducto: boolean = false; 21 private showBtnCargarProducto: boolean = false;
21 private categorias: Categoria[] = []; 22 private categorias: Categoria[] = [];
22 23
23 constructor( 24 constructor(
24 private productoService: ProductoService, 25 private productoService: ProductoService,
25 private router: Router) { } 26 private router: Router) { }
26 27
27 ngOnInit() { 28 ngOnInit() {
28 29
29 this.productoService.getCategorias() 30 this.productoService.getCategorias()
30 .subscribe((categorias: Categoria[]) => { 31 .subscribe((categorias: Categoria[]) => {
31 this.categorias = categorias; 32 this.categorias = categorias;
32 this.categoriaActive = categorias[0].id; 33 this.categoriaActive = categorias[0].id;
33 }); 34 });
34 35
35 this.productoService.productoAcargar = undefined; 36 this.productoService.productoAcargar = undefined;
36 this.productoService.getAll() 37 this.productoService.getAll()
37 .subscribe((data: Producto[]) => { 38 .subscribe((data: Producto[]) => {
38 39
39 this.auxProductos = this.productos = data; 40 this.auxProductos = this.productos = data;
40 }, (error) => { 41 }, (error) => {
41 this.showSpinner = false; 42 this.showSpinner = false;
42 console.error(error); 43 console.error(error);
43 }); 44 });
44 } 45 }
45 46
46 filterItems() { 47 filterItems() {
47 48
48 this.auxProductos = this.productos.filter(x => { 49 this.auxProductos = this.productos.filter(x => {
49 return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && 50 return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) &&
50 x.categoria_selfservice == this.categoriaActive; 51 x.categoria_selfservice == this.categoriaActive;
51 }); 52 });
52 } 53 }
53 54
54 agregarAlCarrito(producto: Producto) { 55 agregarAlCarrito(producto: Producto) {
55 56
56 producto.cantidad = 1; 57 producto.cantidad = 1;
57 this.productoService.productos.push(producto); 58 this.productoService.productos.push(producto);
58 } 59 }
59 60
60 private mostrarBotonCargar(producto: Producto) { 61 private mostrarBotonCargar(producto: Producto) {
61 62
62 for (let i = 0; i < this.auxProductos.length; i++) { 63 for (let i = 0; i < this.auxProductos.length; i++) {
63 if (this.auxProductos[i].id !== producto.id) 64 if (this.auxProductos[i].id !== producto.id)
64 this.auxProductos[i].showCargarProducto = false; 65 this.auxProductos[i].showCargarProducto = false;
65 else if (producto.showCargarProducto) return; 66 else if (producto.showCargarProducto) return;
66 } 67 }
67 producto.showCargarProducto = !producto.showCargarProducto 68 producto.showCargarProducto = !producto.showCargarProducto
68 } 69 }
69 70
70 private elegirProducto(producto: Producto) { 71 private elegirProducto(producto: Producto) {
71 72
72 this.productoService.productoAcargar = producto; 73 this.productoService.productoAcargar = producto;
73 this.router.navigate(['inicio']); 74 this.router.navigate(['inicio']);
74 } 75 }
75 } 76 }
76 77
77 interface Categoria {
78 id: number,
79 detalle: string,
80 es_promocion: boolean,
81 vigencia_desde: Date,
82 vigencia_hasta: Date
83 }
src/app/wrappers/categoria.ts
File was created 1 export interface Categoria {
2 id: number,
3 detalle: string,
4 es_promocion: boolean,
5 vigencia_desde: Date,
6 vigencia_hasta: Date
7 }