Commit f68c8f26479868cb19b92762935b285f7fd0b76c
1 parent
90e72dbbc2
Exists in
develop
arreglo mr
Showing
1 changed file
with
1 additions
and
2 deletions
Show diff stats
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 = false; | 24 | loading = true; |
25 | 25 | ||
26 | constructor( | 26 | constructor( |
27 | public modalPromocion: BsModalRef, | 27 | public modalPromocion: BsModalRef, |
28 | private modalService: BsModalService, | 28 | private modalService: BsModalService, |
29 | private articuloService: ArticuloService, | 29 | private articuloService: ArticuloService, |
30 | private promocionService: PromocionService, | 30 | private promocionService: PromocionService, |
31 | private sinonimoService: SinonimoService, | 31 | private sinonimoService: SinonimoService, |
32 | private inactiveScreen: InactiveScreenService, | 32 | private inactiveScreen: InactiveScreenService, |
33 | ) { | 33 | ) { |
34 | this.onClose = new Subject(); | 34 | this.onClose = new Subject(); |
35 | } | 35 | } |
36 | 36 | ||
37 | ngOnInit() { | 37 | ngOnInit() { |
38 | this.getPromociones(); | 38 | this.getPromociones(); |
39 | this.loading = true; | ||
40 | } | 39 | } |
41 | 40 | ||
42 | selectPromo(promo: IArticulo) { | 41 | selectPromo(promo: IArticulo) { |
43 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 42 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
44 | .subscribe((res: ISinonimo[]) => { | 43 | .subscribe((res: ISinonimo[]) => { |
45 | if (res.length) { | 44 | if (res.length) { |
46 | const sinonimos = []; | 45 | const sinonimos = []; |
47 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 46 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
48 | Object.keys(gruposArticulos).forEach(key => { | 47 | Object.keys(gruposArticulos).forEach(key => { |
49 | sinonimos.push({ productos: gruposArticulos[key] }); | 48 | sinonimos.push({ productos: gruposArticulos[key] }); |
50 | }); | 49 | }); |
51 | res = sinonimos; | 50 | res = sinonimos; |
52 | this.openModalSinonimos(res, promo); | 51 | this.openModalSinonimos(res, promo); |
53 | } else { | 52 | } else { |
54 | promo.cantidad = 1; | 53 | promo.cantidad = 1; |
55 | this.articuloService.setArticulo(promo); | 54 | this.articuloService.setArticulo(promo); |
56 | this.modalPromocion.hide(); | 55 | this.modalPromocion.hide(); |
57 | } | 56 | } |
58 | }, err => console.error(err)); | 57 | }, err => console.error(err)); |
59 | this.mediaPantalla(); | 58 | this.mediaPantalla(); |
60 | } | 59 | } |
61 | 60 | ||
62 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 61 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
63 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 62 | const modalSinonimo = this.modalService.show(SinonimoComponent, { |
64 | initialState: { | 63 | initialState: { |
65 | sinonimos: sinonimosData, | 64 | sinonimos: sinonimosData, |
66 | articulo | 65 | articulo |
67 | }, | 66 | }, |
68 | class: 'modal-dialog-centered' | 67 | class: 'modal-dialog-centered' |
69 | }); | 68 | }); |
70 | 69 | ||
71 | modalSinonimo.content.onClose | 70 | modalSinonimo.content.onClose |
72 | .subscribe((res: any) => { | 71 | .subscribe((res: any) => { |
73 | for (const a of articulo.productos) { | 72 | for (const a of articulo.productos) { |
74 | for (const aRes of res.articulos) { | 73 | for (const aRes of res.articulos) { |
75 | if (a.idSinonimo === aRes.ID_SIN) { | 74 | if (a.idSinonimo === aRes.ID_SIN) { |
76 | a.CODA = aRes.CodArt; | 75 | a.CODA = aRes.CodArt; |
77 | a.CodArt = aRes.CodArt; | 76 | a.CodArt = aRes.CodArt; |
78 | a.SECA = aRes.CodSec; | 77 | a.SECA = aRes.CodSec; |
79 | aRes.CodSec = aRes.CodSec; | 78 | aRes.CodSec = aRes.CodSec; |
80 | a.PreVen = aRes.PreVen; | 79 | a.PreVen = aRes.PreVen; |
81 | a.id = aRes.id; | 80 | a.id = aRes.id; |
82 | a.DET_LAR = aRes.DET_LAR; | 81 | a.DET_LAR = aRes.DET_LAR; |
83 | a.DetArt = aRes.DetArt; | 82 | a.DetArt = aRes.DetArt; |
84 | } | 83 | } |
85 | } | 84 | } |
86 | } | 85 | } |
87 | this.articuloService.setArticulo(articulo); | 86 | this.articuloService.setArticulo(articulo); |
88 | this.modalPromocion.hide(); | 87 | this.modalPromocion.hide(); |
89 | }); | 88 | }); |
90 | } | 89 | } |
91 | 90 | ||
92 | getPromociones() { | 91 | getPromociones() { |
93 | const sector = this.articulosPromo[0].CodSec; | 92 | const sector = this.articulosPromo[0].CodSec; |
94 | const codigo = this.articulosPromo[0].CodArt; | 93 | const codigo = this.articulosPromo[0].CodArt; |
95 | this.promocionService.getPromociones(sector, codigo) | 94 | this.promocionService.getPromociones(sector, codigo) |
96 | .subscribe((res: IArticulo[]) => { | 95 | .subscribe((res: IArticulo[]) => { |
97 | this.promociones = res; | 96 | this.promociones = res; |
98 | this.loading = false; | 97 | this.loading = false; |
99 | }, error => { console.error(error); }); | 98 | }, error => { console.error(error); }); |
100 | } | 99 | } |
101 | 100 | ||
102 | @HostListener('document:click', ['$event']) | 101 | @HostListener('document:click', ['$event']) |
103 | eventListener(event: Event) { | 102 | eventListener(event: Event) { |
104 | clearTimeout(this.inactiveScreen.timerReposo); | 103 | clearTimeout(this.inactiveScreen.timerReposo); |
105 | this.inactiveScreen.startTimeOutInactividad(); | 104 | this.inactiveScreen.startTimeOutInactividad(); |
106 | } | 105 | } |
107 | 106 | ||
108 | @HostListener('scroll', ['$event']) | 107 | @HostListener('scroll', ['$event']) |
109 | scrollEvent(event: Event) { | 108 | scrollEvent(event: Event) { |
110 | clearTimeout(this.inactiveScreen.timerReposo); | 109 | clearTimeout(this.inactiveScreen.timerReposo); |
111 | this.inactiveScreen.startTimeOutInactividad(); | 110 | this.inactiveScreen.startTimeOutInactividad(); |
112 | } | 111 | } |
113 | 112 | ||
114 | mediaPantalla() { | 113 | mediaPantalla() { |
115 | if ($('body').hasClass('media-pantalla')) { | 114 | if ($('body').hasClass('media-pantalla')) { |
116 | $('.modal-content').addClass('media-pantalla'); | 115 | $('.modal-content').addClass('media-pantalla'); |
117 | } | 116 | } |
118 | } | 117 | } |
119 | } | 118 | } |
120 | 119 |