Commit d2123c803ab0ee56699004d6b88be070165bb71c
1 parent
c91a1487a6
Exists in
master
and in
1 other branch
Borrado metodo
Showing
1 changed file
with
0 additions
and
5 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() { | ||
81 | |||
82 | this.popoverDirective.show(); | ||
83 | } | ||
84 | |||
85 | getProductos() { | 80 | getProductos() { |
86 | this.productoService.getAll() | 81 | this.productoService.getAll() |
87 | .subscribe((productos: Producto[]) => { | 82 | .subscribe((productos: Producto[]) => { |
88 | this.productos = productos; | 83 | this.productos = productos; |
89 | }); | 84 | }); |
90 | } | 85 | } |
91 | 86 | ||
92 | irBusquedaProductos(verPromociones) { | 87 | irBusquedaProductos(verPromociones) { |
93 | 88 | ||
94 | this.productoService.verCategoriasProductos = verPromociones; | 89 | this.productoService.verCategoriasProductos = verPromociones; |
95 | this.router.navigate(['busqueda-productos']); | 90 | this.router.navigate(['busqueda-productos']); |
96 | } | 91 | } |
97 | 92 | ||
98 | confirmarProducto() { | 93 | confirmarProducto() { |
99 | this.promoAcargar.cantidad = 1; | 94 | this.promoAcargar.cantidad = 1; |
100 | this.productoService.productos.push(this.promoAcargar); | 95 | this.productoService.productos.push(this.promoAcargar); |
101 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; | 96 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; |
102 | this.promociones = []; | 97 | this.promociones = []; |
103 | this.popoverDirective.hide(); | 98 | this.popoverDirective.hide(); |
104 | } | 99 | } |
105 | 100 | ||
106 | deshacerCarga() { | 101 | deshacerCarga() { |
107 | 102 | ||
108 | if (this.sinonimos.length > 0) { | 103 | if (this.sinonimos.length > 0) { |
109 | this.sinonimos = []; | 104 | this.sinonimos = []; |
110 | this.popoverDirective.hide(); | 105 | this.popoverDirective.hide(); |
111 | } | 106 | } |
112 | 107 | ||
113 | if (this.promoAcargar) { | 108 | if (this.promoAcargar) { |
114 | this.promoAcargar = undefined; | 109 | this.promoAcargar = undefined; |
115 | if (this.productoAcargar.PRO) { | 110 | if (this.productoAcargar.PRO) { |
116 | this.productoAcargar = undefined; | 111 | this.productoAcargar = undefined; |
117 | this.promociones = []; | 112 | this.promociones = []; |
118 | this.popoverDirective.hide(); | 113 | this.popoverDirective.hide(); |
119 | } else { | 114 | } else { |
120 | this.popoverDirective.show(); | 115 | this.popoverDirective.show(); |
121 | } | 116 | } |
122 | } else { | 117 | } else { |
123 | this.productoAcargar = undefined; | 118 | this.productoAcargar = undefined; |
124 | this.promociones = []; | 119 | this.promociones = []; |
125 | this.popoverDirective.hide(); | 120 | this.popoverDirective.hide(); |
126 | } | 121 | } |
127 | } | 122 | } |
128 | 123 | ||
129 | promoSeleccionada($event: Producto) { | 124 | promoSeleccionada($event: Producto) { |
130 | 125 | ||
131 | this.promoAcargar = $event; | 126 | this.promoAcargar = $event; |
132 | this.promoAcargar.tieneSinonimos = true; | 127 | this.promoAcargar.tieneSinonimos = true; |
133 | if (this.promoAcargar.tieneSinonimos) { | 128 | if (this.promoAcargar.tieneSinonimos) { |
134 | var sector = this.promoAcargar.CodSec; | 129 | var sector = this.promoAcargar.CodSec; |
135 | var codigo = this.promoAcargar.CodArt; | 130 | var codigo = this.promoAcargar.CodArt; |
136 | this.productoService.getPromocionSinonimos(sector, codigo) | 131 | this.productoService.getPromocionSinonimos(sector, codigo) |
137 | .subscribe((res: Sinonimo[]) => { | 132 | .subscribe((res: Sinonimo[]) => { |
138 | 133 | ||
139 | res.forEach(sinonimo => { | 134 | res.forEach(sinonimo => { |
140 | 135 | ||
141 | sinonimo.productos.forEach(productoSinonimo => { | 136 | sinonimo.productos.forEach(productoSinonimo => { |
142 | 137 | ||
143 | this.promoAcargar.productos.forEach(productoPromo => { | 138 | this.promoAcargar.productos.forEach(productoPromo => { |
144 | 139 | ||
145 | if (productoSinonimo.id === productoPromo.id) { | 140 | if (productoSinonimo.id === productoPromo.id) { |
146 | sinonimo.cantidad = productoPromo.cantidad; | 141 | sinonimo.cantidad = productoPromo.cantidad; |
147 | sinonimo.productoPadre = productoPromo.id; | 142 | sinonimo.productoPadre = productoPromo.id; |
148 | } | 143 | } |
149 | }) | 144 | }) |
150 | }) | 145 | }) |
151 | }) | 146 | }) |
152 | 147 | ||
153 | this.sinonimos = res; | 148 | this.sinonimos = res; |
154 | if (res.length > 0) | 149 | if (res.length > 0) |
155 | this.showPopover(); | 150 | this.showPopover(); |
156 | else | 151 | else |
157 | this.popoverDirective.hide(); | 152 | this.popoverDirective.hide(); |
158 | }) | 153 | }) |
159 | } else { | 154 | } else { |
160 | this.popoverDirective.hide(); | 155 | this.popoverDirective.hide(); |
161 | } | 156 | } |
162 | } | 157 | } |
163 | 158 | ||
164 | productosPersonalizados($event: Producto[]) { | 159 | productosPersonalizados($event: Producto[]) { |
165 | 160 | ||
166 | var productosPersonalizados = $event; | 161 | var productosPersonalizados = $event; |
167 | 162 | ||
168 | this.promoAcargar.productos.forEach(productoPromo => { | 163 | this.promoAcargar.productos.forEach(productoPromo => { |
169 | 164 | ||
170 | if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); | 165 | if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); |
171 | }) | 166 | }) |
172 | 167 | ||
173 | this.promoAcargar.productos = productosPersonalizados; | 168 | this.promoAcargar.productos = productosPersonalizados; |
174 | this.confirmarProducto(); | 169 | this.confirmarProducto(); |
175 | } | 170 | } |
176 | 171 | ||
177 | buscarByCodigoBarras(busqueda) { | 172 | buscarByCodigoBarras(busqueda) { |
178 | 173 | ||
179 | let producto = this.productos.filter(producto => { | 174 | let producto = this.productos.filter(producto => { |
180 | return producto.codigoBarra == busqueda; | 175 | return producto.codigoBarra == busqueda; |
181 | }); | 176 | }); |
182 | 177 | ||
183 | if (producto.length) { | 178 | if (producto.length) { |
184 | 179 | ||
185 | this.productoAcargar = producto[0]; | 180 | this.productoAcargar = producto[0]; |
186 | this.getPromociones(); | 181 | this.getPromociones(); |
187 | 182 | ||
188 | } else { | 183 | } else { |
189 | alert('No se encuentra el producto'); | 184 | alert('No se encuentra el producto'); |
190 | } | 185 | } |
191 | 186 | ||
192 | } | 187 | } |
193 | 188 | ||
194 | } | 189 | } |
195 | 190 |