Commit 4ffae611a2afd3dc98e7cc25715b5564c5cbcd7f
1 parent
29059ce020
Exists in
develop
Cambio nombre de metodo
Showing
3 changed files
with
3 additions
and
3 deletions
Show diff stats
src/app/app.component.html
1 | <router-outlet></router-outlet> | 1 | <router-outlet></router-outlet> |
2 |
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef } from 'ngx-bootstrap/modal'; |
3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
4 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 4 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
6 | import { ICategoria } from 'src/app/interfaces/ICategoria'; | 6 | import { ICategoria } from 'src/app/interfaces/ICategoria'; |
7 | import { CategoriaService } from 'src/app/services/categoria/categoria.service'; | 7 | import { CategoriaService } from 'src/app/services/categoria/categoria.service'; |
8 | 8 | ||
9 | @Component({ | 9 | @Component({ |
10 | selector: 'app-seleccion-articulos', | 10 | selector: 'app-seleccion-articulos', |
11 | templateUrl: './seleccion-articulos.component.html', | 11 | templateUrl: './seleccion-articulos.component.html', |
12 | styleUrls: ['./seleccion-articulos.component.scss'] | 12 | styleUrls: ['./seleccion-articulos.component.scss'] |
13 | }) | 13 | }) |
14 | export class SeleccionArticulosComponent implements OnInit { | 14 | export class SeleccionArticulosComponent implements OnInit { |
15 | showSpinner = true; | 15 | showSpinner = true; |
16 | timeoutHandler: any; | 16 | timeoutHandler: any; |
17 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 17 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
18 | articulos: IArticulo[] = []; | 18 | articulos: IArticulo[] = []; |
19 | auxArticulos: IArticulo[] = []; | 19 | auxArticulos: IArticulo[] = []; |
20 | showQuantity = 100; | 20 | showQuantity = 100; |
21 | queMostrar = 'todos'; | 21 | queMostrar = 'todos'; |
22 | categoriaActive: number = null; | 22 | categoriaActive: number = null; |
23 | categorias: ICategoria[] = []; | 23 | categorias: ICategoria[] = []; |
24 | searchTerm = ''; | 24 | searchTerm = ''; |
25 | ordenandoByVendidos = true; | 25 | ordenandoByVendidos = true; |
26 | allActive = true; | 26 | allActive = true; |
27 | modalRef: BsModalRef; | 27 | modalRef: BsModalRef; |
28 | 28 | ||
29 | constructor( | 29 | constructor( |
30 | public articuloService: ArticuloService, | 30 | public articuloService: ArticuloService, |
31 | private categoriaService: CategoriaService, | 31 | private categoriaService: CategoriaService, |
32 | ) { } | 32 | ) { } |
33 | 33 | ||
34 | ngOnInit() { | 34 | ngOnInit() { |
35 | this.getCategorias(); | 35 | this.getCategorias(); |
36 | } | 36 | } |
37 | 37 | ||
38 | getCategorias() { | 38 | getCategorias() { |
39 | this.categoriaService.getCategorias() | 39 | this.categoriaService.getAll() |
40 | .subscribe((categorias: ICategoria[]) => { | 40 | .subscribe((categorias: ICategoria[]) => { |
41 | switch (this.queMostrar) { | 41 | switch (this.queMostrar) { |
42 | case 'todos': | 42 | case 'todos': |
43 | this.categorias = categorias; | 43 | this.categorias = categorias; |
44 | this.categoriaActive = 0; | 44 | this.categoriaActive = 0; |
45 | break; | 45 | break; |
46 | case 'promociones': | 46 | case 'promociones': |
47 | this.categorias = categorias; | 47 | this.categorias = categorias; |
48 | this.categoriaActive = 19; | 48 | this.categoriaActive = 19; |
49 | break; | 49 | break; |
50 | case 'ordenar': | 50 | case 'ordenar': |
51 | this.categorias = categorias.filter((categoria: ICategoria) => { | 51 | this.categorias = categorias.filter((categoria: ICategoria) => { |
52 | return categoria.ES_PEDIDO; | 52 | return categoria.ES_PEDIDO; |
53 | }); | 53 | }); |
54 | this.categoriaActive = 4; | 54 | this.categoriaActive = 4; |
55 | break; | 55 | break; |
56 | default: | 56 | default: |
57 | this.categorias = categorias; | 57 | this.categorias = categorias; |
58 | this.categoriaActive = 0; | 58 | this.categoriaActive = 0; |
59 | break; | 59 | break; |
60 | } | 60 | } |
61 | !localStorage.getItem('articulos') ? | 61 | !localStorage.getItem('articulos') ? |
62 | this.getProductos() : | 62 | this.getProductos() : |
63 | this.setProductos(); | 63 | this.setProductos(); |
64 | }); | 64 | }); |
65 | } | 65 | } |
66 | 66 | ||
67 | getProductos() { | 67 | getProductos() { |
68 | this.articuloService.getAll() | 68 | this.articuloService.getAll() |
69 | .subscribe((result: IArticulo[]) => { | 69 | .subscribe((result: IArticulo[]) => { |
70 | this.articuloService.setArticulosSinImagen(result); | 70 | this.articuloService.setArticulosSinImagen(result); |
71 | if (this.queMostrar === 'ordenar') { | 71 | if (this.queMostrar === 'ordenar') { |
72 | this.categorias.forEach((categoria: ICategoria) => { | 72 | this.categorias.forEach((categoria: ICategoria) => { |
73 | const tempArticulos = result.filter((articulo: IArticulo) => { | 73 | const tempArticulos = result.filter((articulo: IArticulo) => { |
74 | return articulo.categoria_selfservice === categoria.id; | 74 | return articulo.categoria_selfservice === categoria.id; |
75 | }); | 75 | }); |
76 | result = tempArticulos; | 76 | result = tempArticulos; |
77 | }); | 77 | }); |
78 | } | 78 | } |
79 | localStorage.setItem('articulos', JSON.stringify(result)); | 79 | localStorage.setItem('articulos', JSON.stringify(result)); |
80 | this.setProductos(); | 80 | this.setProductos(); |
81 | }, (error) => { | 81 | }, (error) => { |
82 | this.showSpinner = false; | 82 | this.showSpinner = false; |
83 | console.error(error); | 83 | console.error(error); |
84 | }); | 84 | }); |
85 | } | 85 | } |
86 | 86 | ||
87 | setProductos() { | 87 | setProductos() { |
88 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 88 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
89 | this.filterItems(); | 89 | this.filterItems(); |
90 | } | 90 | } |
91 | 91 | ||
92 | filterItems() { | 92 | filterItems() { |
93 | if (this.categoriaActive === 0) { | 93 | if (this.categoriaActive === 0) { |
94 | this.auxArticulos = this.articulos; | 94 | this.auxArticulos = this.articulos; |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | this.auxArticulos = this.articulos.filter(x => { | 97 | this.auxArticulos = this.articulos.filter(x => { |
98 | return x.categoria_selfservice === this.categoriaActive; | 98 | return x.categoria_selfservice === this.categoriaActive; |
99 | }); | 99 | }); |
100 | this.ordenar(); | 100 | this.ordenar(); |
101 | } | 101 | } |
102 | 102 | ||
103 | ordenar() { | 103 | ordenar() { |
104 | if (this.ordenandoByVendidos) { | 104 | if (this.ordenandoByVendidos) { |
105 | this.auxArticulos.sort((a, b) => { | 105 | this.auxArticulos.sort((a, b) => { |
106 | return b.cantidadVendida - a.cantidadVendida; | 106 | return b.cantidadVendida - a.cantidadVendida; |
107 | }); | 107 | }); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | selectCategoria(index: number, idCategoria?: number) { | 111 | selectCategoria(index: number, idCategoria?: number) { |
112 | if (this.categoriaActive === idCategoria) return; | 112 | if (this.categoriaActive === idCategoria) return; |
113 | this.categoriaActive = idCategoria; | 113 | this.categoriaActive = idCategoria; |
114 | this.allActive = idCategoria === 0 ? true : false; | 114 | this.allActive = idCategoria === 0 ? true : false; |
115 | this.categorias.forEach((categoria, i) => { | 115 | this.categorias.forEach((categoria, i) => { |
116 | categoria.selected = index === i ? true : false; | 116 | categoria.selected = index === i ? true : false; |
117 | }); | 117 | }); |
118 | this.filterItems(); | 118 | this.filterItems(); |
119 | } | 119 | } |
120 | 120 | ||
121 | elegirArticulo(articulo: IArticulo) { | 121 | elegirArticulo(articulo: IArticulo) { |
122 | this.articuloService.getById(articulo.id) | 122 | this.articuloService.getById(articulo.id) |
123 | .subscribe((res: IArticulo) => { | 123 | .subscribe((res: IArticulo) => { |
124 | res.cantidad = 1; | 124 | res.cantidad = 1; |
125 | this.articuloService.setArticulo(res); | 125 | this.articuloService.setArticulo(res); |
126 | }, err => console.error(err)); | 126 | }, err => console.error(err)); |
127 | } | 127 | } |
128 | 128 | ||
129 | increaseShow() { | 129 | increaseShow() { |
130 | this.showQuantity += 100; | 130 | this.showQuantity += 100; |
131 | } | 131 | } |
132 | 132 | ||
133 | mouseup() { | 133 | mouseup() { |
134 | if (!this.timeoutHandler) return; | 134 | if (!this.timeoutHandler) return; |
135 | clearInterval(this.timeoutHandler); | 135 | clearInterval(this.timeoutHandler); |
136 | } | 136 | } |
137 | 137 | ||
138 | scrollY(el: HTMLElement, value) { | 138 | scrollY(el: HTMLElement, value) { |
139 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 139 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
140 | this.timeoutHandler = setInterval(() => { | 140 | this.timeoutHandler = setInterval(() => { |
141 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 141 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
142 | }, 500); | 142 | }, 500); |
143 | } | 143 | } |
144 | 144 | ||
145 | scrollX(el: HTMLElement, value) { | 145 | scrollX(el: HTMLElement, value) { |
146 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 146 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
147 | this.timeoutHandler = setInterval(() => { | 147 | this.timeoutHandler = setInterval(() => { |
148 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 148 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
149 | }, 500); | 149 | }, 500); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 |
src/app/services/categoria/categoria.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 3 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
4 | 4 | ||
5 | @Injectable({ | 5 | @Injectable({ |
6 | providedIn: 'root' | 6 | providedIn: 'root' |
7 | }) | 7 | }) |
8 | export class CategoriaService { | 8 | export class CategoriaService { |
9 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; | 9 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; |
10 | 10 | ||
11 | constructor( | 11 | constructor( |
12 | private http: HttpClient, | 12 | private http: HttpClient, |
13 | ) { } | 13 | ) { } |
14 | 14 | ||
15 | getCategorias() { | 15 | getAll() { |
16 | return this.http.get(`${this.urlDeboSuite}/categorias`); | 16 | return this.http.get(`${this.urlDeboSuite}/categorias`); |
17 | } | 17 | } |
18 | } | 18 | } |
19 | 19 |