Commit be7b891885e37a1288a01abe687432e91c09edce
1 parent
14a144eb22
Exists in
master
and in
2 other branches
Agregada funcion para ingresar articulos al carrito
Showing
3 changed files
with
21 additions
and
22 deletions
Show diff stats
src/app/modules/seleccion-articulos/seleccion-articulos.component.html
1 | <div class="h-92 bg-white fade-in-left"> | 1 | <div class="h-92 bg-white fade-in-left"> |
2 | <!-- PUBLICIDADES --> | 2 | <!-- PUBLICIDADES --> |
3 | <app-header-publicidad></app-header-publicidad> | 3 | <app-header-publicidad></app-header-publicidad> |
4 | 4 | ||
5 | <div class="row mx-0 h-90 align-items-end"> | 5 | <div class="row mx-0 h-90 align-items-end"> |
6 | <!-- CABECERA --> | 6 | <!-- CABECERA --> |
7 | <div class="row w-100 mx-3 h-auto border border-primary rounded-sm"> | 7 | <div class="row w-100 mx-3 h-auto border border-primary rounded-sm"> |
8 | <div class="col-12 p-2 align-self-center"> | 8 | <div class="col-12 p-2 align-self-center"> |
9 | <div class="px-3"> | 9 | <div class="px-3"> |
10 | <p class="h6 text-truncate">SELECCIONÁ TÚ COMIDA Y/O BEBIDA</p> | 10 | <p class="h6 text-truncate">SELECCIONÁ TÚ COMIDA Y/O BEBIDA</p> |
11 | </div> | 11 | </div> |
12 | </div> | 12 | </div> |
13 | </div> | 13 | </div> |
14 | <!-- CUERPO --> | 14 | <!-- CUERPO --> |
15 | <div class="row w-100 mr-4 h-70"> | 15 | <div class="row w-100 mr-4 h-70"> |
16 | <div class="col-12 h-100 px-0 py-3"> | 16 | <div class="col-12 h-100 px-0 py-3"> |
17 | <div class="row mx-0 h-100"> | 17 | <div class="row mx-0 h-100"> |
18 | <!-- FILTRO CATEGORIAS --> | 18 | <!-- FILTRO CATEGORIAS --> |
19 | <div class="col-5 col-sm-3 col-xl-2 h-100"> | 19 | <div class="col-5 col-sm-3 col-xl-2 h-100"> |
20 | <p class="h6 h-6 m-0 text-center"><small>CATEGORÍAS</small></p> | 20 | <p class="h6 h-6 m-0 text-center"><small>CATEGORÍAS</small></p> |
21 | <div class="row mx-0 h-94 justify-content-center align-items-center"> | 21 | <div class="row mx-0 h-94 justify-content-center align-items-center"> |
22 | <div class="col-auto btn-effect h-5"> | 22 | <div class="col-auto btn-effect h-5"> |
23 | <img | 23 | <img |
24 | draggable="false" | 24 | draggable="false" |
25 | ondragstart="return false;" | 25 | ondragstart="return false;" |
26 | (contextmenu)="false" | 26 | (contextmenu)="false" |
27 | class="h-100 d-block mx-auto rotate-90-neg" | 27 | class="h-100 d-block mx-auto rotate-90-neg" |
28 | src="assets/img/ir-color.svg" | 28 | src="assets/img/ir-color.svg" |
29 | (mousedown)="scrollY(templateCategorias, -100)" | 29 | (mousedown)="scrollY(templateCategorias, -100)" |
30 | (mouseup)="mouseup()" | 30 | (mouseup)="mouseup()" |
31 | (mouseleave)="mouseup()"> | 31 | (mouseleave)="mouseup()"> |
32 | </div> | 32 | </div> |
33 | <!-- CATEGORIAS --> | 33 | <!-- CATEGORIAS --> |
34 | <div | 34 | <div |
35 | #templateCategorias | 35 | #templateCategorias |
36 | class="col-12 px-0 box-categorias border border-primary border-left-0 rounded-right scroll-y"> | 36 | class="col-12 px-0 box-categorias border border-primary border-left-0 rounded-right scroll-y"> |
37 | <div | 37 | <div |
38 | class="row mx-4 mb-2 h-32 justify-content-center tab" | 38 | class="row mx-4 mb-2 h-32 justify-content-center tab" |
39 | [ngClass]="{ 'active': allActive, 'border-bottom-effect': !allActive }" | 39 | [ngClass]="{ 'active': allActive, 'border-bottom-effect': !allActive }" |
40 | (click)="selectCategoria(-1, 0)"> | 40 | (click)="selectCategoria(-1, 0)"> |
41 | <img | 41 | <img |
42 | draggable="false" | 42 | draggable="false" |
43 | ondragstart="return false;" | 43 | ondragstart="return false;" |
44 | (contextmenu)="false" | 44 | (contextmenu)="false" |
45 | class="col-12 h-50 align-self-end d-none d-sm-block rounded-circle" | 45 | class="col-12 h-50 align-self-end d-none d-sm-block rounded-circle" |
46 | src="assets/img/ir-color.svg"> | 46 | src="assets/img/ir-color.svg"> |
47 | <small class="col-12 px-0 my-1 h-25 align-self-end text-center text-truncate">Todos</small> | 47 | <small class="col-12 px-0 my-1 h-25 align-self-end text-center text-truncate">Todos</small> |
48 | </div> | 48 | </div> |
49 | <div | 49 | <div |
50 | class="row mx-4 mb-2 h-32 justify-content-center tab" | 50 | class="row mx-4 mb-2 h-32 justify-content-center tab" |
51 | [ngClass]="{ 'active': categoria.selected, 'border-bottom-effect': !categoria.selected }" | 51 | [ngClass]="{ 'active': categoria.selected, 'border-bottom-effect': !categoria.selected }" |
52 | (click)="selectCategoria(i, categoria.id)" | 52 | (click)="selectCategoria(i, categoria.id)" |
53 | *ngFor="let categoria of categorias; let i = index;"> | 53 | *ngFor="let categoria of categorias; let i = index;"> |
54 | <img | 54 | <img |
55 | draggable="false" | 55 | draggable="false" |
56 | ondragstart="return false;" | 56 | ondragstart="return false;" |
57 | (contextmenu)="false" | 57 | (contextmenu)="false" |
58 | class="col-12 h-50 align-self-end d-none d-sm-block rounded-circle" | 58 | class="col-12 h-50 align-self-end d-none d-sm-block rounded-circle" |
59 | src="assets/img/ir-color.svg"> | 59 | src="assets/img/ir-color.svg"> |
60 | <small class="col-12 px-0 my-1 h-25 align-self-end text-center text-truncate">{{categoria.detalle}}</small> | 60 | <small class="col-12 px-0 my-1 h-25 align-self-end text-center text-truncate">{{categoria.detalle}}</small> |
61 | </div> | 61 | </div> |
62 | </div> | 62 | </div> |
63 | <div class="col-auto btn-effect h-5"> | 63 | <div class="col-auto btn-effect h-5"> |
64 | <img | 64 | <img |
65 | draggable="false" | 65 | draggable="false" |
66 | ondragstart="return false;" | 66 | ondragstart="return false;" |
67 | (contextmenu)="false" | 67 | (contextmenu)="false" |
68 | class="h-100 d-block mx-auto rotate-90" | 68 | class="h-100 d-block mx-auto rotate-90" |
69 | src="assets/img/ir-color.svg" | 69 | src="assets/img/ir-color.svg" |
70 | (mousedown)="scrollY(templateCategorias, 100)" | 70 | (mousedown)="scrollY(templateCategorias, 100)" |
71 | (mouseup)="mouseup()" | 71 | (mouseup)="mouseup()" |
72 | (mouseleave)="mouseup()"> | 72 | (mouseleave)="mouseup()"> |
73 | </div> | 73 | </div> |
74 | </div> | 74 | </div> |
75 | </div> | 75 | </div> |
76 | <!-- LISTA DE ARTICULOS --> | 76 | <!-- LISTA DE ARTICULOS --> |
77 | <div class="col-7 col-sm-9 col-xl-10 pb-3 h-80 align-self-center scroll-y"> | 77 | <div class="col-7 col-sm-9 col-xl-10 pb-3 h-80 align-self-center scroll-y"> |
78 | <div class="row row-cols-1 row-cols-sm-3 row-cols-xl-6"> | 78 | <div class="row row-cols-1 row-cols-sm-3 row-cols-xl-6"> |
79 | <!-- ARTICULO --> | 79 | <!-- ARTICULO --> |
80 | <div | 80 | <div |
81 | class="col px-2 my-1 my-md-3 h-auto" | 81 | class="col px-2 my-1 my-md-3 h-auto" |
82 | *ngFor="let articulo of auxArticulos | slice:0:showQuantity;"> | 82 | *ngFor="let articulo of auxArticulos | slice:0:showQuantity;"> |
83 | <div class="swing-in-top-fwd card h-auto"> | 83 | <div class="swing-in-top-fwd card h-auto"> |
84 | <img | 84 | <img |
85 | draggable="false" | 85 | draggable="false" |
86 | ondragstart="return false;" | 86 | ondragstart="return false;" |
87 | (contextmenu)="false" | 87 | (contextmenu)="false" |
88 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" | 88 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" |
89 | class="card-img-top h-55 shadow-sm rounded-sm"> | 89 | class="card-img-top h-55 shadow-sm rounded-sm"> |
90 | <div class="row mx-0 py-1 h-auto justify-content-center"> | 90 | <div class="row mx-0 py-1 h-auto justify-content-center"> |
91 | <p class="col-12 px-1 h6 h-auto text-primary text-center">{{articulo.DetArt}}</p> | 91 | <p class="col-12 px-1 h6 h-auto text-primary text-center">{{articulo.DetArt}}</p> |
92 | <p class="col-12 px-1 h-auto text-center line-height-sm"> | 92 | <p class="col-12 px-1 h-auto text-center line-height-sm"> |
93 | <small>{{articulo.DET_LAR}}</small> | 93 | <small>{{articulo.DET_LAR}}</small> |
94 | </p> | 94 | </p> |
95 | <div class="col-12 px-1 align-self-end btn-effect h-auto"> | 95 | <div class="col-12 px-1 align-self-end btn-effect h-auto"> |
96 | <div | 96 | <div |
97 | [ngClass]="{'bg-secondary': articulo.promo}" | 97 | [ngClass]="{'bg-secondary': articulo.promo}" |
98 | class="row mx-0 justify-content-between bg-primary badge-pill" | 98 | class="row mx-0 justify-content-between bg-primary badge-pill" |
99 | (click)="elegirArticulo(articulo)"> | 99 | (click)="elegirArticulo(articulo)"> |
100 | <div class="col px-0 align-self-center text-white text-right"> | 100 | <div class="col px-0 align-self-center text-white text-right"> |
101 | {{articulo.PreVen | currency}} | 101 | {{articulo.PreVen | currency}} |
102 | </div> | 102 | </div> |
103 | <div class="col-5 px-0"> | 103 | <div class="col-5 px-0"> |
104 | <img | 104 | <img |
105 | draggable="false" | 105 | draggable="false" |
106 | ondragstart="return false;" | 106 | ondragstart="return false;" |
107 | (contextmenu)="false" | 107 | (contextmenu)="false" |
108 | class="d-block ml-auto py-1 icon-30" | 108 | class="d-block ml-auto py-1 icon-30" |
109 | src="assets/img/ir.svg"> | 109 | src="assets/img/ir.svg"> |
110 | </div> | 110 | </div> |
111 | </div> | 111 | </div> |
112 | </div> | 112 | </div> |
113 | </div> | 113 | </div> |
114 | </div> | 114 | </div> |
115 | </div> | 115 | </div> |
116 | </div> | 116 | </div> |
117 | <!-- BOTON VER MAS --> | 117 | <!-- BOTON VER MAS --> |
118 | <div class="row mx-0"> | 118 | <div class="row mx-0"> |
119 | <div | 119 | <div |
120 | *ngIf="showQuantity <= auxArticulos.slice(0, showQuantity).length" | 120 | *ngIf="showQuantity <= auxArticulos.slice(0, showQuantity).length" |
121 | class="col-12 px-0 mb-2"> | 121 | class="col-12 px-0 mb-2"> |
122 | <button | 122 | <button |
123 | (click)="increaseShow()" | 123 | (click)="increaseShow()" |
124 | class="btn btn-block btn-outline-primary"> | 124 | class="btn btn-block btn-outline-primary"> |
125 | Ver Más | 125 | Ver Más |
126 | </button> | 126 | </button> |
127 | </div> | 127 | </div> |
128 | </div> | 128 | </div> |
129 | </div> | 129 | </div> |
130 | </div> | 130 | </div> |
131 | </div> | 131 | </div> |
132 | </div> | 132 | </div> |
133 | <!-- FOOTER CARRITO DE COMPRAS --> | 133 | <!-- FOOTER CARRITO DE COMPRAS --> |
134 | <div class="row w-90 mx-auto h-auto justify-content-center"> | 134 | <div class="row w-90 mx-auto h-auto justify-content-center"> |
135 | <div class="col-12 h-75 px-0 border border-primary rounded"> | 135 | <div class="col-12 h-75 px-0 border border-primary rounded"> |
136 | <div class="row mx-0 h-15 border-bottom border-primary"> | 136 | <div class="row mx-0 h-15 border-bottom border-primary"> |
137 | <p class="col align-self-center text-truncate"><small>ARTÍCULOS EN TÚ CARRITO DE COMPRAS</small></p> | 137 | <p class="col align-self-center text-truncate"><small>ARTÍCULOS EN TÚ CARRITO DE COMPRAS</small></p> |
138 | </div> | 138 | </div> |
139 | <div class="row h-85 mx-0 justify-content-between"> | 139 | <div class="row h-85 mx-0 justify-content-between"> |
140 | <div class="col-auto btn-effect h-20 align-self-center"> | 140 | <div class="col-auto btn-effect h-20 align-self-center"> |
141 | <img | 141 | <img |
142 | draggable="false" | 142 | draggable="false" |
143 | ondragstart="return false;" | 143 | ondragstart="return false;" |
144 | (contextmenu)="false" | 144 | (contextmenu)="false" |
145 | class="icon-30 rotate-180-neg" | 145 | class="icon-30 rotate-180-neg" |
146 | src="assets/img/ir-fondo-color.svg" | 146 | src="assets/img/ir-fondo-color.svg" |
147 | (mousedown)="scrollX(templateCarrito, -100)" | 147 | (mousedown)="scrollX(templateCarrito, -100)" |
148 | (mouseup)="mouseup()" | 148 | (mouseup)="mouseup()" |
149 | (mouseleave)="mouseup()"> | 149 | (mouseleave)="mouseup()"> |
150 | </div> | 150 | </div> |
151 | <div class="col-6 col-sm-8 col-md-9 col-lg-10 h-100"> | 151 | <div class="col-6 col-sm-8 col-md-9 col-lg-10 h-100"> |
152 | <div #templateCarrito class="row flex-row flex-nowrap h-100 mx-0 scroll-x"> | 152 | <div #templateCarrito class="row flex-row flex-nowrap h-100 mx-0 scroll-x"> |
153 | <div *ngIf="!articuloService.carrito.length" class="col h-100"> | ||
154 | <p>No hay articulos en el carrito</p> | ||
155 | </div> | ||
153 | <div | 156 | <div |
154 | class="col-10 col-sm-4 col-lg-2 col-xl-auto px-2 px-xl-4 my-2 h-100 align-self-center border-right border-primary" | 157 | class="col-10 col-sm-4 col-lg-2 px-2 px-xl-4 my-2 h-100 align-self-center border-right border-primary swing-in-top-fwd" |
155 | (click)="selectCategoria(i)" | 158 | *ngFor="let articulo of articuloService.carrito; let i = index;"> |
156 | *ngFor="let categoria of [{},{},{},{},{},{},{},{},{},{},{},{},{},{}]; let i = index;"> | ||
157 | <img | 159 | <img |
158 | draggable="false" | 160 | draggable="false" |
159 | ondragstart="return false;" | 161 | ondragstart="return false;" |
160 | (contextmenu)="false" | 162 | (contextmenu)="false" |
161 | class="d-block h-55 p-2 mx-auto" | 163 | class="d-block h-55 img-fluid p-2 mx-auto" |
162 | src="assets/img/ir-color.svg"> | 164 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}"> |
163 | <p class="d-block mt-auto text-center text-primary"><small>{{'articulo'}}</small></p> | 165 | <p class="d-block mt-auto text-center text-primary text-truncate"> |
166 | <small>{{articulo.DetArt}}</small> | ||
167 | </p> | ||
164 | </div> | 168 | </div> |
165 | </div> | 169 | </div> |
166 | </div> | 170 | </div> |
167 | <div class="col-auto btn-effect h-20 align-self-center"> | 171 | <div class="col-auto btn-effect h-20 align-self-center"> |
168 | <img | 172 | <img |
169 | draggable="false" | 173 | draggable="false" |
170 | ondragstart="return false;" | 174 | ondragstart="return false;" |
171 | (contextmenu)="false" | 175 | (contextmenu)="false" |
172 | class="icon-30" | 176 | class="icon-30" |
173 | src="assets/img/ir-fondo-color.svg" | 177 | src="assets/img/ir-fondo-color.svg" |
174 | (mousedown)="scrollX(templateCarrito, 100)" | 178 | (mousedown)="scrollX(templateCarrito, 100)" |
175 | (mouseup)="mouseup()" | 179 | (mouseup)="mouseup()" |
176 | (mouseleave)="mouseup()"> | 180 | (mouseleave)="mouseup()"> |
177 | </div> | 181 | </div> |
178 | </div> | 182 | </div> |
179 | </div> | 183 | </div> |
180 | <div class="col-auto p-0 mt-2 ml-auto h-20"> | 184 | <div class="col-auto p-0 mt-2 ml-auto h-20"> |
181 | <div | 185 | <div |
182 | class="btn-effect col-auto align-self-center px-0 bg-white" | 186 | class="btn-effect col-auto align-self-center px-0 bg-white" |
183 | [routerLink]="['/carrito']"> | 187 | [routerLink]="['/carrito']"> |
184 | <div class="row mx-0 bg-light"> | 188 | <div class="row mx-0 bg-light"> |
185 | <div class="col-auto align-self-center text-primary">VER CARRITO</div> | 189 | <div class="col-auto align-self-center text-primary">VER CARRITO</div> |
186 | <div class="col-auto p-0 bg-primary d-none d-sm-block"> | 190 | <div class="col-auto p-0 bg-primary d-none d-sm-block"> |
187 | <img | 191 | <img |
188 | draggable="false" | 192 | draggable="false" |
189 | ondragstart="return false;" | 193 | ondragstart="return false;" |
190 | (contextmenu)="false" | 194 | (contextmenu)="false" |
191 | class="p-2 icon-40" | 195 | class="p-2 icon-40" |
192 | src="assets/img/carrito.svg"> | 196 | src="assets/img/carrito.svg"> |
193 | </div> | 197 | </div> |
194 | </div> | 198 | </div> |
195 | </div> | 199 | </div> |
196 | </div> | 200 | </div> |
197 | </div> | 201 | </div> |
198 | </div> | 202 | </div> |
199 | 203 | ||
200 | </div> | 204 | </div> |
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
1 | import { Component, OnInit } from "@angular/core"; | 1 | import { Component, OnInit } from "@angular/core"; |
2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
3 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; | 3 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; |
4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
6 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 6 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
7 | import { ICategoria } from 'src/app/interfaces/ICategoria'; | 7 | import { ICategoria } from 'src/app/interfaces/ICategoria'; |
8 | 8 | ||
9 | @Component({ | 9 | @Component({ |
10 | selector: "app-seleccion-articulos", | 10 | selector: "app-seleccion-articulos", |
11 | templateUrl: "./seleccion-articulos.component.html", | 11 | templateUrl: "./seleccion-articulos.component.html", |
12 | styleUrls: ["./seleccion-articulos.component.scss"] | 12 | styleUrls: ["./seleccion-articulos.component.scss"] |
13 | }) | 13 | }) |
14 | export class SeleccionArticulosComponent implements OnInit { | 14 | export class SeleccionArticulosComponent implements OnInit { |
15 | showSpinner = true; | 15 | showSpinner = true; |
16 | timeoutHandler: any; | 16 | timeoutHandler: any; |
17 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 17 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
18 | articulos: IArticulo[] = []; | 18 | articulos: IArticulo[] = []; |
19 | auxArticulos: IArticulo[] = []; | 19 | auxArticulos: IArticulo[] = []; |
20 | showQuantity = 100; | 20 | showQuantity = 100; |
21 | queMostrar = 'todos'; | 21 | queMostrar = 'todos'; |
22 | categoriaActive: number = null; | 22 | categoriaActive: number = null; |
23 | categorias: ICategoria[] = []; | 23 | categorias: ICategoria[] = []; |
24 | searchTerm = ''; | 24 | searchTerm = ''; |
25 | ordenandoByVendidos = true; | 25 | ordenandoByVendidos = true; |
26 | allActive = true; | 26 | allActive = true; |
27 | modalRef: BsModalRef; | 27 | modalRef: BsModalRef; |
28 | 28 | ||
29 | constructor( | 29 | constructor( |
30 | private modalService: BsModalService, | 30 | private modalService: BsModalService, |
31 | private articuloService: ArticuloService, | 31 | private articuloService: ArticuloService, |
32 | ) { } | 32 | ) { } |
33 | 33 | ||
34 | ngOnInit() { | 34 | ngOnInit() { |
35 | this.getCategorias(); | 35 | this.getCategorias(); |
36 | this.articuloService.getAll() | 36 | this.articuloService.getAll() |
37 | .subscribe((res: IArticulo[]) => { | 37 | .subscribe((res: IArticulo[]) => { |
38 | this.articuloService.setArticulosSinImagen(res); | 38 | this.articuloService.setArticulosSinImagen(res); |
39 | localStorage.setItem('articulos', JSON.stringify(res)); | 39 | localStorage.setItem('articulos', JSON.stringify(res)); |
40 | this.setProductos(); | 40 | this.setProductos(); |
41 | this.articulos = res; | 41 | this.articulos = res; |
42 | }, err => console.error(err)); | 42 | }, err => console.error(err)); |
43 | } | 43 | } |
44 | 44 | ||
45 | getCategorias() { | 45 | getCategorias() { |
46 | this.articuloService.getCategorias() | 46 | this.articuloService.getCategorias() |
47 | .subscribe((categorias: ICategoria[]) => { | 47 | .subscribe((categorias: ICategoria[]) => { |
48 | switch (this.queMostrar) { | 48 | switch (this.queMostrar) { |
49 | case 'todos': | 49 | case 'todos': |
50 | this.categorias = categorias; | 50 | this.categorias = categorias; |
51 | this.categoriaActive = 0; | 51 | this.categoriaActive = 0; |
52 | break; | 52 | break; |
53 | case 'promociones': | 53 | case 'promociones': |
54 | this.categorias = categorias; | 54 | this.categorias = categorias; |
55 | this.categoriaActive = 19; | 55 | this.categoriaActive = 19; |
56 | break; | 56 | break; |
57 | case 'ordenar': | 57 | case 'ordenar': |
58 | this.categorias = categorias.filter((categoria: ICategoria) => { | 58 | this.categorias = categorias.filter((categoria: ICategoria) => { |
59 | return categoria.ES_PEDIDO; | 59 | return categoria.ES_PEDIDO; |
60 | }); | 60 | }); |
61 | this.categoriaActive = 4; | 61 | this.categoriaActive = 4; |
62 | break; | 62 | break; |
63 | default: | 63 | default: |
64 | this.categorias = categorias; | 64 | this.categorias = categorias; |
65 | this.categoriaActive = 0; | 65 | this.categoriaActive = 0; |
66 | break; | 66 | break; |
67 | } | 67 | } |
68 | !localStorage.getItem('articulos') ? | 68 | !localStorage.getItem('articulos') ? |
69 | this.getProductos() : | 69 | this.getProductos() : |
70 | this.setProductos(); | 70 | this.setProductos(); |
71 | }); | 71 | }); |
72 | } | 72 | } |
73 | 73 | ||
74 | getProductos() { | 74 | getProductos() { |
75 | this.articuloService.getAll() | 75 | this.articuloService.getAll() |
76 | .subscribe((result: IArticulo[]) => { | 76 | .subscribe((result: IArticulo[]) => { |
77 | this.articuloService.setArticulosSinImagen(result); | 77 | this.articuloService.setArticulosSinImagen(result); |
78 | if (this.queMostrar == 'ordenar') { | 78 | if (this.queMostrar == 'ordenar') { |
79 | this.categorias.forEach((categoria: ICategoria) => { | 79 | this.categorias.forEach((categoria: ICategoria) => { |
80 | let tempArticulos = result.filter((articulo: IArticulo) => { | 80 | let tempArticulos = result.filter((articulo: IArticulo) => { |
81 | return articulo.categoria_selfservice == categoria.id; | 81 | return articulo.categoria_selfservice == categoria.id; |
82 | }); | 82 | }); |
83 | result = tempArticulos; | 83 | result = tempArticulos; |
84 | }); | 84 | }); |
85 | } | 85 | } |
86 | localStorage.setItem('articulos', JSON.stringify(result)); | 86 | localStorage.setItem('articulos', JSON.stringify(result)); |
87 | this.setProductos(); | 87 | this.setProductos(); |
88 | }, (error) => { | 88 | }, (error) => { |
89 | this.showSpinner = false; | 89 | this.showSpinner = false; |
90 | console.error(error); | 90 | console.error(error); |
91 | }); | 91 | }); |
92 | } | 92 | } |
93 | 93 | ||
94 | setProductos() { | 94 | setProductos() { |
95 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 95 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
96 | this.filterItems(); | 96 | this.filterItems(); |
97 | } | 97 | } |
98 | 98 | ||
99 | filterItems() { | 99 | filterItems() { |
100 | if (this.categoriaActive == 0) { | 100 | if (this.categoriaActive == 0) { |
101 | this.auxArticulos = this.articulos; | 101 | this.auxArticulos = this.articulos; |
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | this.auxArticulos = this.articulos.filter(x => { | 104 | this.auxArticulos = this.articulos.filter(x => { |
105 | return x.categoria_selfservice === this.categoriaActive; | 105 | return x.categoria_selfservice === this.categoriaActive; |
106 | }); | 106 | }); |
107 | this.ordenar(); | 107 | this.ordenar(); |
108 | } | 108 | } |
109 | 109 | ||
110 | ordenar() { | 110 | ordenar() { |
111 | if (this.ordenandoByVendidos) { | 111 | if (this.ordenandoByVendidos) { |
112 | this.auxArticulos.sort((a, b) => { | 112 | this.auxArticulos.sort((a, b) => { |
113 | return b.cantidadVendida - a.cantidadVendida; | 113 | return b.cantidadVendida - a.cantidadVendida; |
114 | }); | 114 | }); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | selectCategoria(index: number, idCategoria?: number) { | 118 | selectCategoria(index: number, idCategoria?: number) { |
119 | if (this.categoriaActive == idCategoria) return; | 119 | if (this.categoriaActive == idCategoria) return; |
120 | this.categoriaActive = idCategoria; | 120 | this.categoriaActive = idCategoria; |
121 | this.allActive = idCategoria === 0 ? true : false; | 121 | this.allActive = idCategoria === 0 ? true : false; |
122 | this.categorias.forEach((categoria, i) => { | 122 | this.categorias.forEach((categoria, i) => { |
123 | categoria.selected = index === i ? true : false; | 123 | categoria.selected = index === i ? true : false; |
124 | }); | 124 | }); |
125 | this.filterItems(); | 125 | this.filterItems(); |
126 | } | 126 | } |
127 | 127 | ||
128 | elegirArticulo(articulo: any) { | 128 | elegirArticulo(articulo: IArticulo) { |
129 | if (articulo.promo) { | 129 | this.articuloService.setArticulo(articulo); |
130 | this.modalRef = this.modalService.show(PromocionComponent, { | ||
131 | class: 'custom-modal modal-dialog-centered', | ||
132 | ignoreBackdropClick: true, | ||
133 | }) | ||
134 | } | ||
135 | } | 130 | } |
136 | 131 | ||
137 | increaseShow() { | 132 | increaseShow() { |
138 | this.showQuantity += 100; | 133 | this.showQuantity += 100; |
139 | } | 134 | } |
140 | 135 | ||
141 | mouseup() { | 136 | mouseup() { |
142 | if (!this.timeoutHandler) return; | 137 | if (!this.timeoutHandler) return; |
143 | clearInterval(this.timeoutHandler); | 138 | clearInterval(this.timeoutHandler); |
144 | } | 139 | } |
145 | 140 | ||
146 | scrollY(el: HTMLElement, value) { | 141 | scrollY(el: HTMLElement, value) { |
147 | el.scroll({ behavior: "smooth", top: value + el.scrollTop }); | 142 | el.scroll({ behavior: "smooth", top: value + el.scrollTop }); |
148 | this.timeoutHandler = setInterval(() => { | 143 | this.timeoutHandler = setInterval(() => { |
149 | el.scroll({ behavior: "smooth", top: value + el.scrollTop }); | 144 | el.scroll({ behavior: "smooth", top: value + el.scrollTop }); |
150 | }, 500); | 145 | }, 500); |
151 | } | 146 | } |
152 | 147 | ||
153 | scrollX(el: HTMLElement, value) { | 148 | scrollX(el: HTMLElement, value) { |
154 | el.scroll({ behavior: "smooth", left: value + el.scrollLeft }); | 149 | el.scroll({ behavior: "smooth", left: value + el.scrollLeft }); |
155 | this.timeoutHandler = setInterval(() => { | 150 | this.timeoutHandler = setInterval(() => { |
156 | el.scroll({ behavior: "smooth", left: value + el.scrollLeft }); | 151 | el.scroll({ behavior: "smooth", left: value + el.scrollLeft }); |
157 | }, 500); | 152 | }, 500); |
158 | } | 153 | } |
159 | } | 154 | } |
160 | 155 |
src/app/services/articulo/articulo.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { APP_SETTINGS } from '../../../etc/AppSettings'; | 3 | import { APP_SETTINGS } from '../../../etc/AppSettings'; |
4 | import { IArticulo } from '../../interfaces/IArticulo'; | 4 | import { IArticulo } from '../../interfaces/IArticulo'; |
5 | import { ClienteService } from '../cliente/cliente.service'; | 5 | import { ClienteService } from '../cliente/cliente.service'; |
6 | import { Observable } from 'rxjs'; | 6 | import { Observable } from 'rxjs'; |
7 | 7 | ||
8 | @Injectable({ | 8 | @Injectable({ |
9 | providedIn: 'root' | 9 | providedIn: 'root' |
10 | }) | 10 | }) |
11 | export class ArticuloService { | 11 | export class ArticuloService { |
12 | articulos: IArticulo[] = []; | 12 | carrito: IArticulo[] = []; |
13 | articuloAcargar: IArticulo; | 13 | articuloAcargar: IArticulo; |
14 | promoAcargar: IArticulo; | 14 | promoAcargar: IArticulo; |
15 | mostrar: string; | 15 | mostrar: string; |
16 | esPromoPersonalizada: boolean = false; | 16 | esPromoPersonalizada: boolean = false; |
17 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; | 17 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; |
18 | 18 | ||
19 | constructor( | 19 | constructor( |
20 | private http: HttpClient, | 20 | private http: HttpClient, |
21 | private clienteService: ClienteService, | 21 | private clienteService: ClienteService, |
22 | ) { } | 22 | ) { } |
23 | 23 | ||
24 | getById(id) { | 24 | getById(id) { |
25 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); | 25 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); |
26 | } | 26 | } |
27 | 27 | ||
28 | getAll() { | 28 | getAll() { |
29 | return this.http.get(`${this.urlDeboSuite}/articulos/`); | 29 | return this.http.get(`${this.urlDeboSuite}/articulos/`); |
30 | } | 30 | } |
31 | 31 | ||
32 | getAllWithPaginator(page: number = 1) { | 32 | getAllWithPaginator(page: number = 1) { |
33 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); | 33 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); |
34 | } | 34 | } |
35 | 35 | ||
36 | setArticulos(articulo: IArticulo) { | 36 | setArticulo(articulo: IArticulo) { |
37 | for (let i = 0; i < this.articulos.length; i++) { | 37 | for (let i = 0; i < this.carrito.length; i++) { |
38 | if (this.articulos[i].id === articulo.id) { | 38 | if (this.carrito[i].id === articulo.id) { |
39 | if (articulo.PRO) break; | 39 | if (articulo.PRO) break; |
40 | this.articulos[i].cantidad++; | 40 | this.carrito[i].cantidad++; |
41 | return; | 41 | return; |
42 | } | 42 | } |
43 | } | 43 | } |
44 | this.articulos.unshift(articulo); | 44 | this.carrito.unshift(articulo); |
45 | } | 45 | } |
46 | 46 | ||
47 | getPromocionByCodigos(sector, codigo) { | 47 | getPromocionByCodigos(sector, codigo) { |
48 | return this.http.get(`${this.urlDeboSuite}/promociones/by-codigos/${sector}/${codigo}`); | 48 | return this.http.get(`${this.urlDeboSuite}/promociones/by-codigos/${sector}/${codigo}`); |
49 | } | 49 | } |
50 | 50 | ||
51 | getPromociones(sector, codigo) { | 51 | getPromociones(sector, codigo) { |
52 | return this.http.get(`${this.urlDeboSuite}/promociones/in-articulo/${sector}/${codigo}`); | 52 | return this.http.get(`${this.urlDeboSuite}/promociones/in-articulo/${sector}/${codigo}`); |
53 | } | 53 | } |
54 | 54 | ||
55 | getPromocionSinonimos(sector, codigo) { | 55 | getPromocionSinonimos(sector, codigo) { |
56 | return this.http.get(`${this.urlDeboSuite}/sinonimos/promo/${sector}/${codigo}`); | 56 | return this.http.get(`${this.urlDeboSuite}/sinonimos/promo/${sector}/${codigo}`); |
57 | } | 57 | } |
58 | 58 | ||
59 | getCategorias() { | 59 | getCategorias() { |
60 | return this.http.get(`${this.urlDeboSuite}/categorias`); | 60 | return this.http.get(`${this.urlDeboSuite}/categorias`); |
61 | } | 61 | } |
62 | 62 | ||
63 | getComponentes(sector, codigo) { | 63 | getComponentes(sector, codigo) { |
64 | return this.http.get(`${this.urlDeboSuite}/promociones/articulos/${sector}/${codigo}`); | 64 | return this.http.get(`${this.urlDeboSuite}/promociones/articulos/${sector}/${codigo}`); |
65 | } | 65 | } |
66 | 66 | ||
67 | pay(dataPago: any) { | 67 | pay(dataPago: any) { |
68 | return new Observable((observer) => { | 68 | return new Observable((observer) => { |
69 | this.clienteService.getById(-1) | 69 | this.clienteService.getById(-1) |
70 | .subscribe(cliente => { | 70 | .subscribe(cliente => { |
71 | let puntoVenta = parseInt(localStorage.getItem('impresoraPVE')); | 71 | let puntoVenta = parseInt(localStorage.getItem('impresoraPVE')); |
72 | this.markArticuloInPromoAsRemoved(); | 72 | this.markArticuloInPromoAsRemoved(); |
73 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${dataPago.medioPago}`, { | 73 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${dataPago.medioPago}`, { |
74 | productos: this.articulos, | 74 | productos: this.carrito, |
75 | cliente: cliente, | 75 | cliente: cliente, |
76 | origen: 'autoservicio', | 76 | origen: 'autoservicio', |
77 | codigoVendedor: 5, | 77 | codigoVendedor: 5, |
78 | puntoVenta: dataPago.medioPago === 9 ? -1 * puntoVenta : puntoVenta, | 78 | puntoVenta: dataPago.medioPago === 9 ? -1 * puntoVenta : puntoVenta, |
79 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 79 | pedidoAnombreDe: dataPago.pedidoAnombreDe, |
80 | numeroPlanilla: '11111', | 80 | numeroPlanilla: '11111', |
81 | }) | 81 | }) |
82 | .subscribe((data) => { | 82 | .subscribe((data) => { |
83 | observer.next(data); | 83 | observer.next(data); |
84 | observer.complete(); | 84 | observer.complete(); |
85 | }); | 85 | }); |
86 | }); | 86 | }); |
87 | }); | 87 | }); |
88 | } | 88 | } |
89 | 89 | ||
90 | cleanShoppingCar() { | 90 | cleanShoppingCar() { |
91 | this.articuloAcargar = undefined; | 91 | this.articuloAcargar = undefined; |
92 | this.promoAcargar = undefined; | 92 | this.promoAcargar = undefined; |
93 | this.articulos = []; | 93 | this.carrito = []; |
94 | } | 94 | } |
95 | 95 | ||
96 | setArticulosSinImagen(articulos: IArticulo[]) { | 96 | setArticulosSinImagen(articulos: IArticulo[]) { |
97 | articulos.forEach((articulo: IArticulo) => { | 97 | articulos.forEach((articulo: IArticulo) => { |
98 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : | 98 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : |
99 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; | 99 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; |
100 | }); | 100 | }); |
101 | } | 101 | } |
102 | 102 | ||
103 | markArticuloInPromoAsRemoved() { | 103 | markArticuloInPromoAsRemoved() { |
104 | this.articulos.forEach((articulo: IArticulo) => { | 104 | this.carrito.forEach((articulo: IArticulo) => { |
105 | if (articulo.PRO) { | 105 | if (articulo.PRO) { |
106 | articulo.productos.forEach((articulo: IArticulo) => { | 106 | articulo.productos.forEach((articulo: IArticulo) => { |
107 | if (articulo.cantidadAdicionada === 0) { | 107 | if (articulo.cantidadAdicionada === 0) { |
108 | articulo.cantidad = 0; | 108 | articulo.cantidad = 0; |
109 | articulo.importeValorExtra = 0; | 109 | articulo.importeValorExtra = 0; |
110 | } | 110 | } |
111 | }); | 111 | }); |
112 | } | 112 | } |
113 | }); | 113 | }); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 |