Commit b98fa43e302d27092b73e3da6018b5237cd58566
1 parent
42f74088a6
Exists in
master
and in
1 other branch
Agregado filtro Todos.
Showing
2 changed files
with
13 additions
and
4 deletions
 
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.html
| 1 | <div class="row m-0 fade-in"> | 1 | <div class="row m-0 fade-in"> | 
| 2 | <div class="col-12 p-0"> | 2 | <div class="col-12 p-0"> | 
| 3 | 3 | ||
| 4 | <!-- NOMBRE DE SECCION --> | 4 | <!-- NOMBRE DE SECCION --> | 
| 5 | <div class="row m-0"> | 5 | <div class="row m-0"> | 
| 6 | <div class="col-12 p-0"> | 6 | <div class="col-12 p-0"> | 
| 7 | <p class="h5 py-1 bg-gray text-muted text-center"> | 7 | <p class="h5 py-1 bg-gray text-muted text-center"> | 
| 8 | Búsqueda | 8 | Búsqueda | 
| 9 | <i class="fa fa-search"></i> | 9 | <i class="fa fa-search"></i> | 
| 10 | </p> | 10 | </p> | 
| 11 | </div> | 11 | </div> | 
| 12 | </div> | 12 | </div> | 
| 13 | 13 | ||
| 14 | <div class="row m-3 disable-user-select"> | 14 | <div class="row m-3 disable-user-select"> | 
| 15 | 15 | ||
| 16 | <!-- FILTROS --> | 16 | <!-- FILTROS --> | 
| 17 | <div *ngIf="verCategorias" class="col-sm-2 p-1"> | 17 | <div *ngIf="verCategorias" class="col-sm-2 p-1"> | 
| 18 | <div class="text-center"> | 18 | <div class="text-center"> | 
| 19 | <p class="font-weight-bold text-muted border-bottom pb-2">Buscar por Categoría</p> | 19 | <p class="font-weight-bold text-muted border-bottom pb-2">Buscar por Categoría</p> | 
| 20 | </div> | 20 | </div> | 
| 21 | <ul class="list-group"> | 21 | <ul class="list-group"> | 
| 22 | <li | 22 | <li | 
| 23 | [ngClass]="{active: categoriaActive == 0}" | ||
| 24 | (click)="categoriaActive = 0; filterItems()" | ||
| 25 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> | ||
| 26 | Todos | ||
| 27 | </li> | ||
| 28 | <li | ||
| 23 | *ngFor="let categoria of categorias" | 29 | *ngFor="let categoria of categorias" | 
| 24 | [ngClass]="{active: categoriaActive == categoria.id}" | 30 | [ngClass]="{active: categoriaActive == categoria.id}" | 
| 25 | (click)="categoriaActive = categoria.id; filterItems()" | 31 | (click)="categoriaActive = categoria.id; filterItems()" | 
| 26 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> | 32 | class="list-group-item list-group-item-action text-center my-1 p-2 h6"> | 
| 27 | {{categoria.detalle}} | 33 | {{categoria.detalle}} | 
| 28 | </li> | 34 | </li> | 
| 29 | </ul> | 35 | </ul> | 
| 30 | </div> | 36 | </div> | 
| 31 | 37 | ||
| 32 | <!-- SEARCH INPUT --> | 38 | <!-- SEARCH INPUT --> | 
| 33 | <div *ngIf="productos.length > 0" class="fade-in col"> | 39 | <div *ngIf="productos.length > 0" class="fade-in col"> | 
| 34 | 40 | ||
| 35 | <div class="row search"> | 41 | <div class="row search"> | 
| 36 | <div class="col-sm-10"> | 42 | <div class="col-sm-10"> | 
| 37 | <span class="fa fa-search form-control-lg form-control-search pl-3"></span> | 43 | <span class="fa fa-search form-control-lg form-control-search pl-3"></span> | 
| 38 | <input | 44 | <input | 
| 39 | [matKeyboard]="'spanish'" | 45 | [matKeyboard]="'spanish'" | 
| 40 | type="text" | 46 | type="text" | 
| 41 | class="form-control form-control-lg shadow-sm rounded-pill px-5" | 47 | class="form-control form-control-lg shadow-sm rounded-pill px-5" | 
| 42 | placeholder="Búsqueda productos" | 48 | placeholder="Búsqueda productos" | 
| 43 | [(ngModel)]="searchTerm" | 49 | [(ngModel)]="searchTerm" | 
| 44 | (ngModelChange)="filterItems()"> | 50 | (ngModelChange)="filterItems()"> | 
| 45 | </div> | 51 | </div> | 
| 46 | <!-- BOTON VOLVER --> | 52 | <!-- BOTON VOLVER --> | 
| 47 | <div class="col-sm-2"> | 53 | <div class="col-sm-2"> | 
| 48 | <button | 54 | <button | 
| 49 | type="button" | 55 | type="button" | 
| 50 | class="btn btn-light btn-lg shadow-sm" | 56 | class="btn btn-light btn-lg shadow-sm" | 
| 51 | [routerLink]="['/inicio']"> | 57 | [routerLink]="['/inicio']"> | 
| 52 | <span class="font-weight-normal h6 pr-2">Volver</span> | 58 | <span class="font-weight-normal h6 pr-2">Volver</span> | 
| 53 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> | 59 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> | 
| 54 | </button> | 60 | </button> | 
| 55 | </div> | 61 | </div> | 
| 56 | <div class="col-sm-12 my-2"> | 62 | <div class="col-sm-12 my-2"> | 
| 57 | <span class="badge badge-light px-2">Más vendidos</span> | 63 | <span class="badge badge-light px-2">Más vendidos</span> | 
| 58 | </div> | 64 | </div> | 
| 59 | </div> | 65 | </div> | 
| 60 | <!-- LISTA DE PRODUCTOS --> | 66 | <!-- LISTA DE PRODUCTOS --> | 
| 61 | <div class="row align-items-start vh-70 overflow-scroll disable-user-select"> | 67 | <div class="row align-items-start vh-70 overflow-scroll disable-user-select"> | 
| 62 | <div | 68 | <div | 
| 63 | class="col-4 p-2" | 69 | class="col-4 p-2" | 
| 64 | *ngFor="let producto of auxProductos"> | 70 | *ngFor="let producto of auxProductos"> | 
| 65 | <div | 71 | <div | 
| 66 | class="card-effect bg-white rounded-sm shadow border-0" | 72 | class="card-effect bg-white rounded-sm shadow border-0" | 
| 67 | (click)="elegirProducto(producto)"> | 73 | (click)="elegirProducto(producto)"> | 
| 68 | <img src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}" class="rounded-sm w-100 m-auto"> | 74 | <img src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}" class="rounded-sm w-100 m-auto"> | 
| 69 | <div class="p-2"> | 75 | <div class="p-2"> | 
| 70 | <p class="h6 text-left m-0">{{producto.DetArt}}</p> | 76 | <p class="h6 text-left m-0">{{producto.DetArt}}</p> | 
| 71 | <div class="row justify-content-between m-0"> | 77 | <div class="row justify-content-between m-0"> | 
| 72 | <div class="col-12 p-0"> | 78 | <div class="col-12 p-0"> | 
| 73 | <div class="text-left"> | 79 | <div class="text-left"> | 
| 74 | <p class="m-0 h6"><small>{{producto.DET_LAR}}</small></p> | 80 | <p class="m-0 h6"><small>{{producto.DET_LAR}}</small></p> | 
| 75 | </div> | 81 | </div> | 
| 76 | </div> | 82 | </div> | 
| 77 | <div class="col-12 my-auto pt-2 pr-2 p-0"> | 83 | <div class="col-12 my-auto pt-2 pr-2 p-0"> | 
| 78 | <p class="text-right m-0 h6">{{producto.PreVen | currency}}</p> | 84 | <p class="text-right m-0 h6">{{producto.PreVen | currency}}</p> | 
| 79 | </div> | 85 | </div> | 
| 80 | </div> | 86 | </div> | 
| 81 | </div> | 87 | </div> | 
| 82 | </div> | 88 | </div> | 
| 83 | </div> | 89 | </div> | 
| 84 | </div> | 90 | </div> | 
| 85 | </div> | 91 | </div> | 
| 86 | 92 | ||
| 87 | <!-- SPINNER --> | 93 | <!-- SPINNER --> | 
| 88 | <div | 94 | <div | 
| 89 | *ngIf="productos.length === 0 && showSpinner" | 95 | *ngIf="productos.length === 0 && showSpinner" | 
| 90 | class="col-sm-10 p-0 align-self-center text-center"> | 96 | class="col-sm-10 p-0 align-self-center text-center"> | 
| 91 | <div class="spinner-border spinner-lg text-secondary" role="status"></div> | 97 | <div class="spinner-border spinner-lg text-secondary" role="status"></div> | 
| 92 | <span class="text-secondary m-2 h5">Cargando información.</span> | 98 | <span class="text-secondary m-2 h5">Cargando información.</span> | 
| 93 | </div> | 99 | </div> | 
| 94 | 100 | ||
| 95 | </div> | 101 | </div> | 
| 96 | 102 | ||
| 97 | </div> | 103 | </div> | 
| 98 | 104 | ||
| 99 | </div> | 105 | </div> | 
| 100 | 106 | 
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 ? 1 : 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 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 54 | if (this.categoriaActive === 0) | 
| 55 | x.categoria_selfservice == this.categoriaActive; | 55 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) | 
| 56 | else | ||
| 57 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && | ||
| 58 | x.categoria_selfservice === this.categoriaActive; | ||
| 56 | }); | 59 | }); | 
| 57 | } | 60 | } | 
| 58 | 61 | ||
| 59 | agregarAlCarrito(producto: Producto) { | 62 | agregarAlCarrito(producto: Producto) { | 
| 60 | 63 | ||
| 61 | producto.cantidad = 1; | 64 | producto.cantidad = 1; | 
| 62 | this.productoService.productos.push(producto); | 65 | this.productoService.productos.push(producto); | 
| 63 | } | 66 | } | 
| 64 | 67 | ||
| 65 | lostBlur() { | 68 | lostBlur() { | 
| 66 | this.blurFocus.emit(); | 69 | this.blurFocus.emit(); | 
| 67 | } | 70 | } | 
| 68 | 71 | ||
| 69 | private elegirProducto(producto: Producto) { | 72 | private elegirProducto(producto: Producto) { | 
| 70 | 73 | ||
| 71 | if (producto.PRO) { | 74 | if (producto.PRO) { | 
| 72 | 75 | ||
| 73 | let imagenes = producto.imagenes; | 76 | let imagenes = producto.imagenes; | 
| 74 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | 77 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | 
| 75 | .subscribe(res => { | 78 | .subscribe(res => { | 
| 76 | 79 | ||
| 77 | this.productoService.productoAcargar = res[0]; | 80 | this.productoService.productoAcargar = res[0]; | 
| 78 | this.productoService.productoAcargar.imagenes = imagenes; | 81 | this.productoService.productoAcargar.imagenes = imagenes; | 
| 79 | this.router.navigate(['inicio']); | 82 | this.router.navigate(['inicio']); | 
| 80 | }, | 83 | }, | 
| 81 | error => { console.error(error); } | 84 | error => { console.error(error); } | 
| 82 | ); | 85 | ); | 
| 83 | }else { | 86 | } else { | 
| 84 | 87 | ||
| 85 | this.productoService.productoAcargar = producto; | 88 | this.productoService.productoAcargar = producto; | 
| 86 | this.router.navigate(['inicio']); | 89 | this.router.navigate(['inicio']); | 
| 87 | } | 90 | } | 
| 88 | 91 | ||
| 89 | } | 92 | } | 
| 90 | } | 93 | } | 
| 91 | 94 |