Commit 83dfaec4863248cff2b86b6a02e2ae1ddacded8c
1 parent
4bdc05ab71
Exists in
develop
Fix
en cantidades de sinonimos
Showing
3 changed files
with
21 additions
and
9 deletions
Show diff stats
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
1 | import { Component, OnInit, OnDestroy, HostListener, ViewChild, AfterViewInit } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy, HostListener, ViewChild, AfterViewInit } from '@angular/core'; |
2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } 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 { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 7 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
8 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; | 8 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; |
9 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 9 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
11 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; |
12 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; | 12 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; |
13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; |
14 | import { ANIMATIONS } from 'src/app/utils/animations'; | 14 | import { ANIMATIONS } from 'src/app/utils/animations'; |
15 | 15 | ||
16 | @Component({ | 16 | @Component({ |
17 | selector: 'app-seleccion-articulos', | 17 | selector: 'app-seleccion-articulos', |
18 | templateUrl: './seleccion-articulos.component.html', | 18 | templateUrl: './seleccion-articulos.component.html', |
19 | styleUrls: ['./seleccion-articulos.component.scss'], | 19 | styleUrls: ['./seleccion-articulos.component.scss'], |
20 | animations: [ANIMATIONS.EnterLeaveY] | 20 | animations: [ANIMATIONS.EnterLeaveY] |
21 | }) | 21 | }) |
22 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { | 22 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { |
23 | loading = true; | 23 | loading = true; |
24 | timeoutHandler: any; | 24 | timeoutHandler: any; |
25 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 25 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
26 | articulos: IArticulo[] = []; | 26 | articulos: IArticulo[] = []; |
27 | auxArticulos: IArticulo[] = []; | 27 | auxArticulos: IArticulo[] = []; |
28 | showQuantity = 100; | 28 | showQuantity = 100; |
29 | searchTerm = ''; | 29 | searchTerm = ''; |
30 | ordenandoByVendidos = true; | 30 | ordenandoByVendidos = true; |
31 | modalRef: BsModalRef; | 31 | modalRef: BsModalRef; |
32 | total = 0; | 32 | total = 0; |
33 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; | 33 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; |
34 | 34 | ||
35 | constructor( | 35 | constructor( |
36 | public articuloService: ArticuloService, | 36 | public articuloService: ArticuloService, |
37 | private sinonimoService: SinonimoService, | 37 | private sinonimoService: SinonimoService, |
38 | private modalService: BsModalService, | 38 | private modalService: BsModalService, |
39 | private inactiveScreen: InactiveScreenService, | 39 | private inactiveScreen: InactiveScreenService, |
40 | ) { } | 40 | ) { } |
41 | 41 | ||
42 | ngOnInit() { } | 42 | ngOnInit() { } |
43 | 43 | ||
44 | ngAfterViewInit(): void { | 44 | ngAfterViewInit(): void { |
45 | this.filtroCategorias.getCategorias(); | 45 | this.filtroCategorias.getCategorias(); |
46 | this.mediaPantalla(); | 46 | this.mediaPantalla(); |
47 | } | 47 | } |
48 | 48 | ||
49 | ngOnDestroy() { | 49 | ngOnDestroy() { |
50 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 50 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { |
51 | this.modalService.hide(i); | 51 | this.modalService.hide(i); |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | getProductos() { | 55 | getProductos() { |
56 | this.articuloService.getAll() | 56 | this.articuloService.getAll() |
57 | .subscribe((result: IArticulo[]) => { | 57 | .subscribe((result: IArticulo[]) => { |
58 | this.articuloService.setArticulosSinImagen(result); | 58 | this.articuloService.setArticulosSinImagen(result); |
59 | if (this.filtroCategorias.queMostrar === 'ordenar') { | 59 | if (this.filtroCategorias.queMostrar === 'ordenar') { |
60 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { | 60 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { |
61 | const tempArticulos = result.filter((articulo: IArticulo) => { | 61 | const tempArticulos = result.filter((articulo: IArticulo) => { |
62 | return articulo.categoria_selfservice === categoria.id; | 62 | return articulo.categoria_selfservice === categoria.id; |
63 | }); | 63 | }); |
64 | result = tempArticulos; | 64 | result = tempArticulos; |
65 | }); | 65 | }); |
66 | } | 66 | } |
67 | localStorage.setItem('articulos', JSON.stringify(result)); | 67 | localStorage.setItem('articulos', JSON.stringify(result)); |
68 | this.setProductos(); | 68 | this.setProductos(); |
69 | }, (error) => { | 69 | }, (error) => { |
70 | console.error(error); | 70 | console.error(error); |
71 | }); | 71 | }); |
72 | } | 72 | } |
73 | 73 | ||
74 | setProductos() { | 74 | setProductos() { |
75 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 75 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
76 | this.filterItems(); | 76 | this.filterItems(); |
77 | this.loading = false; | 77 | this.loading = false; |
78 | } | 78 | } |
79 | 79 | ||
80 | filterItems() { | 80 | filterItems() { |
81 | if (this.filtroCategorias.categoriaActive === 0) { | 81 | if (this.filtroCategorias.categoriaActive === 0) { |
82 | this.auxArticulos = this.articulos; | 82 | this.auxArticulos = this.articulos; |
83 | return; | 83 | return; |
84 | } | 84 | } |
85 | this.auxArticulos = this.articulos.filter(x => { | 85 | this.auxArticulos = this.articulos.filter(x => { |
86 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; | 86 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; |
87 | }); | 87 | }); |
88 | this.ordenar(); | 88 | this.ordenar(); |
89 | } | 89 | } |
90 | 90 | ||
91 | ordenar() { | 91 | ordenar() { |
92 | if (this.ordenandoByVendidos) { | 92 | if (this.ordenandoByVendidos) { |
93 | this.auxArticulos.sort((a, b) => { | 93 | this.auxArticulos.sort((a, b) => { |
94 | return b.cantidadVendida - a.cantidadVendida; | 94 | return b.cantidadVendida - a.cantidadVendida; |
95 | }); | 95 | }); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | selectArticulo(articulo: IArticulo) { | 99 | selectArticulo(articulo: IArticulo) { |
100 | this.getByID(articulo.id); | 100 | this.getByID(articulo.id); |
101 | } | 101 | } |
102 | 102 | ||
103 | getByID(id: number) { | 103 | getByID(id: number) { |
104 | this.articuloService.getById(id) | 104 | this.articuloService.getById(id) |
105 | .subscribe((res: IArticulo) => { | 105 | .subscribe((res: IArticulo) => { |
106 | if (res.FPP) { | 106 | if (res.FPP) { |
107 | this.openModalPromos(res); | 107 | this.openModalPromos(res); |
108 | } else { | 108 | } else { |
109 | this.getSinonimos(res); | 109 | this.getSinonimos(res); |
110 | } | 110 | } |
111 | }, err => console.error(err)); | 111 | }, err => console.error(err)); |
112 | } | 112 | } |
113 | 113 | ||
114 | getSinonimos(articulo: IArticulo) { | 114 | getSinonimos(articulo: IArticulo) { |
115 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 115 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
116 | .subscribe((res: any[]) => { | 116 | .subscribe((res: any[]) => { |
117 | if (res.length) { | 117 | if (res.length) { |
118 | const sinonimos = []; | 118 | const sinonimos = []; |
119 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 119 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
120 | Object.keys(gruposArticulos).forEach((key, i) => { | 120 | Object.keys(gruposArticulos).forEach((key, i) => { |
121 | sinonimos.push({ productos: gruposArticulos[key] }); | 121 | sinonimos.push({ productos: gruposArticulos[key], }); |
122 | sinonimos[i].cantidad = articulo.productos[i].cantidad; | 122 | for (const a of articulo.productos) { |
123 | sinonimos[i].cantidadRestante = articulo.productos[i].cantidad; | 123 | if (key === a.idSinonimo.toString()) { |
124 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | ||
125 | continue; | ||
126 | } | ||
127 | } | ||
124 | }); | 128 | }); |
125 | res = sinonimos; | 129 | res = sinonimos; |
126 | this.openModalSinonimos(res, articulo); | 130 | this.openModalSinonimos(res, articulo); |
127 | } else { | 131 | } else { |
128 | this.articuloService.setArticulo(articulo); | 132 | this.articuloService.setArticulo(articulo); |
129 | } | 133 | } |
130 | }); | 134 | }); |
131 | } | 135 | } |
132 | 136 | ||
133 | openModalPromos(articulo: IArticulo) { | 137 | openModalPromos(articulo: IArticulo) { |
134 | if (this.modalRef) return; | 138 | if (this.modalRef) return; |
135 | this.articuloService.setArticulosSinImagen([articulo]); | 139 | this.articuloService.setArticulosSinImagen([articulo]); |
136 | this.modalRef = this.modalService.show(PromocionComponent, { | 140 | this.modalRef = this.modalService.show(PromocionComponent, { |
137 | initialState: { articulosPromo: [articulo] }, | 141 | initialState: { articulosPromo: [articulo] }, |
138 | class: 'modal-dialog-centered', | 142 | class: 'modal-dialog-centered', |
139 | ignoreBackdropClick: true, | 143 | ignoreBackdropClick: true, |
140 | }); | 144 | }); |
141 | this.modalRef.content.onClose | 145 | this.modalRef.content.onClose |
142 | .subscribe(() => this.modalRef = null); | 146 | .subscribe(() => this.modalRef = null); |
143 | this.mediaPantalla(); | 147 | this.mediaPantalla(); |
144 | } | 148 | } |
145 | 149 | ||
146 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 150 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
147 | if (this.modalRef) return; | 151 | if (this.modalRef) return; |
148 | this.modalRef = this.modalService.show(SinonimoComponent, { | 152 | this.modalRef = this.modalService.show(SinonimoComponent, { |
149 | initialState: { | 153 | initialState: { |
150 | sinonimos: sinonimosData, | 154 | sinonimos: sinonimosData, |
151 | articulo | 155 | articulo |
152 | }, | 156 | }, |
153 | class: 'modal-dialog-centered', | 157 | class: 'modal-dialog-centered', |
154 | ignoreBackdropClick: true, | 158 | ignoreBackdropClick: true, |
155 | }); | 159 | }); |
156 | 160 | ||
157 | this.modalRef.content.onClose | 161 | this.modalRef.content.onClose |
158 | .subscribe((res: any) => { | 162 | .subscribe((res: any) => { |
159 | this.modalRef = null; | 163 | this.modalRef = null; |
160 | if (!res) return; | 164 | if (!res) return; |
161 | articulo.productos = res.articulos; | 165 | articulo.productos = res.articulos; |
162 | this.articuloService.setArticulo(articulo); | 166 | this.articuloService.setArticulo(articulo); |
163 | }); | 167 | }); |
164 | this.mediaPantalla(); | 168 | this.mediaPantalla(); |
165 | } | 169 | } |
166 | 170 | ||
167 | deleteArticulo(index: number) { | 171 | deleteArticulo(index: number) { |
168 | this.articuloService.deleteArticulo(index); | 172 | this.articuloService.deleteArticulo(index); |
169 | } | 173 | } |
170 | 174 | ||
171 | increaseShow() { | 175 | increaseShow() { |
172 | this.showQuantity += 100; | 176 | this.showQuantity += 100; |
173 | } | 177 | } |
174 | 178 | ||
175 | @HostListener('scroll', ['$event']) | 179 | @HostListener('scroll', ['$event']) |
176 | scrollEvent(event: Event) { | 180 | scrollEvent(event: Event) { |
177 | clearTimeout(this.inactiveScreen.timerReposo); | 181 | clearTimeout(this.inactiveScreen.timerReposo); |
178 | this.inactiveScreen.startTimeOutInactividad(); | 182 | this.inactiveScreen.startTimeOutInactividad(); |
179 | } | 183 | } |
180 | 184 | ||
181 | mouseup() { | 185 | mouseup() { |
182 | if (!this.timeoutHandler) return; | 186 | if (!this.timeoutHandler) return; |
183 | clearInterval(this.timeoutHandler); | 187 | clearInterval(this.timeoutHandler); |
184 | } | 188 | } |
185 | 189 | ||
186 | scrollY(el: HTMLElement, value) { | 190 | scrollY(el: HTMLElement, value) { |
187 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 191 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
188 | this.timeoutHandler = setInterval(() => { | 192 | this.timeoutHandler = setInterval(() => { |
189 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 193 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
190 | }, 500); | 194 | }, 500); |
191 | } | 195 | } |
192 | 196 | ||
193 | scrollX(el: HTMLElement, value) { | 197 | scrollX(el: HTMLElement, value) { |
194 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 198 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
195 | this.timeoutHandler = setInterval(() => { | 199 | this.timeoutHandler = setInterval(() => { |
196 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 200 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
197 | }, 500); | 201 | }, 500); |
198 | } | 202 | } |
199 | 203 | ||
200 | mediaPantalla() { | 204 | mediaPantalla() { |
201 | if ($('body').hasClass('media-pantalla')) { | 205 | if ($('body').hasClass('media-pantalla')) { |
202 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 206 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
203 | .cat-box,.img-categoria, .modal-content`) | 207 | .cat-box,.img-categoria, .modal-content`) |
204 | .addClass('media-pantalla') | 208 | .addClass('media-pantalla') |
205 | .addBack('media-pantalla'); | 209 | .addBack('media-pantalla'); |
206 | } | 210 | } |
207 | } | 211 | } |
208 | } | 212 | } |
209 | 213 |
src/app/shared/header-publicidad/header-publicidad.component.ts
1 | import { Component, OnInit, TemplateRef } from '@angular/core'; | 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; |
2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; | 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; |
4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; | 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; |
5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
6 | import { PromocionComponent } from '../promocion/promocion.component'; | 6 | import { PromocionComponent } from '../promocion/promocion.component'; |
7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; | 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; |
8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; | 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; |
10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; |
14 | 14 | ||
15 | @Component({ | 15 | @Component({ |
16 | selector: 'app-header-publicidad', | 16 | selector: 'app-header-publicidad', |
17 | templateUrl: './header-publicidad.component.html', | 17 | templateUrl: './header-publicidad.component.html', |
18 | styleUrls: ['./header-publicidad.component.scss'] | 18 | styleUrls: ['./header-publicidad.component.scss'] |
19 | }) | 19 | }) |
20 | export class HeaderPublicidadComponent implements OnInit { | 20 | export class HeaderPublicidadComponent implements OnInit { |
21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
22 | publicidades: IPublicidad[] = []; | 22 | publicidades: IPublicidad[] = []; |
23 | modalRef: BsModalRef; | 23 | modalRef: BsModalRef; |
24 | modalSinonimo: BsModalRef; | 24 | modalSinonimo: BsModalRef; |
25 | 25 | ||
26 | constructor( | 26 | constructor( |
27 | private publicidadService: PublicidadService, | 27 | private publicidadService: PublicidadService, |
28 | private articuloService: ArticuloService, | 28 | private articuloService: ArticuloService, |
29 | private modalService: BsModalService, | 29 | private modalService: BsModalService, |
30 | private sinonimoService: SinonimoService | 30 | private sinonimoService: SinonimoService |
31 | ) { } | 31 | ) { } |
32 | 32 | ||
33 | ngOnInit() { | 33 | ngOnInit() { |
34 | this.getPublicidades(); | 34 | this.getPublicidades(); |
35 | this.mediaPantalla(); | 35 | this.mediaPantalla(); |
36 | } | 36 | } |
37 | 37 | ||
38 | getPublicidades() { | 38 | getPublicidades() { |
39 | this.publicidadService.getAll() | 39 | this.publicidadService.getAll() |
40 | .subscribe((res: IPublicidad[]) => { | 40 | .subscribe((res: IPublicidad[]) => { |
41 | this.publicidades = res; | 41 | this.publicidades = res; |
42 | }, err => console.error(err)); | 42 | }, err => console.error(err)); |
43 | } | 43 | } |
44 | 44 | ||
45 | elegirArticulo(publicidad: IPublicidad) { | 45 | elegirArticulo(publicidad: IPublicidad) { |
46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); |
47 | } | 47 | } |
48 | 48 | ||
49 | getByID(id: number) { | 49 | getByID(id: number) { |
50 | this.articuloService.getById(id) | 50 | this.articuloService.getById(id) |
51 | .subscribe((res: IArticulo) => { | 51 | .subscribe((res: IArticulo) => { |
52 | if (res.FPP) { | 52 | if (res.FPP) { |
53 | this.openModalPromos(res); | 53 | this.openModalPromos(res); |
54 | return; | 54 | return; |
55 | } else { | 55 | } else { |
56 | this.openModalConfirmacion(res); | 56 | this.openModalConfirmacion(res); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | }, err => console.error(err)); | 59 | }, err => console.error(err)); |
60 | } | 60 | } |
61 | 61 | ||
62 | openModalPromos(articulo: IArticulo) { | 62 | openModalPromos(articulo: IArticulo) { |
63 | if (this.modalRef) return; | 63 | if (this.modalRef) return; |
64 | this.modalRef = this.modalService.show(PromocionComponent, | 64 | this.modalRef = this.modalService.show(PromocionComponent, |
65 | { | 65 | { |
66 | initialState: { | 66 | initialState: { |
67 | idArticulo: articulo.id | 67 | idArticulo: articulo.id |
68 | }, | 68 | }, |
69 | class: 'modal-dialog-centered' | 69 | class: 'modal-dialog-centered' |
70 | }); | 70 | }); |
71 | } | 71 | } |
72 | 72 | ||
73 | openModalConfirmacion(articulo: IArticulo) { | 73 | openModalConfirmacion(articulo: IArticulo) { |
74 | if (this.modalRef) return; | 74 | if (this.modalRef) return; |
75 | this.articuloService.setArticulosSinImagen([articulo]); | 75 | this.articuloService.setArticulosSinImagen([articulo]); |
76 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 76 | this.modalRef = this.modalService.show(ConfirmacionComponent, |
77 | { | 77 | { |
78 | initialState: { | 78 | initialState: { |
79 | titleMessage: articulo.DET_LAR, | 79 | titleMessage: articulo.DET_LAR, |
80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', |
81 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, | 81 | footerMessageFirst: `¿QUERÉS AGREGAR ESTE COMBO`, |
82 | footerMessageSecond: `a tu carrito?`, | 82 | footerMessageSecond: `a tu carrito?`, |
83 | footerConfirmation: articulo.PreVen | 83 | footerConfirmation: articulo.PreVen |
84 | }, | 84 | }, |
85 | ignoreBackdropClick: true, | 85 | ignoreBackdropClick: true, |
86 | class: 'modal-dialog-centered' | 86 | class: 'modal-dialog-centered' |
87 | }); | 87 | }); |
88 | this.modalRef.content.onClose.subscribe((resClose) => { | 88 | this.modalRef.content.onClose.subscribe((resClose) => { |
89 | this.modalRef = null; | 89 | this.modalRef = null; |
90 | if (!resClose) return; | 90 | if (!resClose) return; |
91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
92 | .subscribe((res: ISinonimo[]) => { | 92 | .subscribe((res: ISinonimo[]) => { |
93 | if (res.length) { | 93 | if (res.length) { |
94 | const sinonimos = []; | 94 | const sinonimos = []; |
95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
96 | Object.keys(gruposArticulos).forEach((key, i) => { | 96 | Object.keys(gruposArticulos).forEach((key, i) => { |
97 | sinonimos.push({ productos: gruposArticulos[key] }); | 97 | sinonimos.push({ productos: gruposArticulos[key], }); |
98 | sinonimos[i].cantidad = articulo.productos[i].cantidad; | 98 | for (const a of articulo.productos) { |
99 | sinonimos[i].cantidadRestante = articulo.productos[i].cantidad; | 99 | if (key === a.idSinonimo.toString()) { |
100 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | ||
101 | continue; | ||
102 | } | ||
103 | } | ||
100 | }); | 104 | }); |
101 | res = sinonimos; | 105 | res = sinonimos; |
102 | this.openModalSinonimos(res, articulo); | 106 | this.openModalSinonimos(res, articulo); |
103 | } else { | 107 | } else { |
104 | articulo.cantidad = 1; | 108 | articulo.cantidad = 1; |
105 | this.articuloService.setArticulo(articulo); | 109 | this.articuloService.setArticulo(articulo); |
106 | } | 110 | } |
107 | }, err => console.error(err)); | 111 | }, err => console.error(err)); |
108 | }); | 112 | }); |
109 | this.mediaPantalla(); | 113 | this.mediaPantalla(); |
110 | } | 114 | } |
111 | 115 | ||
112 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 116 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
113 | if (this.modalSinonimo) return; | 117 | if (this.modalSinonimo) return; |
114 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 118 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
115 | initialState: { | 119 | initialState: { |
116 | sinonimos: sinonimosData, | 120 | sinonimos: sinonimosData, |
117 | articulo | 121 | articulo |
118 | }, | 122 | }, |
119 | class: 'modal-dialog-centered' | 123 | class: 'modal-dialog-centered' |
120 | }); | 124 | }); |
121 | this.modalSinonimo.content.onClose | 125 | this.modalSinonimo.content.onClose |
122 | .subscribe((res: any) => { | 126 | .subscribe((res: any) => { |
123 | this.modalSinonimo = null; | 127 | this.modalSinonimo = null; |
124 | if (!res) return; | 128 | if (!res) return; |
125 | articulo.productos = res.articulos; | 129 | articulo.productos = res.articulos; |
126 | this.articuloService.setArticulo(articulo); | 130 | this.articuloService.setArticulo(articulo); |
127 | }); | 131 | }); |
128 | } | 132 | } |
129 | 133 | ||
130 | mediaPantalla() { | 134 | mediaPantalla() { |
131 | if ($('body').hasClass('media-pantalla')) { | 135 | if ($('body').hasClass('media-pantalla')) { |
132 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 136 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); |
133 | } | 137 | } |
134 | } | 138 | } |
135 | } | 139 | } |
136 | 140 |
src/app/shared/promocion/promocion.component.ts
1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; |
2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; | 5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; |
6 | import { Subject } from 'rxjs'; | 6 | import { Subject } from 'rxjs'; |
7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
12 | import * as _ from 'lodash'; | 12 | import * as _ from 'lodash'; |
13 | 13 | ||
14 | @Component({ | 14 | @Component({ |
15 | selector: 'app-promocion', | 15 | selector: 'app-promocion', |
16 | templateUrl: './promocion.component.html', | 16 | templateUrl: './promocion.component.html', |
17 | styleUrls: ['./promocion.component.scss'] | 17 | styleUrls: ['./promocion.component.scss'] |
18 | }) | 18 | }) |
19 | export class PromocionComponent implements OnInit { | 19 | export class PromocionComponent implements OnInit { |
20 | articulosPromo: IArticulo[] = []; | 20 | articulosPromo: IArticulo[] = []; |
21 | promociones: IArticulo[] = []; | 21 | promociones: IArticulo[] = []; |
22 | onClose: Subject<any>; | 22 | onClose: Subject<any>; |
23 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 23 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
24 | loading = true; | 24 | loading = true; |
25 | modalSinonimo: BsModalRef; | 25 | modalSinonimo: BsModalRef; |
26 | isPromoSelected = false; | 26 | isPromoSelected = false; |
27 | 27 | ||
28 | constructor( | 28 | constructor( |
29 | private modalPromocion: BsModalRef, | 29 | private modalPromocion: BsModalRef, |
30 | private modalService: BsModalService, | 30 | private modalService: BsModalService, |
31 | private articuloService: ArticuloService, | 31 | private articuloService: ArticuloService, |
32 | private promocionService: PromocionService, | 32 | private promocionService: PromocionService, |
33 | private sinonimoService: SinonimoService, | 33 | private sinonimoService: SinonimoService, |
34 | private inactiveScreen: InactiveScreenService, | 34 | private inactiveScreen: InactiveScreenService, |
35 | ) { | 35 | ) { |
36 | this.onClose = new Subject(); | 36 | this.onClose = new Subject(); |
37 | } | 37 | } |
38 | 38 | ||
39 | ngOnInit() { | 39 | ngOnInit() { |
40 | this.getPromociones(); | 40 | this.getPromociones(); |
41 | } | 41 | } |
42 | 42 | ||
43 | selectPromo(promo: IArticulo) { | 43 | selectPromo(promo: IArticulo) { |
44 | if (this.isPromoSelected) return; | 44 | if (this.isPromoSelected) return; |
45 | this.isPromoSelected = true; | 45 | this.isPromoSelected = true; |
46 | this.articuloService.getById(promo.id) | 46 | this.articuloService.getById(promo.id) |
47 | .subscribe((resPromo: IArticulo) => { | 47 | .subscribe((resPromo: IArticulo) => { |
48 | promo = resPromo; | 48 | promo = resPromo; |
49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
50 | .subscribe((res: ISinonimo[]) => { | 50 | .subscribe((res: ISinonimo[]) => { |
51 | if (res.length) { | 51 | if (res.length) { |
52 | const sinonimos = []; | 52 | const sinonimos = []; |
53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
54 | Object.keys(gruposArticulos).forEach((key, i) => { | 54 | Object.keys(gruposArticulos).forEach((key, i) => { |
55 | sinonimos.push({ productos: gruposArticulos[key] }); | 55 | sinonimos.push({ productos: gruposArticulos[key], }); |
56 | sinonimos[i].cantidad = promo.productos[i].cantidad; | 56 | for (const a of promo.productos) { |
57 | sinonimos[i].cantidadRestante = promo.productos[i].cantidad; | 57 | if (key === a.idSinonimo.toString()) { |
58 | sinonimos[i].cantidad = sinonimos[i].cantidadRestante = a.cantidad; | ||
59 | continue; | ||
60 | } | ||
61 | } | ||
58 | }); | 62 | }); |
59 | res = sinonimos; | 63 | res = sinonimos; |
60 | this.openModalSinonimos(res, promo); | 64 | this.openModalSinonimos(res, promo); |
61 | } else { | 65 | } else { |
62 | promo.cantidad = 1; | 66 | promo.cantidad = 1; |
63 | this.articuloService.setArticulo(promo); | 67 | this.articuloService.setArticulo(promo); |
64 | this.onClose.next(); | 68 | this.onClose.next(); |
65 | this.modalPromocion.hide(); | 69 | this.modalPromocion.hide(); |
66 | } | 70 | } |
67 | }, err => console.error(err)); | 71 | }, err => console.error(err)); |
68 | }, err => console.error(err)); | 72 | }, err => console.error(err)); |
69 | this.mediaPantalla(); | 73 | this.mediaPantalla(); |
70 | } | 74 | } |
71 | 75 | ||
72 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 76 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
73 | if (this.modalSinonimo) return; | 77 | if (this.modalSinonimo) return; |
74 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 78 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
75 | initialState: { | 79 | initialState: { |
76 | sinonimos: sinonimosData, | 80 | sinonimos: sinonimosData, |
77 | articulo | 81 | articulo |
78 | }, | 82 | }, |
79 | class: 'modal-dialog-centered', | 83 | class: 'modal-dialog-centered', |
80 | ignoreBackdropClick: true, | 84 | ignoreBackdropClick: true, |
81 | }); | 85 | }); |
82 | 86 | ||
83 | this.modalSinonimo.content.onClose | 87 | this.modalSinonimo.content.onClose |
84 | .subscribe((res: any) => { | 88 | .subscribe((res: any) => { |
85 | this.modalSinonimo = null; | 89 | this.modalSinonimo = null; |
86 | if (!res) { | 90 | if (!res) { |
87 | this.onClose.next(); | 91 | this.onClose.next(); |
88 | this.modalPromocion.hide(); | 92 | this.modalPromocion.hide(); |
89 | return; | 93 | return; |
90 | } | 94 | } |
91 | articulo.productos = res.articulos; | 95 | articulo.productos = res.articulos; |
92 | this.articuloService.setArticulo(articulo); | 96 | this.articuloService.setArticulo(articulo); |
93 | this.onClose.next(); | 97 | this.onClose.next(); |
94 | this.modalPromocion.hide(); | 98 | this.modalPromocion.hide(); |
95 | }); | 99 | }); |
96 | } | 100 | } |
97 | 101 | ||
98 | getPromociones() { | 102 | getPromociones() { |
99 | const sector = this.articulosPromo[0].CodSec; | 103 | const sector = this.articulosPromo[0].CodSec; |
100 | const codigo = this.articulosPromo[0].CodArt; | 104 | const codigo = this.articulosPromo[0].CodArt; |
101 | this.promocionService.getPromociones(sector, codigo) | 105 | this.promocionService.getPromociones(sector, codigo) |
102 | .subscribe((res: IArticulo[]) => { | 106 | .subscribe((res: IArticulo[]) => { |
103 | this.promociones = res; | 107 | this.promociones = res; |
104 | this.loading = false; | 108 | this.loading = false; |
105 | }, error => { console.error(error); }); | 109 | }, error => { console.error(error); }); |
106 | } | 110 | } |
107 | 111 | ||
108 | @HostListener('document:click', ['$event']) | 112 | @HostListener('document:click', ['$event']) |
109 | eventListener(event: Event) { | 113 | eventListener(event: Event) { |
110 | clearTimeout(this.inactiveScreen.timerReposo); | 114 | clearTimeout(this.inactiveScreen.timerReposo); |
111 | this.inactiveScreen.startTimeOutInactividad(); | 115 | this.inactiveScreen.startTimeOutInactividad(); |
112 | } | 116 | } |
113 | 117 | ||
114 | @HostListener('scroll', ['$event']) | 118 | @HostListener('scroll', ['$event']) |
115 | scrollEvent(event: Event) { | 119 | scrollEvent(event: Event) { |
116 | clearTimeout(this.inactiveScreen.timerReposo); | 120 | clearTimeout(this.inactiveScreen.timerReposo); |
117 | this.inactiveScreen.startTimeOutInactividad(); | 121 | this.inactiveScreen.startTimeOutInactividad(); |
118 | } | 122 | } |
119 | 123 | ||
120 | mediaPantalla() { | 124 | mediaPantalla() { |
121 | if ($('body').hasClass('media-pantalla')) { | 125 | if ($('body').hasClass('media-pantalla')) { |
122 | $('.modal-content').addClass('media-pantalla'); | 126 | $('.modal-content').addClass('media-pantalla'); |
123 | } | 127 | } |
124 | } | 128 | } |
125 | } | 129 | } |
126 | 130 |