Commit 0fa71566656abba8fd22da76a98918d6afea6d3b
Exists in
develop
Merge branch 'master' into 'develop'
Master(benjamin) See merge request !88
Showing
2 changed files
Show diff stats
src/app/shared/promocion/promocion.component.html
1 | <!-- <div class="d-flex justify-content-center" | ||
2 | *ngIf="loading"> | ||
3 | <div class="spinner-border text-primary" role="status"> | ||
4 | <span class="sr-only">Loading...</span> | ||
5 | </div> | ||
6 | </div> --> | ||
7 | <div class="bg-primary rounded"> | 1 | <div class="bg-primary rounded"> |
8 | <div class="modal-header" *ngIf="articulosPromo.length"> | 2 | <div class="modal-header" *ngIf="articulosPromo.length"> |
9 | <img | 3 | <img |
10 | draggable="false" | 4 | draggable="false" |
11 | ondragstart="return false;" | 5 | ondragstart="return false;" |
12 | (contextmenu)="false" | 6 | (contextmenu)="false" |
13 | (click)="selectPromo(articulosPromo[0])" | 7 | (click)="selectPromo(articulosPromo[0])" |
14 | class="btn-effect icon-30 mt-2 mr-2 position-absolute top-0 right-0 z-index" | 8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute top-0 right-0 z-index" |
15 | src="assets/img/icono-cancelar-blanco.svg"> | 9 | src="assets/img/icono-cancelar-blanco.svg"> |
16 | <div class="row w-100 no-gutters justify-content-between"> | 10 | <div class="row w-100 no-gutters justify-content-between"> |
17 | <div class="col align-self-center"> | 11 | <div class="col align-self-center"> |
18 | <p class="h3 text-white">{{articulosPromo[0].DetArt}}</p> | 12 | <p class="h3 text-white">{{articulosPromo[0].DetArt}}</p> |
19 | </div> | 13 | </div> |
20 | <div class="col-auto align-self-center mt-4 pl-2"> | 14 | <div class="col-auto align-self-center mt-4 pl-2"> |
21 | <div | 15 | <div |
22 | class="row mx-0 justify-content-between bg-white badge-pill btn-effect" | 16 | class="row mx-0 justify-content-between bg-white badge-pill btn-effect" |
23 | (click)="selectPromo(articulosPromo[0])"> | 17 | (click)="selectPromo(articulosPromo[0])"> |
24 | <div class="col-auto align-self-center text-primary"> | 18 | <div class="col-auto align-self-center text-primary"> |
25 | <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p> | 19 | <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p> |
26 | </div> | 20 | </div> |
27 | <div class="col-auto px-0"> | 21 | <div class="col-auto px-0"> |
28 | <img | 22 | <img |
29 | draggable="false" | 23 | draggable="false" |
30 | ondragstart="return false;" | 24 | ondragstart="return false;" |
31 | (contextmenu)="false" | 25 | (contextmenu)="false" |
32 | class="d-block ml-auto my-1 icon-20" | 26 | class="d-block ml-auto my-1 icon-20" |
33 | src="assets/img/ir-color.svg"> | 27 | src="assets/img/ir-color.svg"> |
34 | </div> | 28 | </div> |
35 | </div> | 29 | </div> |
36 | </div> | 30 | </div> |
37 | </div> | 31 | </div> |
38 | </div> | 32 | </div> |
39 | <div class="modal-body" *ngIf="articulosPromo.length"> | 33 | <div class="modal-body" *ngIf="articulosPromo.length"> |
40 | <div class="row no-gutters w-100"> | 34 | <div class="row no-gutters w-100"> |
41 | <div class="col-9 col-9 align-self-center"> | 35 | <div class="col-9 col-9 align-self-center"> |
42 | <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> | 36 | <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> |
43 | <p class="h1 text-white">en un combo?</p> | 37 | <p class="h1 text-white">en un combo?</p> |
44 | </div> | 38 | </div> |
45 | <div class="col-3"> | 39 | <div class="col-3"> |
46 | <img | 40 | <img |
47 | draggable="false" | 41 | draggable="false" |
48 | ondragstart="return false;" | 42 | ondragstart="return false;" |
49 | (contextmenu)="false" | 43 | (contextmenu)="false" |
50 | src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" | 44 | src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" |
51 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'" | 45 | onerror="this.src='assets/img/imagen-no-encontrada.jpg'" |
52 | class="card-img-top img-fluid rounded-circle"> | 46 | class="card-img-top img-fluid rounded-circle"> |
53 | </div> | 47 | </div> |
54 | </div> | 48 | </div> |
55 | <div | 49 | <div |
50 | class="d-flex justify-content-center mt-2" | ||
51 | *ngIf="loading"> | ||
52 | <div class="spinner-border text-white" role="status"> | ||
53 | <span class="sr-only">Loading...</span> | ||
54 | </div> | ||
55 | </div> | ||
56 | <div | ||
56 | class="row mt-3 no-gutters lista-promociones scroll-y-visible" | 57 | class="row mt-3 no-gutters lista-promociones scroll-y-visible" |
57 | (scroll)="scrollEvent($event)"> | 58 | (scroll)="scrollEvent($event)"> |
58 | <div class="col-12"> | 59 | <div class="col-12"> |
59 | <div *ngFor="let promo of promociones; let i = index"> | 60 | <div *ngFor="let promo of promociones; let i = index"> |
60 | <div | 61 | <div |
61 | [ngClass]="{ 'mt-2': i !== 0 }" | 62 | [ngClass]="{ 'mt-2': i !== 0 }" |
62 | class="btn-effect bg-white badge-pill text-primary" | 63 | class="btn-effect bg-white badge-pill text-primary" |
63 | (click)="selectPromo(promo)"> | 64 | (click)="selectPromo(promo)"> |
64 | <div class="d-flex"> | 65 | <div class="d-flex"> |
65 | <p class="text-truncate mr-auto my-auto"><small>{{promo.DetArt}}</small></p> | 66 | <p class="text-truncate mr-auto my-auto"><small>{{promo.DetArt}}</small></p> |
66 | <p class="font-weight-bold ml-auto my-auto pr-2"> | 67 | <p class="font-weight-bold ml-auto my-auto pr-2"> |
67 | <span>{{promo.PreVen | currency}}</span> | 68 | <span>{{promo.PreVen | currency}}</span> |
68 | </p> | 69 | </p> |
69 | <img | 70 | <img |
70 | draggable="false" | 71 | draggable="false" |
71 | ondragstart="return false;" | 72 | ondragstart="return false;" |
72 | (contextmenu)="false" | 73 | (contextmenu)="false" |
73 | class="d-block py-1 icon-30" | 74 | class="d-block py-1 icon-30" |
74 | src="assets/img/ir-color.svg"> | 75 | src="assets/img/ir-color.svg"> |
75 | </div> | 76 | </div> |
76 | </div> | 77 | </div> |
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 | 25 | ||
25 | constructor( | 26 | constructor( |
26 | public modalPromocion: BsModalRef, | 27 | public modalPromocion: BsModalRef, |
27 | private modalService: BsModalService, | 28 | private modalService: BsModalService, |
28 | private articuloService: ArticuloService, | 29 | private articuloService: ArticuloService, |
29 | private promocionService: PromocionService, | 30 | private promocionService: PromocionService, |
30 | private sinonimoService: SinonimoService, | 31 | private sinonimoService: SinonimoService, |
31 | private inactiveScreen: InactiveScreenService, | 32 | private inactiveScreen: InactiveScreenService, |
32 | ) { | 33 | ) { |
33 | this.onClose = new Subject(); | 34 | this.onClose = new Subject(); |
34 | } | 35 | } |
35 | 36 | ||
36 | ngOnInit() { | 37 | ngOnInit() { |
37 | this.getPromociones(); | 38 | this.getPromociones(); |
38 | } | 39 | } |
39 | 40 | ||
40 | selectPromo(promo: IArticulo) { | 41 | selectPromo(promo: IArticulo) { |
41 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 42 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
42 | .subscribe((res: ISinonimo[]) => { | 43 | .subscribe((res: ISinonimo[]) => { |
43 | if (res.length) { | 44 | if (res.length) { |
44 | const sinonimos = []; | 45 | const sinonimos = []; |
45 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 46 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
46 | Object.keys(gruposArticulos).forEach(key => { | 47 | Object.keys(gruposArticulos).forEach(key => { |
47 | sinonimos.push({ productos: gruposArticulos[key] }); | 48 | sinonimos.push({ productos: gruposArticulos[key] }); |
48 | }); | 49 | }); |
49 | res = sinonimos; | 50 | res = sinonimos; |
50 | this.openModalSinonimos(res, promo); | 51 | this.openModalSinonimos(res, promo); |
51 | } else { | 52 | } else { |
52 | promo.cantidad = 1; | 53 | promo.cantidad = 1; |
53 | this.articuloService.setArticulo(promo); | 54 | this.articuloService.setArticulo(promo); |
54 | this.modalPromocion.hide(); | 55 | this.modalPromocion.hide(); |
55 | } | 56 | } |
56 | }, err => console.error(err)); | 57 | }, err => console.error(err)); |
57 | this.mediaPantalla(); | 58 | this.mediaPantalla(); |
58 | } | 59 | } |
59 | 60 | ||
60 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 61 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
61 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 62 | const modalSinonimo = this.modalService.show(SinonimoComponent, { |
62 | initialState: { | 63 | initialState: { |
63 | sinonimos: sinonimosData, | 64 | sinonimos: sinonimosData, |
64 | articulo | 65 | articulo |
65 | }, | 66 | }, |
66 | class: 'modal-dialog-centered' | 67 | class: 'modal-dialog-centered' |
67 | }); | 68 | }); |
68 | 69 | ||
69 | modalSinonimo.content.onClose | 70 | modalSinonimo.content.onClose |
70 | .subscribe((res: any) => { | 71 | .subscribe((res: any) => { |
71 | for (const a of articulo.productos) { | 72 | for (const a of articulo.productos) { |
72 | for (const aRes of res.articulos) { | 73 | for (const aRes of res.articulos) { |
73 | if (a.idSinonimo === aRes.ID_SIN) { | 74 | if (a.idSinonimo === aRes.ID_SIN) { |
74 | a.CODA = aRes.CodArt; | 75 | a.CODA = aRes.CodArt; |
75 | a.CodArt = aRes.CodArt; | 76 | a.CodArt = aRes.CodArt; |
76 | a.SECA = aRes.CodSec; | 77 | a.SECA = aRes.CodSec; |
77 | aRes.CodSec = aRes.CodSec; | 78 | aRes.CodSec = aRes.CodSec; |
78 | a.PreVen = aRes.PreVen; | 79 | a.PreVen = aRes.PreVen; |
79 | a.id = aRes.id; | 80 | a.id = aRes.id; |
80 | a.DET_LAR = aRes.DET_LAR; | 81 | a.DET_LAR = aRes.DET_LAR; |
81 | a.DetArt = aRes.DetArt; | 82 | a.DetArt = aRes.DetArt; |
82 | } | 83 | } |
83 | } | 84 | } |
84 | } | 85 | } |
85 | this.articuloService.setArticulo(articulo); | 86 | this.articuloService.setArticulo(articulo); |
86 | this.modalPromocion.hide(); | 87 | this.modalPromocion.hide(); |
87 | }); | 88 | }); |
88 | } | 89 | } |
89 | 90 | ||
90 | getPromociones() { | 91 | getPromociones() { |
91 | const sector = this.articulosPromo[0].CodSec; | 92 | const sector = this.articulosPromo[0].CodSec; |
92 | const codigo = this.articulosPromo[0].CodArt; | 93 | const codigo = this.articulosPromo[0].CodArt; |
93 | this.promocionService.getPromociones(sector, codigo) | 94 | this.promocionService.getPromociones(sector, codigo) |
94 | .subscribe((res: IArticulo[]) => { | 95 | .subscribe((res: IArticulo[]) => { |
95 | this.promociones = res; | 96 | this.promociones = res; |
97 | this.loading = false; | ||
96 | }, error => { console.error(error); }); | 98 | }, error => { console.error(error); }); |
97 | } | 99 | } |
98 | 100 | ||
99 | @HostListener('document:click', ['$event']) | 101 | @HostListener('document:click', ['$event']) |
100 | eventListener(event: Event) { | 102 | eventListener(event: Event) { |
101 | clearTimeout(this.inactiveScreen.timerReposo); | 103 | clearTimeout(this.inactiveScreen.timerReposo); |
102 | this.inactiveScreen.startTimeOutInactividad(); | 104 | this.inactiveScreen.startTimeOutInactividad(); |
103 | } | 105 | } |
104 | 106 | ||
105 | @HostListener('scroll', ['$event']) | 107 | @HostListener('scroll', ['$event']) |
106 | scrollEvent(event: Event) { | 108 | scrollEvent(event: Event) { |
107 | clearTimeout(this.inactiveScreen.timerReposo); | 109 | clearTimeout(this.inactiveScreen.timerReposo); |
108 | this.inactiveScreen.startTimeOutInactividad(); | 110 | this.inactiveScreen.startTimeOutInactividad(); |
109 | } | 111 | } |
110 | 112 | ||
111 | mediaPantalla() { | 113 | mediaPantalla() { |
112 | if ($('body').hasClass('media-pantalla')) { | 114 | if ($('body').hasClass('media-pantalla')) { |
113 | $('.modal-content').addClass('media-pantalla'); | 115 | $('.modal-content').addClass('media-pantalla'); |
114 | } | 116 | } |
115 | } | 117 | } |
116 | } | 118 | } |
117 | 119 |