Commit b023575075183e501158f6b2c825f048a5722014
1 parent
134630072f
Exists in
develop
Fix
Manejo de modales.
Showing
3 changed files
with
25 additions
and
5 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 => { | 120 | Object.keys(gruposArticulos).forEach(key => { |
121 | sinonimos.push({ productos: gruposArticulos[key] }); | 121 | sinonimos.push({ productos: gruposArticulos[key] }); |
122 | }); | 122 | }); |
123 | res = sinonimos; | 123 | res = sinonimos; |
124 | this.openModalSinonimos(res, articulo); | 124 | this.openModalSinonimos(res, articulo); |
125 | } else { | 125 | } else { |
126 | this.articuloService.setArticulo(articulo); | 126 | this.articuloService.setArticulo(articulo); |
127 | } | 127 | } |
128 | }); | 128 | }); |
129 | } | 129 | } |
130 | 130 | ||
131 | openModalPromos(articulo: IArticulo) { | 131 | openModalPromos(articulo: IArticulo) { |
132 | if (this.modalRef) return; | 132 | if (this.modalRef) return; |
133 | this.articuloService.setArticulosSinImagen([articulo]); | 133 | this.articuloService.setArticulosSinImagen([articulo]); |
134 | this.modalRef = this.modalService.show(PromocionComponent, { | 134 | this.modalRef = this.modalService.show(PromocionComponent, { |
135 | initialState: { articulosPromo: [articulo] }, | 135 | initialState: { articulosPromo: [articulo] }, |
136 | class: 'modal-dialog-centered', | 136 | class: 'modal-dialog-centered', |
137 | ignoreBackdropClick: true, | 137 | ignoreBackdropClick: true, |
138 | }); | 138 | }); |
139 | this.modalRef.content.onClose | 139 | this.modalRef.content.onClose |
140 | .subscribe(() => this.modalRef = null); | 140 | .subscribe(() => this.modalRef = null); |
141 | this.mediaPantalla(); | 141 | this.mediaPantalla(); |
142 | } | 142 | } |
143 | 143 | ||
144 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 144 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
145 | if (this.modalRef) return; | ||
145 | this.modalRef = this.modalService.show(SinonimoComponent, { | 146 | this.modalRef = this.modalService.show(SinonimoComponent, { |
146 | initialState: { | 147 | initialState: { |
147 | sinonimos: sinonimosData, | 148 | sinonimos: sinonimosData, |
148 | articulo | 149 | articulo |
149 | }, | 150 | }, |
150 | class: 'modal-dialog-centered' | 151 | class: 'modal-dialog-centered', |
152 | ignoreBackdropClick: true, | ||
151 | }); | 153 | }); |
152 | 154 | ||
153 | this.modalRef.content.onClose | 155 | this.modalRef.content.onClose |
154 | .subscribe((res: any) => { | 156 | .subscribe((res: any) => { |
157 | this.modalRef = null; | ||
155 | for (const a of articulo.productos) { | 158 | for (const a of articulo.productos) { |
156 | for (const aRes of res.articulos) { | 159 | for (const aRes of res.articulos) { |
157 | if (a.idSinonimo === aRes.ID_SIN) { | 160 | if (a.idSinonimo === aRes.ID_SIN) { |
158 | a.CODA = aRes.CodArt; | 161 | a.CODA = aRes.CodArt; |
159 | a.CodArt = aRes.CodArt; | 162 | a.CodArt = aRes.CodArt; |
160 | a.SECA = aRes.CodSec; | 163 | a.SECA = aRes.CodSec; |
161 | aRes.CodSec = aRes.CodSec; | 164 | aRes.CodSec = aRes.CodSec; |
162 | a.PreVen = aRes.PreVen; | 165 | a.PreVen = aRes.PreVen; |
163 | a.id = aRes.id; | 166 | a.id = aRes.id; |
164 | a.DET_LAR = aRes.DET_LAR; | 167 | a.DET_LAR = aRes.DET_LAR; |
165 | a.DetArt = aRes.DetArt; | 168 | a.DetArt = aRes.DetArt; |
166 | } | 169 | } |
167 | } | 170 | } |
168 | } | 171 | } |
169 | this.articuloService.setArticulo(articulo); | 172 | this.articuloService.setArticulo(articulo); |
170 | }); | 173 | }); |
171 | this.mediaPantalla(); | 174 | this.mediaPantalla(); |
172 | } | 175 | } |
173 | 176 | ||
174 | deleteArticulo(index: number) { | 177 | deleteArticulo(index: number) { |
175 | this.articuloService.deleteArticulo(index); | 178 | this.articuloService.deleteArticulo(index); |
176 | } | 179 | } |
177 | 180 | ||
178 | increaseShow() { | 181 | increaseShow() { |
179 | this.showQuantity += 100; | 182 | this.showQuantity += 100; |
180 | } | 183 | } |
181 | 184 | ||
182 | @HostListener('scroll', ['$event']) | 185 | @HostListener('scroll', ['$event']) |
183 | scrollEvent(event: Event) { | 186 | scrollEvent(event: Event) { |
184 | clearTimeout(this.inactiveScreen.timerReposo); | 187 | clearTimeout(this.inactiveScreen.timerReposo); |
185 | this.inactiveScreen.startTimeOutInactividad(); | 188 | this.inactiveScreen.startTimeOutInactividad(); |
186 | } | 189 | } |
187 | 190 | ||
188 | mouseup() { | 191 | mouseup() { |
189 | if (!this.timeoutHandler) return; | 192 | if (!this.timeoutHandler) return; |
190 | clearInterval(this.timeoutHandler); | 193 | clearInterval(this.timeoutHandler); |
191 | } | 194 | } |
192 | 195 | ||
193 | scrollY(el: HTMLElement, value) { | 196 | scrollY(el: HTMLElement, value) { |
194 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 197 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
195 | this.timeoutHandler = setInterval(() => { | 198 | this.timeoutHandler = setInterval(() => { |
196 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 199 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
197 | }, 500); | 200 | }, 500); |
198 | } | 201 | } |
199 | 202 | ||
200 | scrollX(el: HTMLElement, value) { | 203 | scrollX(el: HTMLElement, value) { |
201 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 204 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
202 | this.timeoutHandler = setInterval(() => { | 205 | this.timeoutHandler = setInterval(() => { |
203 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 206 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
204 | }, 500); | 207 | }, 500); |
205 | } | 208 | } |
206 | 209 | ||
207 | mediaPantalla() { | 210 | mediaPantalla() { |
208 | if ($('body').hasClass('media-pantalla')) { | 211 | if ($('body').hasClass('media-pantalla')) { |
209 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 212 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
210 | .cat-box,.img-categoria, .modal-content`) | 213 | .cat-box,.img-categoria, .modal-content`) |
211 | .addClass('media-pantalla') | 214 | .addClass('media-pantalla') |
212 | .addBack('media-pantalla'); | 215 | .addBack('media-pantalla'); |
213 | } | 216 | } |
214 | } | 217 | } |
215 | } | 218 | } |
216 | 219 |
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; | ||
26 | isPromoSelected = false; | ||
25 | 27 | ||
26 | constructor( | 28 | constructor( |
27 | public modalPromocion: BsModalRef, | 29 | private modalPromocion: BsModalRef, |
28 | private modalService: BsModalService, | 30 | private modalService: BsModalService, |
29 | private articuloService: ArticuloService, | 31 | private articuloService: ArticuloService, |
30 | private promocionService: PromocionService, | 32 | private promocionService: PromocionService, |
31 | private sinonimoService: SinonimoService, | 33 | private sinonimoService: SinonimoService, |
32 | private inactiveScreen: InactiveScreenService, | 34 | private inactiveScreen: InactiveScreenService, |
33 | ) { | 35 | ) { |
34 | this.onClose = new Subject(); | 36 | this.onClose = new Subject(); |
35 | } | 37 | } |
36 | 38 | ||
37 | ngOnInit() { | 39 | ngOnInit() { |
38 | this.getPromociones(); | 40 | this.getPromociones(); |
39 | } | 41 | } |
40 | 42 | ||
41 | selectPromo(promo: IArticulo) { | 43 | selectPromo(promo: IArticulo) { |
44 | if (this.isPromoSelected) return; | ||
45 | this.isPromoSelected = true; | ||
42 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 46 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
43 | .subscribe((res: ISinonimo[]) => { | 47 | .subscribe((res: ISinonimo[]) => { |
44 | if (res.length) { | 48 | if (res.length) { |
45 | const sinonimos = []; | 49 | const sinonimos = []; |
46 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 50 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
47 | Object.keys(gruposArticulos).forEach(key => { | 51 | Object.keys(gruposArticulos).forEach(key => { |
48 | sinonimos.push({ productos: gruposArticulos[key] }); | 52 | sinonimos.push({ productos: gruposArticulos[key] }); |
49 | }); | 53 | }); |
50 | res = sinonimos; | 54 | res = sinonimos; |
51 | this.openModalSinonimos(res, promo); | 55 | this.openModalSinonimos(res, promo); |
52 | } else { | 56 | } else { |
53 | promo.cantidad = 1; | 57 | promo.cantidad = 1; |
54 | this.articuloService.setArticulo(promo); | 58 | this.articuloService.setArticulo(promo); |
55 | this.onClose.next(); | 59 | this.onClose.next(); |
56 | this.modalPromocion.hide(); | 60 | this.modalPromocion.hide(); |
57 | } | 61 | } |
58 | }, err => console.error(err)); | 62 | }, err => console.error(err)); |
59 | this.mediaPantalla(); | 63 | this.mediaPantalla(); |
60 | } | 64 | } |
61 | 65 | ||
62 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 66 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
63 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 67 | if (this.modalSinonimo) return; |
68 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | ||
64 | initialState: { | 69 | initialState: { |
65 | sinonimos: sinonimosData, | 70 | sinonimos: sinonimosData, |
66 | articulo | 71 | articulo |
67 | }, | 72 | }, |
68 | class: 'modal-dialog-centered' | 73 | class: 'modal-dialog-centered', |
74 | ignoreBackdropClick: true, | ||
69 | }); | 75 | }); |
70 | 76 | ||
71 | modalSinonimo.content.onClose | 77 | this.modalSinonimo.content.onClose |
72 | .subscribe((res: any) => { | 78 | .subscribe((res: any) => { |
79 | this.modalSinonimo = null; | ||
80 | if (!res) { | ||
81 | this.onClose.next(); | ||
82 | this.modalPromocion.hide(); | ||
83 | return; | ||
84 | } | ||
73 | for (const a of articulo.productos) { | 85 | for (const a of articulo.productos) { |
74 | for (const aRes of res.articulos) { | 86 | for (const aRes of res.articulos) { |
75 | if (a.idSinonimo === aRes.ID_SIN) { | 87 | if (a.idSinonimo === aRes.ID_SIN) { |
76 | a.CODA = aRes.CodArt; | 88 | a.CODA = aRes.CodArt; |
77 | a.CodArt = aRes.CodArt; | 89 | a.CodArt = aRes.CodArt; |
78 | a.SECA = aRes.CodSec; | 90 | a.SECA = aRes.CodSec; |
79 | aRes.CodSec = aRes.CodSec; | 91 | aRes.CodSec = aRes.CodSec; |
80 | a.PreVen = aRes.PreVen; | 92 | a.PreVen = aRes.PreVen; |
81 | a.id = aRes.id; | 93 | a.id = aRes.id; |
82 | a.DET_LAR = aRes.DET_LAR; | 94 | a.DET_LAR = aRes.DET_LAR; |
83 | a.DetArt = aRes.DetArt; | 95 | a.DetArt = aRes.DetArt; |
84 | } | 96 | } |
85 | } | 97 | } |
86 | } | 98 | } |
87 | this.articuloService.setArticulo(articulo); | 99 | this.articuloService.setArticulo(articulo); |
100 | this.onClose.next(); | ||
88 | this.modalPromocion.hide(); | 101 | this.modalPromocion.hide(); |
89 | }); | 102 | }); |
90 | } | 103 | } |
91 | 104 | ||
92 | getPromociones() { | 105 | getPromociones() { |
93 | const sector = this.articulosPromo[0].CodSec; | 106 | const sector = this.articulosPromo[0].CodSec; |
94 | const codigo = this.articulosPromo[0].CodArt; | 107 | const codigo = this.articulosPromo[0].CodArt; |
95 | this.promocionService.getPromociones(sector, codigo) | 108 | this.promocionService.getPromociones(sector, codigo) |
96 | .subscribe((res: IArticulo[]) => { | 109 | .subscribe((res: IArticulo[]) => { |
97 | this.promociones = res; | 110 | this.promociones = res; |
98 | this.loading = false; | 111 | this.loading = false; |
99 | }, error => { console.error(error); }); | 112 | }, error => { console.error(error); }); |
100 | } | 113 | } |
101 | 114 | ||
102 | @HostListener('document:click', ['$event']) | 115 | @HostListener('document:click', ['$event']) |
103 | eventListener(event: Event) { | 116 | eventListener(event: Event) { |
104 | clearTimeout(this.inactiveScreen.timerReposo); | 117 | clearTimeout(this.inactiveScreen.timerReposo); |
105 | this.inactiveScreen.startTimeOutInactividad(); | 118 | this.inactiveScreen.startTimeOutInactividad(); |
106 | } | 119 | } |
107 | 120 | ||
108 | @HostListener('scroll', ['$event']) | 121 | @HostListener('scroll', ['$event']) |
109 | scrollEvent(event: Event) { | 122 | scrollEvent(event: Event) { |
110 | clearTimeout(this.inactiveScreen.timerReposo); | 123 | clearTimeout(this.inactiveScreen.timerReposo); |
111 | this.inactiveScreen.startTimeOutInactividad(); | 124 | this.inactiveScreen.startTimeOutInactividad(); |
112 | } | 125 | } |
113 | 126 | ||
114 | mediaPantalla() { | 127 | mediaPantalla() { |
115 | if ($('body').hasClass('media-pantalla')) { | 128 | if ($('body').hasClass('media-pantalla')) { |
116 | $('.modal-content').addClass('media-pantalla'); | 129 | $('.modal-content').addClass('media-pantalla'); |
117 | } | 130 | } |
118 | } | 131 | } |
119 | } | 132 | } |
120 | 133 |
src/app/shared/sinonimo/sinonimo.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
4 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; |
5 | import { Subject, forkJoin } from 'rxjs'; | 5 | import { Subject, forkJoin } from 'rxjs'; |
6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
7 | import { element } from 'protractor'; | 7 | import { element } from 'protractor'; |
8 | 8 | ||
9 | @Component({ | 9 | @Component({ |
10 | selector: 'app-sinonimo', | 10 | selector: 'app-sinonimo', |
11 | templateUrl: './sinonimo.component.html', | 11 | templateUrl: './sinonimo.component.html', |
12 | styleUrls: ['./sinonimo.component.scss'] | 12 | styleUrls: ['./sinonimo.component.scss'] |
13 | }) | 13 | }) |
14 | export class SinonimoComponent implements OnInit { | 14 | export class SinonimoComponent implements OnInit { |
15 | sinonimos: ISinonimo[] = []; | 15 | sinonimos: ISinonimo[] = []; |
16 | isValid: boolean; | 16 | isValid: boolean; |
17 | onClose: Subject<any>; | 17 | onClose: Subject<any>; |
18 | articulosSelected: IArticulo[] = []; | 18 | articulosSelected: IArticulo[] = []; |
19 | articulo: IArticulo; | 19 | articulo: IArticulo; |
20 | isSinonimoSelected = false; | ||
20 | 21 | ||
21 | constructor( | 22 | constructor( |
22 | private modalRef: BsModalRef, | 23 | private modalRef: BsModalRef, |
23 | private articuloService: ArticuloService, | 24 | private articuloService: ArticuloService, |
24 | ) { | 25 | ) { |
25 | this.onClose = new Subject(); | 26 | this.onClose = new Subject(); |
26 | this.articulosSelected.length = this.sinonimos.length; | 27 | this.articulosSelected.length = this.sinonimos.length; |
27 | } | 28 | } |
28 | 29 | ||
29 | ngOnInit() { } | 30 | ngOnInit() { } |
30 | 31 | ||
31 | selectSinonimo(index: number, articulo: IArticulo) { | 32 | selectSinonimo(index: number, articulo: IArticulo) { |
32 | for (const a of this.sinonimos[index].productos) { | 33 | for (const a of this.sinonimos[index].productos) { |
33 | a.seleccionado = false; | 34 | a.seleccionado = false; |
34 | } | 35 | } |
35 | articulo.seleccionado = true; | 36 | articulo.seleccionado = true; |
36 | this.articulosSelected[index] = articulo; | 37 | this.articulosSelected[index] = articulo; |
37 | } | 38 | } |
38 | 39 | ||
39 | validate() { | 40 | validate() { |
40 | this.isValid = true; | 41 | this.isValid = true; |
41 | for (const s of this.sinonimos) { | 42 | for (const s of this.sinonimos) { |
42 | for (const a of s.productos) { | 43 | for (const a of s.productos) { |
43 | this.isValid = (!a.seleccionado) ? false : true; | 44 | this.isValid = (!a.seleccionado) ? false : true; |
44 | if (this.isValid) break; | 45 | if (this.isValid) break; |
45 | } | 46 | } |
46 | if (!this.isValid) break; | 47 | if (!this.isValid) break; |
47 | } | 48 | } |
48 | return !this.isValid ? 'disabled' : 'btn-effect'; | 49 | return !this.isValid ? 'disabled' : 'btn-effect'; |
49 | } | 50 | } |
50 | 51 | ||
51 | continue() { | 52 | continue() { |
52 | if (!this.isValid) return; | 53 | if (!this.isValid) return; |
54 | if (this.isSinonimoSelected) return; | ||
55 | this.isSinonimoSelected = true; | ||
53 | const ID_SINS = []; | 56 | const ID_SINS = []; |
54 | const observables = []; | 57 | const observables = []; |
55 | 58 | ||
56 | for (const articulo of this.articulosSelected) { | 59 | for (const articulo of this.articulosSelected) { |
57 | ID_SINS.push(articulo.ID_SIN); | 60 | ID_SINS.push(articulo.ID_SIN); |
58 | } | 61 | } |
59 | 62 | ||
60 | for (const articulo of this.articulosSelected) { | 63 | for (const articulo of this.articulosSelected) { |
61 | observables.push(this.articuloService.getById(articulo.id)); | 64 | observables.push(this.articuloService.getById(articulo.id)); |
62 | } | 65 | } |
63 | 66 | ||
64 | forkJoin(observables) | 67 | forkJoin(observables) |
65 | .subscribe((res: IArticulo[]) => { | 68 | .subscribe((res: IArticulo[]) => { |
66 | for (const articulo of res) { | 69 | for (const articulo of res) { |
67 | for (const ID_SIN of ID_SINS) { | 70 | for (const ID_SIN of ID_SINS) { |
68 | articulo.ID_SIN = ID_SIN; | 71 | articulo.ID_SIN = ID_SIN; |
69 | } | 72 | } |
70 | } | 73 | } |
71 | this.modalRef.hide(); | 74 | this.modalRef.hide(); |
72 | this.onClose.next({ | 75 | this.onClose.next({ |
73 | articulos: res, | 76 | articulos: res, |
74 | }); | 77 | }); |
75 | }, err => console.error(err)); | 78 | }, err => console.error(err)); |
76 | } | 79 | } |
77 | 80 | ||
78 | scrollTo(index: number) { | 81 | scrollTo(index: number) { |
79 | const el = document.getElementById(index.toString()); | 82 | const el = document.getElementById(index.toString()); |
80 | el.scrollIntoView({ behavior: 'smooth' }); | 83 | el.scrollIntoView({ behavior: 'smooth' }); |
81 | } | 84 | } |
82 | 85 | ||
83 | close() { | 86 | close() { |
84 | this.modalRef.hide(); | 87 | this.modalRef.hide(); |
88 | this.onClose.next(); | ||
85 | } | 89 | } |
86 | 90 | ||
87 | } | 91 | } |
88 | 92 |