Commit 7e8c4a1298593178863d8648cd7457a9f04f677f

Authored by Luis Suarez
1 parent 8f572393ef
Exists in develop

Spinner durante carga del modal Promociones

src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
1 import { Component, OnInit, TemplateRef, OnDestroy, HostListener } from '@angular/core'; 1 import { Component, OnInit, TemplateRef, OnDestroy, HostListener } 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 { CategoriaService } from 'src/app/services/categoria/categoria.service'; 7 import { CategoriaService } from 'src/app/services/categoria/categoria.service';
8 import { PromocionService } from 'src/app/services/promocion/promocion.service'; 8 import { PromocionService } from 'src/app/services/promocion/promocion.service';
9 import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; 9 import { PromocionComponent } from 'src/app/shared/promocion/promocion.component';
10 import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; 10 import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service';
11 11
12 @Component({ 12 @Component({
13 selector: 'app-seleccion-articulos', 13 selector: 'app-seleccion-articulos',
14 templateUrl: './seleccion-articulos.component.html', 14 templateUrl: './seleccion-articulos.component.html',
15 styleUrls: ['./seleccion-articulos.component.scss'] 15 styleUrls: ['./seleccion-articulos.component.scss']
16 }) 16 })
17 export class SeleccionArticulosComponent implements OnInit, OnDestroy { 17 export class SeleccionArticulosComponent implements OnInit, OnDestroy {
18 showSpinner = true; 18 showSpinner = true;
19 timeoutHandler: any; 19 timeoutHandler: any;
20 urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; 20 urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`;
21 articulos: IArticulo[] = []; 21 articulos: IArticulo[] = [];
22 auxArticulos: IArticulo[] = []; 22 auxArticulos: IArticulo[] = [];
23 showQuantity = 100; 23 showQuantity = 100;
24 queMostrar = 'todos'; 24 queMostrar = 'todos';
25 categoriaActive = null; 25 categoriaActive = null;
26 categorias: ICategoria[] = []; 26 categorias: ICategoria[] = [];
27 searchTerm = ''; 27 searchTerm = '';
28 ordenandoByVendidos = true; 28 ordenandoByVendidos = true;
29 allActive = true; 29 allActive = true;
30 modalRef: BsModalRef; 30 modalRef: BsModalRef;
31 total = 0; 31 total = 0;
32 modalClass = '';
32 33
33 constructor( 34 constructor(
34 public articuloService: ArticuloService, 35 public articuloService: ArticuloService,
35 private categoriaService: CategoriaService, 36 private categoriaService: CategoriaService,
36 private modalService: BsModalService, 37 private modalService: BsModalService,
37 private inactiveScreen: InactiveScreenService, 38 private inactiveScreen: InactiveScreenService,
38 ) { } 39 ) { }
39 40
40 ngOnInit() { 41 ngOnInit() {
41 this.getCategorias(); 42 this.getCategorias();
42 this.mediaPantalla(); 43 this.mediaPantalla();
43 } 44 }
44 45
45 ngOnDestroy() { 46 ngOnDestroy() {
46 if (this.modalRef) this.modalRef.hide(); 47 if (this.modalRef) this.modalRef.hide();
47 } 48 }
48 49
49 getCategorias() { 50 getCategorias() {
50 this.categoriaService.getAll() 51 this.categoriaService.getAll()
51 .subscribe((categorias: ICategoria[]) => { 52 .subscribe((categorias: ICategoria[]) => {
52 switch (this.queMostrar) { 53 switch (this.queMostrar) {
53 case 'todos': 54 case 'todos':
54 this.categorias = categorias; 55 this.categorias = categorias;
55 this.categoriaActive = 0; 56 this.categoriaActive = 0;
56 break; 57 break;
57 case 'promociones': 58 case 'promociones':
58 this.categorias = categorias; 59 this.categorias = categorias;
59 this.categoriaActive = 19; 60 this.categoriaActive = 19;
60 break; 61 break;
61 case 'ordenar': 62 case 'ordenar':
62 this.categorias = categorias.filter((categoria: ICategoria) => { 63 this.categorias = categorias.filter((categoria: ICategoria) => {
63 return categoria.ES_PEDIDO; 64 return categoria.ES_PEDIDO;
64 }); 65 });
65 this.categoriaActive = 4; 66 this.categoriaActive = 4;
66 break; 67 break;
67 default: 68 default:
68 this.categorias = categorias; 69 this.categorias = categorias;
69 this.categoriaActive = 0; 70 this.categoriaActive = 0;
70 break; 71 break;
71 } 72 }
72 !localStorage.getItem('articulos') ? 73 !localStorage.getItem('articulos') ?
73 this.getProductos() : 74 this.getProductos() :
74 this.setProductos(); 75 this.setProductos();
75 }); 76 });
76 } 77 }
77 78
78 getProductos() { 79 getProductos() {
79 this.articuloService.getAll() 80 this.articuloService.getAll()
80 .subscribe((result: IArticulo[]) => { 81 .subscribe((result: IArticulo[]) => {
81 this.articuloService.setArticulosSinImagen(result); 82 this.articuloService.setArticulosSinImagen(result);
82 if (this.queMostrar === 'ordenar') { 83 if (this.queMostrar === 'ordenar') {
83 this.categorias.forEach((categoria: ICategoria) => { 84 this.categorias.forEach((categoria: ICategoria) => {
84 const tempArticulos = result.filter((articulo: IArticulo) => { 85 const tempArticulos = result.filter((articulo: IArticulo) => {
85 return articulo.categoria_selfservice === categoria.id; 86 return articulo.categoria_selfservice === categoria.id;
86 }); 87 });
87 result = tempArticulos; 88 result = tempArticulos;
88 }); 89 });
89 } 90 }
90 localStorage.setItem('articulos', JSON.stringify(result)); 91 localStorage.setItem('articulos', JSON.stringify(result));
91 this.setProductos(); 92 this.setProductos();
92 }, (error) => { 93 }, (error) => {
93 this.showSpinner = false; 94 this.showSpinner = false;
94 console.error(error); 95 console.error(error);
95 }); 96 });
96 } 97 }
97 98
98 setProductos() { 99 setProductos() {
99 this.articulos = JSON.parse(localStorage.getItem('articulos')); 100 this.articulos = JSON.parse(localStorage.getItem('articulos'));
100 this.filterItems(); 101 this.filterItems();
101 } 102 }
102 103
103 filterItems() { 104 filterItems() {
104 if (this.categoriaActive === 0) { 105 if (this.categoriaActive === 0) {
105 this.auxArticulos = this.articulos; 106 this.auxArticulos = this.articulos;
106 return; 107 return;
107 } 108 }
108 this.auxArticulos = this.articulos.filter(x => { 109 this.auxArticulos = this.articulos.filter(x => {
109 return x.categoria_selfservice === this.categoriaActive; 110 return x.categoria_selfservice === this.categoriaActive;
110 }); 111 });
111 this.ordenar(); 112 this.ordenar();
112 } 113 }
113 114
114 ordenar() { 115 ordenar() {
115 if (this.ordenandoByVendidos) { 116 if (this.ordenandoByVendidos) {
116 this.auxArticulos.sort((a, b) => { 117 this.auxArticulos.sort((a, b) => {
117 return b.cantidadVendida - a.cantidadVendida; 118 return b.cantidadVendida - a.cantidadVendida;
118 }); 119 });
119 } 120 }
120 } 121 }
121 122
122 selectCategoria(index: number, idCategoria?: number) { 123 selectCategoria(index: number, idCategoria?: number) {
123 if (this.categoriaActive === idCategoria) return; 124 if (this.categoriaActive === idCategoria) return;
124 this.categoriaActive = idCategoria; 125 this.categoriaActive = idCategoria;
125 this.allActive = idCategoria === 0 ? true : false; 126 this.allActive = idCategoria === 0 ? true : false;
126 this.categorias.forEach((categoria, i) => { 127 this.categorias.forEach((categoria, i) => {
127 categoria.selected = index === i ? true : false; 128 categoria.selected = index === i ? true : false;
128 }); 129 });
129 this.filterItems(); 130 this.filterItems();
130 } 131 }
131 132
132 elegirArticulo(articulo: IArticulo) { 133 elegirArticulo(articulo: IArticulo) {
133 if (!articulo.FPP) { 134 if (!articulo.FPP) {
134 this.getByID(articulo.id); 135 this.getByID(articulo.id);
135 } else { 136 } else {
136 this.openModalPromos(articulo); 137 this.openModalPromos(articulo);
137 } 138 }
138 } 139 }
139 140
140 getByID(id: number) { 141 getByID(id: number) {
141 this.articuloService.getById(id) 142 this.articuloService.getById(id)
142 .subscribe((res: IArticulo) => { 143 .subscribe((res: IArticulo) => {
143 res.cantidad = 1; 144 res.cantidad = 1;
144 this.articuloService.setArticulo(res); 145 this.articuloService.setArticulo(res);
145 }, err => console.error(err)); 146 }, err => console.error(err));
146 } 147 }
147 148
148 openModalPromos(articulo: IArticulo) { 149 openModalPromos(articulo: IArticulo) {
149 this.modalRef = this.modalService.show(PromocionComponent, 150 this.modalRef = this.modalService.show(PromocionComponent,
150 { 151 {
151 initialState: { 152 initialState: {
152 idArticulo: articulo.id 153 idArticulo: articulo.id
153 }, 154 },
154 class: 'modal-promo modal-dialog-centered' 155 class: 'modal-promo modal-dialog-centered'
155 }); 156 });
156 } 157 }
157 158
158 deleteArticulo(index: number) { 159 deleteArticulo(index: number) {
159 this.articuloService.carrito.splice(index, 1); 160 this.articuloService.carrito.splice(index, 1);
160 this.articuloService.calcularTotal(); 161 this.articuloService.calcularTotal();
161 } 162 }
162 163
163 increaseShow() { 164 increaseShow() {
164 this.showQuantity += 100; 165 this.showQuantity += 100;
165 } 166 }
166 167
167 @HostListener('scroll', ['$event']) 168 @HostListener('scroll', ['$event'])
168 scrollEvent(event: Event) { 169 scrollEvent(event: Event) {
169 clearTimeout(this.inactiveScreen.timerReposo); 170 clearTimeout(this.inactiveScreen.timerReposo);
170 this.inactiveScreen.startTimeOutInactividad(); 171 this.inactiveScreen.startTimeOutInactividad();
171 } 172 }
172 173
173 mouseup() { 174 mouseup() {
174 if (!this.timeoutHandler) return; 175 if (!this.timeoutHandler) return;
175 clearInterval(this.timeoutHandler); 176 clearInterval(this.timeoutHandler);
176 } 177 }
177 178
178 scrollY(el: HTMLElement, value) { 179 scrollY(el: HTMLElement, value) {
179 el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); 180 el.scroll({ behavior: 'smooth', top: value + el.scrollTop });
180 this.timeoutHandler = setInterval(() => { 181 this.timeoutHandler = setInterval(() => {
181 el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); 182 el.scroll({ behavior: 'smooth', top: value + el.scrollTop });
182 }, 500); 183 }, 500);
183 } 184 }
184 185
185 scrollX(el: HTMLElement, value) { 186 scrollX(el: HTMLElement, value) {
186 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); 187 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft });
187 this.timeoutHandler = setInterval(() => { 188 this.timeoutHandler = setInterval(() => {
188 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); 189 el.scroll({ behavior: 'smooth', left: value + el.scrollLeft });
189 }, 500); 190 }, 500);
190 } 191 }
191 192
192 mediaPantalla() { 193 mediaPantalla() {
193 if ($('body').hasClass('media-pantalla')) { 194 if ($('body').hasClass('media-pantalla')) {
194 $('.cat-content,#content,.cat-btn,#boxCarrito,.cat-box,.img-categoria').addClass('media-pantalla').addBack('media-pantalla'); 195 $('.cat-content,#content,.cat-btn,#boxCarrito,.cat-box,.img-categoria').addClass('media-pantalla').addBack('media-pantalla');
195 } 196 }
196 } 197 }
197 } 198 }
198 199
src/app/shared/promocion/promocion.component.html
1 <div class="modal-header bg-primary rounded-top pt-4 px-2"> 1 <div class="d-flex justify-content-center"
2 <div class="row mx-0 w-100 justify-content-between" *ngIf="articulosPromo.length"> 2 *ngIf="!articulosPromo.length" id="loading">
3 <div class="col-8"> 3 <div class="spinner-border text-primary" role="status">
4 <p class="h3 text-white">{{articulosPromo[0].DetArt | uppercase}}</p> 4 <span class="sr-only">Loading...</span>
5 </div>
6 <div class="col-4 align-self-center">
7 <div
8 class="row mx-0 justify-content-between bg-white badge-pill"
9 (click)="elegirPromo(articulosPromo[0])">
10 <div class="col px-0 align-self-center text-primary">
11 <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p>
12 </div>
13 <div class="col-3 px-0">
14 <img
15 draggable="false"
16 ondragstart="return false;"
17 (contextmenu)="false"
18 class="d-block ml-auto py-1 icon-30 mr-2 pt-2"
19 src="assets/img/ir-color.svg">
20 </div>
21 </div>
22 </div>
23 </div> 5 </div>
24 </div> 6 </div>
25 <div class="modal-body bg-primary rounded-bottom pb-3 px-2" *ngIf="articulosPromo.length"> 7 <div *ngIf="articulosPromo.length">
26 <div class="row mx-0 w-100"> 8 <div class="modal-header bg-primary rounded-top pt-4 px-2">
27 <div class="col-9"> 9 <div class="row mx-0 w-100 justify-content-between">
28 <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p> 10 <div class="col-8">
29 <h1 class="text-white mb-4">en un combo?</h1> 11 <p class="h3 text-white">{{articulosPromo[0].DetArt}}</p>
30 </div> 12 </div>
31 <div class="col-3"> 13 <div class="col-4 align-self-center">
32 <img 14 <div
33 draggable="false" 15 class="row mx-0 justify-content-between bg-white badge-pill"
34 ondragstart="return false;" 16 (click)="elegirPromo(articulosPromo[0])">
35 (contextmenu)="false" 17 <div class="col px-0 align-self-center text-primary">
36 src="{{urlImagenes}}{{articulosPromo[0].imagenes[0].imagen}}" 18 <p class="font-weight-bold">{{articulosPromo[0].PreVen | currency}}</p>
37 onerror="this.src='assets/img/image-not-found.jpg'" 19 </div>
38 class="card-img-top img-fluid rounded-circle"> 20 <div class="col-3 px-0">
39 </div>
40 </div>
41 <div
42 class="row mx-0 lista-promociones scroll-y-visible"
43 (scroll)="scrollEvent($event)">
44 <div class="col-12">
45 <div *ngFor="let promo of promociones">
46 <div class="mx-0 mb-2 bg-white badge-pill text-primary" (click)="elegirPromo(promo)">
47 <div class="d-flex">
48 <p class="text-truncate mr-auto my-auto"><small>{{promo.DetArt}}</small></p>
49 <p class="font-weight-bold my-auto pr-2">
50 <span>{{promo.PreVen | currency}}</span>
51 </p>
52 <img 21 <img
53 draggable="false" 22 draggable="false"
54 ondragstart="return false;" 23 ondragstart="return false;"
55 (contextmenu)="false" 24 (contextmenu)="false"
56 class="d-block icon-30 py-1" 25 class="d-block ml-auto py-1 icon-30 mr-2 pt-2"
57 src="assets/img/ir-color.svg"> 26 src="assets/img/ir-color.svg">
58 </div> 27 </div>
59 </div> 28 </div>
60 </div> 29 </div>
61 </div> 30 </div>
62 </div> 31 </div>
63 </div> 32 <div class="modal-body bg-primary rounded-bottom pb-3 px-2">
33 <div class="row mx-0 w-100">
34 <div class="col-9">
35 <p class="text-white"><small>¿TE GUSTARÍA LLEVAR ESTE ARTÍCULO</small></p>
36 <h1 class="text-white mb-4">en un combo?</h1>
37 </div>
38 <div class="col-3">
39 <img
40 draggable="false"
src/app/shared/promocion/promocion.component.scss
1 .lista-promociones { 1 .lista-promociones {
2 min-height: auto; 2 min-height: auto;
3 max-height: 25vh; 3 max-height: 25vh;
4 } 4 }
5
6 .spinner-border {
7 width: 5rem;
8 height: 5rem;
9 }
5 10
1 @import "scss/styles-bootstrap.scss"; 1 @import "scss/styles-bootstrap.scss";
2 @import "scss/typography.scss"; 2 @import "scss/typography.scss";
3 @import "scss/height-width.scss"; 3 @import "scss/height-width.scss";
4 @import "scss/animations.scss"; 4 @import "scss/animations.scss";
5 @import "scss/icons.scss"; 5 @import "scss/icons.scss";
6 @import "scss/scroll.scss"; 6 @import "scss/scroll.scss";
7 @import "node_modules/bootstrap/scss/_variables.scss"; 7 @import "node_modules/bootstrap/scss/_variables.scss";
8 8
9 @font-face { 9 @font-face {
10 font-family: "Gotham"; 10 font-family: "Gotham";
11 font-style: normal; 11 font-style: normal;
12 font-weight: normal; 12 font-weight: normal;
13 src: url("assets/fonts/gotham-medium.woff") format("woff"); 13 src: url("assets/fonts/gotham-medium.woff") format("woff");
14 } 14 }
15 15
16 html, 16 html,
17 body { 17 body {
18 max-height: 100vh; 18 max-height: 100vh;
19 height: 100%; 19 height: 100%;
20 font-family: "Gotham"; 20 font-family: "Gotham";
21 overflow: hidden; 21 overflow: hidden;
22 user-select: none; 22 user-select: none;
23 } 23 }
24 24
25 .btn-effect { 25 .btn-effect {
26 transition: all 0.3s !important; 26 transition: all 0.3s !important;
27 &:hover { 27 &:hover {
28 cursor: pointer !important; 28 cursor: pointer !important;
29 opacity: 0.7 !important; 29 opacity: 0.7 !important;
30 } 30 }
31 &:active { 31 &:active {
32 transform: scale(1.02) !important; 32 transform: scale(1.02) !important;
33 } 33 }
34 } 34 }
35 35
36 .cursor-pointer { 36 .cursor-pointer {
37 cursor: pointer; 37 cursor: pointer;
38 } 38 }
39 39
40 p { 40 p {
41 margin: 0 !important; 41 margin: 0 !important;
42 } 42 }
43 43
44 .img-in-top { 44 .img-in-top {
45 position: absolute; 45 position: absolute;
46 top: -35px; 46 top: -35px;
47 left: 50%; 47 left: 50%;
48 height: 70px; 48 height: 70px;
49 -webkit-transform: translateX(-50%); 49 -webkit-transform: translateX(-50%);
50 transform: translateX(-50%); 50 transform: translateX(-50%);
51 } 51 }
52 52
53 .right-0 { 53 .right-0 {
54 right: 0; 54 right: 0;
55 } 55 }
56 56
57 .left-0 { 57 .left-0 {
58 left: 0; 58 left: 0;
59 } 59 }
60 60
61 .rotate-45 { 61 .rotate-45 {
62 transform: rotate(45deg); 62 transform: rotate(45deg);
63 } 63 }
64 64
65 .rotate-90 { 65 .rotate-90 {
66 transform: rotate(90deg); 66 transform: rotate(90deg);
67 } 67 }
68 68
69 .rotate-90-neg { 69 .rotate-90-neg {
70 transform: rotate(-90deg); 70 transform: rotate(-90deg);
71 } 71 }
72 72
73 .rotate-180-neg { 73 .rotate-180-neg {
74 transform: rotate(-180deg); 74 transform: rotate(-180deg);
75 } 75 }
76 76
77 body.media-pantalla { 77 body.media-pantalla {
78 height: 50% !important; 78 height: 50% !important;
79 position: absolute; 79 position: absolute;
80 bottom: 0; 80 bottom: 0;
81 width: 100%; 81 width: 100%;
82 } 82 }
83 83
84 .modal-content.media-pantalla { 84 .modal-content.media-pantalla {
85 margin-top: auto !important; 85 margin-top: auto !important;
86 margin-bottom: 50px !important; 86 margin-bottom: 50px !important;
87 } 87 }
88
89 .modal-content {
90 background: transparent !important;
91 }
88 92