Commit e2365a26265ca0553db56c3fde78f71b157e2846
1 parent
5db26b0a74
Exists in
master
and in
1 other branch
fix timeout
Showing
3 changed files
with
10 additions
and
11 deletions
Show diff stats
src/app/components/inicio/inicio.component.ts
| 1 | import { Component, OnInit, ViewChild, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, ViewChild, HostListener } from '@angular/core'; |
| 2 | import { PopoverDirective } from 'ngx-bootstrap'; | 2 | import { PopoverDirective } from 'ngx-bootstrap'; |
| 3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { appSettings } from 'src/etc/AppSettings'; |
| 4 | import { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
| 5 | import { ProductoService } from 'src/app/services/producto.service'; | 5 | import { ProductoService } from 'src/app/services/producto.service'; |
| 6 | import { Producto } from 'src/app/wrappers/producto'; | 6 | import { Producto } from 'src/app/wrappers/producto'; |
| 7 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; | 7 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
| 8 | 8 | ||
| 9 | @Component({ | 9 | @Component({ |
| 10 | selector: 'app-inicio', | 10 | selector: 'app-inicio', |
| 11 | templateUrl: './inicio.component.html', | 11 | templateUrl: './inicio.component.html', |
| 12 | styleUrls: ['./inicio.component.scss'] | 12 | styleUrls: ['./inicio.component.scss'] |
| 13 | }) | 13 | }) |
| 14 | export class InicioComponent implements OnInit { | 14 | export class InicioComponent implements OnInit { |
| 15 | 15 | ||
| 16 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { | 16 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { |
| 17 | 17 | ||
| 18 | if (e.keyCode == 13) { | 18 | if (e.keyCode == 13) { |
| 19 | this.buscarByCodigoBarras(this.busqueda); | 19 | this.buscarByCodigoBarras(this.busqueda); |
| 20 | this.busqueda = ''; | 20 | this.busqueda = ''; |
| 21 | } else { | 21 | } else { |
| 22 | this.busqueda += e.key; | 22 | this.busqueda += e.key; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; | 27 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; |
| 28 | private tienePromo = false; | 28 | private tienePromo = false; |
| 29 | private productoEsPromo = false; | 29 | private productoEsPromo = false; |
| 30 | private busqueda: string = ''; | 30 | private busqueda: string = ''; |
| 31 | 31 | ||
| 32 | private productoAcargar: Producto; | 32 | private productoAcargar: Producto; |
| 33 | private promoAcargar: Producto; | 33 | private promoAcargar: Producto; |
| 34 | 34 | ||
| 35 | productos: Producto[] = []; | 35 | productos: Producto[] = []; |
| 36 | promociones: Producto[] = []; | 36 | promociones: Producto[] = []; |
| 37 | sinonimos: Sinonimo[] = []; | 37 | sinonimos: Sinonimo[] = []; |
| 38 | apiUrl: string = appSettings.apiUrl | 38 | apiUrl: string = appSettings.apiUrl |
| 39 | 39 | ||
| 40 | constructor( | 40 | constructor( |
| 41 | private router: Router, | 41 | private router: Router, |
| 42 | private productoService: ProductoService) { } | 42 | private productoService: ProductoService) { } |
| 43 | 43 | ||
| 44 | ngOnInit() { | 44 | ngOnInit() { |
| 45 | 45 | ||
| 46 | this.productoAcargar = this.productoService.productoAcargar; | 46 | this.productoAcargar = this.productoService.productoAcargar; |
| 47 | if (this.productoAcargar) { | 47 | if (this.productoAcargar) { |
| 48 | if (this.productoAcargar.PRO) { | 48 | if (this.productoAcargar.PRO) { |
| 49 | this.promociones.push(this.productoAcargar); | 49 | this.promociones.push(this.productoAcargar); |
| 50 | this.promoSeleccionada(this.productoAcargar); | 50 | this.promoSeleccionada(this.productoAcargar); |
| 51 | } | 51 | } |
| 52 | else | 52 | else |
| 53 | this.getPromociones(); | 53 | this.getPromociones(); |
| 54 | } | 54 | } |
| 55 | this.getProductos(); | 55 | this.getProductos(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | getPromociones() { | 58 | getPromociones() { |
| 59 | 59 | ||
| 60 | var sector = this.productoAcargar.CodSec; | 60 | var sector = this.productoAcargar.CodSec; |
| 61 | var codigo = this.productoAcargar.CodArt; | 61 | var codigo = this.productoAcargar.CodArt; |
| 62 | this.productoService.getPromociones(sector, codigo) | 62 | this.productoService.getPromociones(sector, codigo) |
| 63 | .subscribe((res: Producto[]) => { | 63 | .subscribe((res: Producto[]) => { |
| 64 | 64 | ||
| 65 | if (res.length === 0) { | 65 | if (res.length === 0) { |
| 66 | //Si no tiene promociones la cargará al carrito despues de un tiempo | 66 | //Si no tiene promociones la cargará al carrito despues de un tiempo |
| 67 | setTimeout(() => { | 67 | // setTimeout(() => { |
| 68 | this.productoAcargar.cantidad = 1; | 68 | this.productoAcargar.cantidad = 1; |
| 69 | this.productoService.productos.push(this.productoAcargar); | 69 | this.productoService.productos.push(this.productoAcargar); |
| 70 | this.productoAcargar = this.productoService.productoAcargar = undefined; | 70 | this.productoAcargar = this.productoService.productoAcargar = undefined; |
| 71 | }, 2000) | 71 | // }, 2000) |
| 72 | } else { | 72 | } else { |
| 73 | 73 | ||
| 74 | this.promociones = res; | 74 | this.promociones = res; |
| 75 | this.popoverDirective.show(); | 75 | this.popoverDirective.show(); |
| 76 | } | 76 | } |
| 77 | }, error => { console.error(error); }) | 77 | }, error => { console.error(error); }) |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | showPopover() { | 80 | showPopover() { |
| 81 | 81 | ||
| 82 | this.popoverDirective.show(); | 82 | this.popoverDirective.show(); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | getProductos() { | 85 | getProductos() { |
| 86 | this.productoService.getAll() | 86 | this.productoService.getAll() |
| 87 | .subscribe((productos: Producto[]) => { | 87 | .subscribe((productos: Producto[]) => { |
| 88 | this.productos = productos; | 88 | this.productos = productos; |
| 89 | }); | 89 | }); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | irBusquedaProductos(verPromociones) { | 92 | irBusquedaProductos(verPromociones) { |
| 93 | 93 | ||
| 94 | this.productoService.verCategoriasProductos = verPromociones; | 94 | this.productoService.verCategoriasProductos = verPromociones; |
| 95 | this.router.navigate(['busqueda-productos']); | 95 | this.router.navigate(['busqueda-productos']); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | confirmarProducto() { | 98 | confirmarProducto() { |
| 99 | this.promoAcargar.cantidad = 1; | 99 | this.promoAcargar.cantidad = 1; |
| 100 | this.productoService.productos.push(this.promoAcargar); | 100 | this.productoService.productos.push(this.promoAcargar); |
| 101 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; | 101 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; |
| 102 | this.promociones = []; | 102 | this.promociones = []; |
| 103 | this.popoverDirective.hide(); | 103 | this.popoverDirective.hide(); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | deshacerCarga() { | 106 | deshacerCarga() { |
| 107 | 107 | ||
| 108 | if (this.sinonimos.length > 0) { | 108 | if (this.sinonimos.length > 0) { |
| 109 | this.sinonimos = []; | 109 | this.sinonimos = []; |
| 110 | this.popoverDirective.hide(); | 110 | this.popoverDirective.hide(); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | if (this.promoAcargar) { | 113 | if (this.promoAcargar) { |
| 114 | this.promoAcargar = undefined; | 114 | this.promoAcargar = undefined; |
| 115 | if (this.productoAcargar.PRO) { | 115 | if (this.productoAcargar.PRO) { |
| 116 | this.productoAcargar = undefined; | 116 | this.productoAcargar = undefined; |
| 117 | this.promociones = []; | 117 | this.promociones = []; |
| 118 | this.popoverDirective.hide(); | 118 | this.popoverDirective.hide(); |
| 119 | } else { | 119 | } else { |
| 120 | this.popoverDirective.show(); | 120 | this.popoverDirective.show(); |
| 121 | } | 121 | } |
| 122 | } else { | 122 | } else { |
| 123 | this.productoAcargar = undefined; | 123 | this.productoAcargar = undefined; |
| 124 | this.promociones = []; | 124 | this.promociones = []; |
| 125 | this.popoverDirective.hide(); | 125 | this.popoverDirective.hide(); |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | promoSeleccionada($event: Producto) { | 129 | promoSeleccionada($event: Producto) { |
| 130 | 130 | ||
| 131 | this.promoAcargar = $event; | 131 | this.promoAcargar = $event; |
| 132 | this.promoAcargar.tieneSinonimos = true; | 132 | this.promoAcargar.tieneSinonimos = true; |
| 133 | if (this.promoAcargar.tieneSinonimos) { | 133 | if (this.promoAcargar.tieneSinonimos) { |
| 134 | var sector = this.promoAcargar.CodSec; | 134 | var sector = this.promoAcargar.CodSec; |
| 135 | var codigo = this.promoAcargar.CodArt; | 135 | var codigo = this.promoAcargar.CodArt; |
| 136 | this.productoService.getPromocionSinonimos(sector, codigo) | 136 | this.productoService.getPromocionSinonimos(sector, codigo) |
| 137 | .subscribe((res: Sinonimo[]) => { | 137 | .subscribe((res: Sinonimo[]) => { |
| 138 | 138 | ||
| 139 | res.forEach(sinonimo => { | 139 | res.forEach(sinonimo => { |
| 140 | 140 | ||
| 141 | sinonimo.productos.forEach(productoSinonimo => { | 141 | sinonimo.productos.forEach(productoSinonimo => { |
| 142 | 142 | ||
| 143 | this.promoAcargar.productos.forEach(productoPromo => { | 143 | this.promoAcargar.productos.forEach(productoPromo => { |
| 144 | 144 | ||
| 145 | if (productoSinonimo.id === productoPromo.id) { | 145 | if (productoSinonimo.id === productoPromo.id) { |
| 146 | sinonimo.cantidad = productoPromo.cantidad; | 146 | sinonimo.cantidad = productoPromo.cantidad; |
| 147 | sinonimo.productoPadre = productoPromo.id; | 147 | sinonimo.productoPadre = productoPromo.id; |
| 148 | } | 148 | } |
| 149 | }) | 149 | }) |
| 150 | }) | 150 | }) |
| 151 | }) | 151 | }) |
| 152 | 152 | ||
| 153 | this.sinonimos = res; | 153 | this.sinonimos = res; |
| 154 | if (res.length > 0) | 154 | if (res.length > 0) |
| 155 | this.showPopover(); | 155 | this.showPopover(); |
| 156 | else | 156 | else |
| 157 | this.popoverDirective.hide(); | 157 | this.popoverDirective.hide(); |
| 158 | }) | 158 | }) |
| 159 | } else { | 159 | } else { |
| 160 | this.popoverDirective.hide(); | 160 | this.popoverDirective.hide(); |
| 161 | } | 161 | } |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | productosPersonalizados($event: Producto[]) { | 164 | productosPersonalizados($event: Producto[]) { |
| 165 | 165 | ||
| 166 | var productosPersonalizados = $event; | 166 | var productosPersonalizados = $event; |
| 167 | 167 | ||
| 168 | this.promoAcargar.productos.forEach(productoPromo => { | 168 | this.promoAcargar.productos.forEach(productoPromo => { |
| 169 | 169 | ||
| 170 | if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); | 170 | if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); |
| 171 | }) | 171 | }) |
| 172 | 172 | ||
| 173 | this.promoAcargar.productos = productosPersonalizados; | 173 | this.promoAcargar.productos = productosPersonalizados; |
| 174 | this.confirmarProducto(); | 174 | this.confirmarProducto(); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | buscarByCodigoBarras(busqueda) { | 177 | buscarByCodigoBarras(busqueda) { |
| 178 | 178 | ||
| 179 | let producto = this.productos.filter(producto => { | 179 | let producto = this.productos.filter(producto => { |
| 180 | return producto.codigoBarra == busqueda; | 180 | return producto.codigoBarra == busqueda; |
| 181 | }); | 181 | }); |
| 182 | 182 | ||
| 183 | if (producto.length) { | 183 | if (producto.length) { |
| 184 | 184 | ||
| 185 | this.productoAcargar = producto[0]; | 185 | this.productoAcargar = producto[0]; |
| 186 | this.getPromociones(); | 186 | this.getPromociones(); |
| 187 | 187 | ||
| 188 | } else { | 188 | } else { |
| 189 | alert('No se encuentra el producto'); | 189 | alert('No se encuentra el producto'); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | } | 194 | } |
| 195 | 195 |
src/app/components/sidebar/sidebar.component.html
| 1 | <div class="disable-user-select d-flex align-items-center flex-column h-100 pt-2 text-center"> | 1 | <div class="disable-user-select d-flex align-items-center flex-column h-100 pt-2 text-center"> |
| 2 | 2 | ||
| 3 | <!-- ENCABEZADO --> | 3 | <!-- ENCABEZADO --> |
| 4 | <p class="h4 border-bottom border-white text-white mt-4 pb-2"> | 4 | <p class="h4 border-bottom border-white text-white mt-4 pb-2"> |
| 5 | Mi compra | 5 | Mi compra |
| 6 | <i class="fa fa-shopping-cart" aria-hidden="true"></i> | 6 | <i class="fa fa-shopping-cart" aria-hidden="true"></i> |
| 7 | </p> | 7 | </p> |
| 8 | 8 | ||
| 9 | <div class="overflow-auto overflow-scroll mb-2 w-100"> | 9 | <div class="overflow-auto overflow-scroll mb-2 w-100"> |
| 10 | <!-- PRODUCTOS CARRITO --> | 10 | <!-- PRODUCTOS CARRITO --> |
| 11 | <div | 11 | <div |
| 12 | class="slide-in-bl my-2 bg-white border-0 rounded-sm" | 12 | class="slide-in-bl my-2 bg-white border-0 rounded-sm" |
| 13 | *ngFor="let producto of productosCarrito.slice().reverse(); let i = index"> | 13 | *ngFor="let producto of productosCarrito.slice().reverse(); let i = index"> |
| 14 | <img class="w-100 m-auto rounded-sm shadow" src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}"> | 14 | <img class="w-100 m-auto rounded-sm shadow" src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}"> |
| 15 | <div class="row m-0 p-0 px-1 py-1 shadow rounded-sm"> | 15 | <div class="row m-0 p-0 px-1 py-1 shadow rounded-sm"> |
| 16 | <div class="col-12 p-0 pt-2 text-left my-auto"> | 16 | <div class="col-12 p-0 pt-2 text-left my-auto"> |
| 17 | <p class="m-0 h6"><small>{{producto.DetArt}}</small></p> | 17 | <p class="m-0 h6"><small>{{producto.DetArt}}</small></p> |
| 18 | <p class="m-0 h6"><small>COD: {{producto.CodRub}}</small></p> | 18 | <p class="m-0 h6"><small>COD: {{producto.CodRub}}</small></p> |
| 19 | </div> | 19 | </div> |
| 20 | <div class="col-12 pr-1 text-right h6 my-auto "> | 20 | <div class="col-12 pr-1 text-right h6 my-auto "> |
| 21 | <p class="m-0">{{producto.PreVen | currency}}</p> | 21 | <p class="m-0">{{producto.PreVen | currency}}</p> |
| 22 | </div> | 22 | </div> |
| 23 | </div> | 23 | </div> |
| 24 | 24 | ||
| 25 | <!-- BOTONES --> | 25 | <!-- BOTONES --> |
| 26 | <div class="row m-0 d-flex justify-content-between"> | 26 | <div class="row m-0 d-flex justify-content-between"> |
| 27 | 27 | ||
| 28 | <!-- SUMAR - RESTAR CANTIDAD --> | 28 | <!-- SUMAR - RESTAR CANTIDAD --> |
| 29 | <div class="col-auto px-1 my-2"> | 29 | <div class="col-auto px-1 my-2"> |
| 30 | <div class="btn-group-sm btn-group float-left my-auto" role="group"> | 30 | <div class="btn-group-sm btn-group float-left my-auto" role="group"> |
| 31 | <button | 31 | <button |
| 32 | type="button" | 32 | type="button" |
| 33 | class="btn btn-light btn-sm my-auto border shadow" | 33 | class="btn btn-light btn-sm my-auto border shadow" |
| 34 | (click)="aumentarCantidad(producto)"> | 34 | (click)="aumentarCantidad(producto)"> |
| 35 | <i class="fa fa-plus" aria-hidden="true"></i> | 35 | <i class="fa fa-plus" aria-hidden="true"></i> |
| 36 | </button> | 36 | </button> |
| 37 | <div class="bg-white border border-white px-3 my-auto text-dark h5 shadow"> | 37 | <div class="bg-white border border-white px-3 my-auto text-dark h5 shadow"> |
| 38 | <small>{{producto.cantidad}}</small> | 38 | <small>{{producto.cantidad}}</small> |
| 39 | </div> | 39 | </div> |
| 40 | <button | 40 | <button |
| 41 | type="button" | 41 | type="button" |
| 42 | class="btn btn-light btn-sm my-auto border shadow" | 42 | class="btn btn-light btn-sm my-auto border shadow" |
| 43 | (click)="restarCantidad(producto)"> | 43 | (click)="restarCantidad(producto)"> |
| 44 | <i class="fa fa-minus" aria-hidden="true"></i> | 44 | <i class="fa fa-minus" aria-hidden="true"></i> |
| 45 | </button> | 45 | </button> |
| 46 | </div> | 46 | </div> |
| 47 | </div> | 47 | </div> |
| 48 | 48 | ||
| 49 | <!-- PERSONALIZAR --> | 49 | <!-- PERSONALIZAR --> |
| 50 | <div class="col-auto px-1 my-2"> | 50 | <div class="col-auto px-1 my-2"> |
| 51 | <button | 51 | <button |
| 52 | *ngIf="esPersonalizable(producto)" | 52 | *ngIf="esPersonalizable(producto)" |
| 53 | type="button" | 53 | type="button" |
| 54 | class="btn btn-light btn-sm my-auto float-left border shadow" | 54 | class="btn btn-light btn-sm my-auto float-left border shadow" |
| 55 | (click)="personalizarPromo(producto, i)"> | 55 | (click)="personalizarPromo(producto, i)"> |
| 56 | <i class="fa fa-refresh text-purple" aria-hidden="true"></i> | 56 | <i class="fa fa-refresh text-purple" aria-hidden="true"></i> |
| 57 | </button> | 57 | </button> |
| 58 | </div> | 58 | </div> |
| 59 | 59 | ||
| 60 | <!-- BORRAR --> | 60 | <!-- BORRAR --> |
| 61 | <div class="col-auto px-1 my-2"> | 61 | <div class="col-auto px-1 my-2"> |
| 62 | <button | 62 | <button |
| 63 | type="button" | 63 | type="button" |
| 64 | class="btn btn-secondary btn-sm my-auto shadow" | 64 | class="btn btn-secondary btn-sm my-auto shadow" |
| 65 | (click)="deleteProducto(producto, i)"> | 65 | (click)="deleteProducto(producto, i)"> |
| 66 | <i class="fa fa-trash" aria-hidden="true"></i> | 66 | <i class="fa fa-trash" aria-hidden="true"></i> |
| 67 | </button> | 67 | </button> |
| 68 | </div> | 68 | </div> |
| 69 | </div> | 69 | </div> |
| 70 | </div> | 70 | </div> |
| 71 | </div> | 71 | </div> |
| 72 | 72 | ||
| 73 | <!-- TOTAL --> | 73 | <!-- TOTAL --> |
| 74 | <div class="card rounded-top-sm mt-auto blue-gradient border-0"> | 74 | <div class="card rounded-top-sm mt-auto blue-gradient border-0"> |
| 75 | <div class="card-body row"> | 75 | <div class="card-body row"> |
| 76 | <div class="col-12"> | 76 | <div class="col-12"> |
| 77 | <p | 77 | <p |
| 78 | class="h4 border-bottom border-secondary text-secondary pb-2"> | 78 | class="h4 border-bottom border-secondary text-secondary pb-2"> |
| 79 | ({{getCantidadProductos()}}) artículos | 79 | ({{getCantidadProductos()}}) artículos |
| 80 | </p> | 80 | </p> |
| 81 | <p class="h3 text-secondary">Total</p> | 81 | <p class="h3 text-secondary">Total</p> |
| 82 | <p class="h3 font-weight-bold">{{getTotal() | currency}}</p> | 82 | <p class="h3 font-weight-bold">{{getTotal() | currency}}</p> |
| 83 | </div> | 83 | </div> |
| 84 | <div class="col-12"> | 84 | <div class="col-12"> |
| 85 | <button | 85 | <button |
| 86 | *ngIf="cantTotal > 0" | 86 | *ngIf="getCantidadProductos() > 0" |
| 87 | type="button" | 87 | type="button" |
| 88 | class="btn btn-block btn-light btn-lg shadow mb-2 p-1" | 88 | class="btn btn-block btn-light btn-lg shadow mb-2 p-1" |
| 89 | routerLink="/confirmacion-carrito"> | 89 | routerLink="/confirmacion-carrito"> |
| 90 | <span class="font-weight-bold pr-1">Finalizar y Pagar</span> | 90 | <span class="font-weight-bold pr-1">Finalizar y Pagar</span> |
| 91 | <i class="fa fa-check text-success" aria-hidden="true"></i> | 91 | <i class="fa fa-check text-success" aria-hidden="true"></i> |
| 92 | </button> | 92 | </button> |
| 93 | <button | 93 | <button |
| 94 | type="button" | 94 | type="button" |
| 95 | class="btn btn-block btn-light shadow btn-sm shadow" | 95 | class="btn btn-block btn-light shadow btn-sm shadow" |
| 96 | [routerLink]="['/cancelar-compra']"> | 96 | [routerLink]="['/cancelar-compra']"> |
| 97 | <span class="pr-1">Cancelar</span> | 97 | <span class="pr-1">Cancelar</span> |
| 98 | <i class="fa fa-times text-danger" aria-hidden="true"></i> | 98 | <i class="fa fa-times text-danger" aria-hidden="true"></i> |
| 99 | </button> | 99 | </button> |
| 100 | </div> | 100 | </div> |
| 101 | </div> | 101 | </div> |
| 102 | </div> | 102 | </div> |
| 103 | </div> | 103 | </div> |
| 104 | 104 |
src/app/components/sidebar/sidebar.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
| 2 | import { Producto } from 'src/app/wrappers/producto'; | 2 | import { Producto } from 'src/app/wrappers/producto'; |
| 3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { appSettings } from 'src/etc/AppSettings'; |
| 4 | import { ProductoService } from 'src/app/services/producto.service'; | 4 | import { ProductoService } from 'src/app/services/producto.service'; |
| 5 | import { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
| 6 | 6 | ||
| 7 | @Component({ | 7 | @Component({ |
| 8 | selector: 'app-sidebar', | 8 | selector: 'app-sidebar', |
| 9 | templateUrl: './sidebar.component.html', | 9 | templateUrl: './sidebar.component.html', |
| 10 | styleUrls: ['./sidebar.component.scss'], | 10 | styleUrls: ['./sidebar.component.scss'], |
| 11 | }) | 11 | }) |
| 12 | export class SidebarComponent implements OnInit { | 12 | export class SidebarComponent implements OnInit { |
| 13 | 13 | ||
| 14 | private cantTotal: number = 0; | 14 | private cantTotal: number = 0; |
| 15 | private cantMin: number = 1; | 15 | private cantMin: number = 1; |
| 16 | private cantMax: number = 50; | 16 | private cantMax: number = 50; |
| 17 | private total: number = 0; | 17 | private total: number = 0; |
| 18 | private apiUrl: string = appSettings.apiUrl; | 18 | private apiUrl: string = appSettings.apiUrl; |
| 19 | 19 | ||
| 20 | public productosCarrito: Producto[] = []; | 20 | public productosCarrito: Producto[] = []; |
| 21 | 21 | ||
| 22 | constructor( | 22 | constructor( |
| 23 | private productoService: ProductoService, | 23 | private productoService: ProductoService, |
| 24 | private router: Router) { | 24 | private router: Router) { |
| 25 | this.router.routeReuseStrategy.shouldReuseRoute = function () { | 25 | this.router.routeReuseStrategy.shouldReuseRoute = function () { |
| 26 | return false; | 26 | return false; |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | ngOnInit() { | 30 | ngOnInit() { |
| 31 | 31 | ||
| 32 | this.productosCarrito = this.productoService.productos; | 32 | this.productosCarrito = this.productoService.productos; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | getCantidadProductos() { | 35 | getCantidadProductos() { |
| 36 | 36 | ||
| 37 | setTimeout(() => { | 37 | var cantTotalAux = 0; |
| 38 | var cantTotalAux = 0; | 38 | this.productosCarrito.forEach(producto => { |
| 39 | this.productosCarrito.forEach(producto => { | 39 | |
| 40 | 40 | cantTotalAux += producto.cantidad; | |
| 41 | cantTotalAux += producto.cantidad; | 41 | }); |
| 42 | }, 250); | 42 | this.cantTotal = cantTotalAux; |
| 43 | this.cantTotal = cantTotalAux; | 43 | |
| 44 | }) | ||
| 45 | return this.cantTotal; | 44 | return this.cantTotal; |
| 46 | } | 45 | } |
| 47 | 46 | ||
| 48 | getTotal() { | 47 | getTotal() { |
| 49 | 48 | ||
| 50 | var subTotal = 0; | 49 | var subTotal = 0; |
| 51 | for (let i = 0; i < this.productosCarrito.length; i++) { | 50 | for (let i = 0; i < this.productosCarrito.length; i++) { |
| 52 | subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); | 51 | subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); |
| 53 | } | 52 | } |
| 54 | return this.total = subTotal; | 53 | return this.total = subTotal; |
| 55 | } | 54 | } |
| 56 | 55 | ||
| 57 | aumentarCantidad(producto: Producto) { | 56 | aumentarCantidad(producto: Producto) { |
| 58 | 57 | ||
| 59 | if (producto.cantidad < this.cantMax) { | 58 | if (producto.cantidad < this.cantMax) { |
| 60 | producto.cantidad++; | 59 | producto.cantidad++; |
| 61 | this.cantTotal++ | 60 | this.cantTotal++ |
| 62 | } | 61 | } |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | restarCantidad(producto: Producto) { | 64 | restarCantidad(producto: Producto) { |
| 66 | 65 | ||
| 67 | if (producto.cantidad > this.cantMin) { | 66 | if (producto.cantidad > this.cantMin) { |
| 68 | producto.cantidad--; | 67 | producto.cantidad--; |
| 69 | this.cantTotal--; | 68 | this.cantTotal--; |
| 70 | } | 69 | } |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | deleteProducto(producto: Producto, index: number) { | 72 | deleteProducto(producto: Producto, index: number) { |
| 74 | 73 | ||
| 75 | this.cantTotal -= producto.cantidad; | 74 | this.cantTotal -= producto.cantidad; |
| 76 | this.total -= producto.PreVen * producto.cantidad; | 75 | this.total -= producto.PreVen * producto.cantidad; |
| 77 | this.productosCarrito.reverse().splice(index, 1); | 76 | this.productosCarrito.reverse().splice(index, 1); |
| 78 | return; | 77 | return; |
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | esPersonalizable(producto: Producto) { | 80 | esPersonalizable(producto: Producto) { |
| 82 | 81 | ||
| 83 | var esPersonalizable: boolean = false; | 82 | var esPersonalizable: boolean = false; |
| 84 | if (producto.tieneSinonimos) | 83 | if (producto.tieneSinonimos) |
| 85 | esPersonalizable = true; | 84 | esPersonalizable = true; |
| 86 | 85 | ||
| 87 | return esPersonalizable; | 86 | return esPersonalizable; |
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | personalizarPromo(producto: Producto, index) { | 89 | personalizarPromo(producto: Producto, index) { |
| 91 | 90 | ||
| 92 | this.productoService.productoAcargar = producto; | 91 | this.productoService.productoAcargar = producto; |
| 93 | this.deleteProducto(producto, index); | 92 | this.deleteProducto(producto, index); |
| 94 | this.router.navigate(['inicio']); | 93 | this.router.navigate(['inicio']); |
| 95 | } | 94 | } |
| 96 | 95 | ||
| 97 | } | 96 | } |
| 98 | 97 |