Commit c337433eafef2f2ccd80bca06a139f2b814b4e23
1 parent
78c2e7838a
Exists in
develop
Add
Sumar y restar cantidad de articulos en carrito
Showing
5 changed files
with
86 additions
and
27 deletions
 
Show diff stats
src/app/modules/carrito/carrito.component.ts
| 1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; | 
| 2 | import { Location } from '@angular/common'; | 2 | import { Location } from '@angular/common'; | 
| 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 
| 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 
| 5 | import { trigger, state, style, transition, animate } from '@angular/animations'; | 5 | import { trigger, state, style, transition, animate } from '@angular/animations'; | 
| 6 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 6 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 
| 7 | import { Router } from '@angular/router'; | 7 | import { Router } from '@angular/router'; | 
| 8 | import { BsModalRef } from 'ngx-bootstrap/modal/public_api'; | 8 | import { BsModalRef } from 'ngx-bootstrap/modal/public_api'; | 
| 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 | 10 | ||
| 11 | @Component({ | 11 | @Component({ | 
| 12 | selector: 'app-carrito', | 12 | selector: 'app-carrito', | 
| 13 | templateUrl: './carrito.component.html', | 13 | templateUrl: './carrito.component.html', | 
| 14 | styleUrls: ['./carrito.component.scss'], | 14 | styleUrls: ['./carrito.component.scss'], | 
| 15 | animations: [ | 15 | animations: [ | 
| 16 | trigger('EnterLeave', [ | 16 | trigger('EnterLeave', [ | 
| 17 | state('flyIn', style({ transform: 'translateX(0)' })), | 17 | state('flyIn', style({ transform: 'translateX(0)' })), | 
| 18 | transition(':enter', [ | 18 | transition(':enter', [ | 
| 19 | style({ transform: 'translateX(-100%)' }), | 19 | style({ transform: 'translateX(-100%)' }), | 
| 20 | animate('1s ease-in') | 20 | animate('1s ease-in') | 
| 21 | ]), | 21 | ]), | 
| 22 | transition(':leave', [ | 22 | transition(':leave', [ | 
| 23 | animate('1s ease-out', style({ transform: 'translateX(-100%)' })) | 23 | animate('1s ease-out', style({ transform: 'translateX(-100%)' })) | 
| 24 | ]) | 24 | ]) | 
| 25 | ]) | 25 | ]) | 
| 26 | ] | 26 | ] | 
| 27 | }) | 27 | }) | 
| 28 | export class CarritoComponent implements OnInit, OnDestroy { | 28 | export class CarritoComponent implements OnInit, OnDestroy { | 
| 29 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 29 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 
| 30 | maxCantidad = 50; | 30 | maxCantidad = 50; | 
| 31 | modalRef: BsModalRef; | 31 | modalRef: BsModalRef; | 
| 32 | 32 | ||
| 33 | constructor( | 33 | constructor( | 
| 34 | public articuloService: ArticuloService, | 34 | public articuloService: ArticuloService, | 
| 35 | private location: Location, | 35 | private location: Location, | 
| 36 | private router: Router, | 36 | private router: Router, | 
| 37 | private inactiveScreen: InactiveScreenService, | 37 | private inactiveScreen: InactiveScreenService, | 
| 38 | ) { } | 38 | ) { } | 
| 39 | 39 | ||
| 40 | ngOnInit() { | 40 | ngOnInit() { | 
| 41 | if (!this.articuloService.carrito.length) { | 41 | if (!this.articuloService.carrito.length) { | 
| 42 | this.router.navigate(['']); | 42 | this.router.navigate(['']); | 
| 43 | return; | 43 | return; | 
| 44 | } | 44 | } | 
| 45 | this.mediaPantallaP(); | 45 | this.mediaPantallaP(); | 
| 46 | } | 46 | } | 
| 47 | 47 | ||
| 48 | ngOnDestroy() { | 48 | ngOnDestroy() { | 
| 49 | if (this.modalRef) this.modalRef.hide(); | 49 | if (this.modalRef) this.modalRef.hide(); | 
| 50 | } | 50 | } | 
| 51 | 51 | ||
| 52 | deleteArticulo(index: number) { | 52 | deleteArticulo(index: number) { | 
| 53 | this.articuloService.deleteArticulo(index); | 53 | this.articuloService.deleteArticulo(index); | 
| 54 | } | 54 | } | 
| 55 | 55 | ||
| 56 | substractCant(articulo: IArticulo) { | 56 | substractCant(articulo: IArticulo) { | 
| 57 | if (articulo.cantidad === 1) return; | 57 | this.articuloService.substractCant(articulo); | 
| 58 | articulo.cantidad--; | ||
| 59 | this.articuloService.calcularTotal(); | ||
| 60 | } | 58 | } | 
| 61 | 59 | ||
| 62 | addCant(articulo: IArticulo) { | 60 | addCant(articulo: IArticulo) { | 
| 63 | if (articulo.cantidad >= this.maxCantidad) return; | 61 | this.articuloService.addCant(articulo); | 
| 64 | articulo.cantidad++; | ||
| 65 | this.articuloService.calcularTotal(); | ||
| 66 | } | 62 | } | 
| 67 | 63 | ||
| 68 | goBack() { | 64 | goBack() { | 
| 69 | this.location.back(); | 65 | this.location.back(); | 
| 70 | } | 66 | } | 
| 71 | 67 | ||
| 72 | @HostListener('document:click', ['$event']) | 68 | @HostListener('document:click', ['$event']) | 
| 73 | eventListener(event: Event) { | 69 | eventListener(event: Event) { | 
| 74 | clearTimeout(this.inactiveScreen.timerReposo); | 70 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 75 | this.inactiveScreen.startTimeOutInactividad(); | 71 | this.inactiveScreen.startTimeOutInactividad(); | 
| 76 | } | 72 | } | 
| 77 | 73 | ||
| 78 | @HostListener('scroll', ['$event']) | 74 | @HostListener('scroll', ['$event']) | 
| 79 | scrollEvent(event: Event) { | 75 | scrollEvent(event: Event) { | 
| 80 | clearTimeout(this.inactiveScreen.timerReposo); | 76 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 81 | this.inactiveScreen.startTimeOutInactividad(); | 77 | this.inactiveScreen.startTimeOutInactividad(); | 
| 82 | } | 78 | } | 
| 83 | 79 | ||
| 84 | mediaPantallaP() { | 80 | mediaPantallaP() { | 
| 85 | if ($('body').hasClass('media-pantalla')) { | 81 | if ($('body').hasClass('media-pantalla')) { | 
| 86 | $('.carrito-content,.carrito-articulo').addClass('media-pantalla'); | 82 | $('.carrito-content,.carrito-articulo').addClass('media-pantalla'); | 
| 87 | } | 83 | } | 
| 88 | } | 84 | } | 
| 89 | } | 85 | } | 
| 90 | 86 | 
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-80 align-items-end"> | 5 | <div class="row mx-0 h-80 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-50 h-md-70" id="content"> | 15 | <div class="row w-100 mr-4 h-50 h-md-70" id="content"> | 
| 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 cat-btn"> | 22 | <div class="col-auto btn-effect h-5 cat-btn"> | 
| 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 py-1 | 36 | class="col-12 px-0 box-categorias border border-primary py-1 | 
| 37 | border-left-0 rounded-right scroll-y cat-box" | 37 | border-left-0 rounded-right scroll-y cat-box" | 
| 38 | (scroll)="scrollEvent($event)"> | 38 | (scroll)="scrollEvent($event)"> | 
| 39 | <div | 39 | <div | 
| 40 | class="row mx-4 mb-2 h-25 h-md-32 h-lg-45 justify-content-center tab cat-content" | 40 | class="row mx-4 mb-2 h-25 h-md-32 h-lg-45 justify-content-center tab cat-content" | 
| 41 | [ngClass]="{ 'active rounded-sm shadow': allActive, 'border-bottom-effect': !allActive, | 41 | [ngClass]="{ 'active rounded-sm shadow': allActive, 'border-bottom-effect': !allActive, | 
| 42 | 'media-pantalla' : boxCarrito.classList.contains('media-pantalla') }" | 42 | 'media-pantalla' : boxCarrito.classList.contains('media-pantalla') }" | 
| 43 | (click)="selectCategoria(-1, 0)"> | 43 | (click)="selectCategoria(-1, 0)"> | 
| 44 | <img | 44 | <img | 
| 45 | draggable="false" | 45 | draggable="false" | 
| 46 | ondragstart="return false;" | 46 | ondragstart="return false;" | 
| 47 | (contextmenu)="false" | 47 | (contextmenu)="false" | 
| 48 | class="col-12 img-fluid align-self-end d-none d-sm-block rounded-circle" | 48 | class="col-12 img-fluid align-self-end d-none d-sm-block rounded-circle" | 
| 49 | src="assets/img/logo-spot.svg"> | 49 | src="assets/img/logo-spot.svg"> | 
| 50 | <small class="col-12 px-0 my-1 h-100 h-md-25 align-self-end text-center text-truncate">Todos</small> | 50 | <small class="col-12 px-0 my-1 h-100 h-md-25 align-self-end text-center text-truncate">Todos</small> | 
| 51 | </div> | 51 | </div> | 
| 52 | <div | 52 | <div | 
| 53 | class="row mx-4 mb-2 h-25 h-md-32 h-lg-45 justify-content-center tab cat-content" | 53 | class="row mx-4 mb-2 h-25 h-md-32 h-lg-45 justify-content-center tab cat-content" | 
| 54 | [ngClass]="{ 'active rounded-sm shadow': categoria.selected, 'border-bottom-effect': !categoria.selected, | 54 | [ngClass]="{ 'active rounded-sm shadow': categoria.selected, 'border-bottom-effect': !categoria.selected, | 
| 55 | 'media-pantalla' : boxCarrito.classList.contains('media-pantalla') }" | 55 | 'media-pantalla' : boxCarrito.classList.contains('media-pantalla') }" | 
| 56 | (click)="selectCategoria(i, categoria.id)" | 56 | (click)="selectCategoria(i, categoria.id)" | 
| 57 | *ngFor="let categoria of categorias; let i = index;"> | 57 | *ngFor="let categoria of categorias; let i = index;"> | 
| 58 | <img | 58 | <img | 
| 59 | draggable="false" | 59 | draggable="false" | 
| 60 | ondragstart="return false;" | 60 | ondragstart="return false;" | 
| 61 | (contextmenu)="false" | 61 | (contextmenu)="false" | 
| 62 | class="col-12 img-fluid align-self-end d-none d-sm-block rounded-circle" | 62 | class="col-12 img-fluid align-self-end d-none d-sm-block rounded-circle" | 
| 63 | [ngClass]="{'media-pantalla' : boxCarrito.classList.contains('media-pantalla')}" | 63 | [ngClass]="{'media-pantalla' : boxCarrito.classList.contains('media-pantalla')}" | 
| 64 | src="{{urlImagenes}}{{categoria.path_imagen}}" | 64 | src="{{urlImagenes}}{{categoria.path_imagen}}" | 
| 65 | onerror="this.src='assets/img/image-not-found.jpg'"> | 65 | onerror="this.src='assets/img/image-not-found.jpg'"> | 
| 66 | <small class="col-12 px-1 my-1 h-100 h-md-25 align-self-end text-center text-truncate">{{categoria.detalle}}</small> | 66 | <small class="col-12 px-1 my-1 h-100 h-md-25 align-self-end text-center text-truncate">{{categoria.detalle}}</small> | 
| 67 | </div> | 67 | </div> | 
| 68 | </div> | 68 | </div> | 
| 69 | <div class="col-auto btn-effect h-5 cat-btn"> | 69 | <div class="col-auto btn-effect h-5 cat-btn"> | 
| 70 | <img | 70 | <img | 
| 71 | draggable="false" | 71 | draggable="false" | 
| 72 | ondragstart="return false;" | 72 | ondragstart="return false;" | 
| 73 | (contextmenu)="false" | 73 | (contextmenu)="false" | 
| 74 | class="h-100 d-block mx-auto rotate-90" | 74 | class="h-100 d-block mx-auto rotate-90" | 
| 75 | src="assets/img/ir-color.svg" | 75 | src="assets/img/ir-color.svg" | 
| 76 | (mousedown)="scrollY(templateCategorias, 100)" | 76 | (mousedown)="scrollY(templateCategorias, 100)" | 
| 77 | (mouseup)="mouseup()" | 77 | (mouseup)="mouseup()" | 
| 78 | (mouseleave)="mouseup()"> | 78 | (mouseleave)="mouseup()"> | 
| 79 | </div> | 79 | </div> | 
| 80 | </div> | 80 | </div> | 
| 81 | </div> | 81 | </div> | 
| 82 | <!-- LISTA DE ARTICULOS --> | 82 | <!-- LISTA DE ARTICULOS --> | 
| 83 | <div | 83 | <div | 
| 84 | class="col-7 col-sm-9 col-xl-10 pb-3 h-100 align-self-center scroll-y-visible" | 84 | class="col-7 col-sm-9 col-xl-10 pb-3 h-100 align-self-center scroll-y-visible" | 
| 85 | (scroll)="scrollEvent($event)"> | 85 | (scroll)="scrollEvent($event)"> | 
| 86 | <div class="row row-cols-1 row-cols-sm-3 row-cols-xl-6"> | 86 | <div class="row row-cols-1 row-cols-sm-3 row-cols-xl-6"> | 
| 87 | <!-- ARTICULO --> | 87 | <!-- ARTICULO --> | 
| 88 | <div | 88 | <div | 
| 89 | class="col px-2 my-1 my-md-3 h-auto" | 89 | class="col px-2 my-1 my-md-3 h-auto" | 
| 90 | *ngFor="let articulo of auxArticulos | slice:0:showQuantity;"> | 90 | *ngFor="let articulo of auxArticulos | slice:0:showQuantity;"> | 
| 91 | <div | 91 | <div | 
| 92 | class="swing-in-top-fwd btn-effect card h-auto" | 92 | class="swing-in-top-fwd btn-effect card h-auto" | 
| 93 | (click)="selectArticulo(articulo)"> | 93 | (click)="selectArticulo(articulo)"> | 
| 94 | <img | 94 | <img | 
| 95 | draggable="false" | 95 | draggable="false" | 
| 96 | ondragstart="return false;" | 96 | ondragstart="return false;" | 
| 97 | (contextmenu)="false" | 97 | (contextmenu)="false" | 
| 98 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" | 98 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" | 
| 99 | onerror="this.src='assets/img/image-not-found.jpg'" | 99 | onerror="this.src='assets/img/image-not-found.jpg'" | 
| 100 | class="card-img-top h-30 h-md-55 rounded-sm"> | 100 | class="card-img-top h-30 h-md-55 rounded-sm"> | 
| 101 | <div class="row mx-0 py-1 h-auto justify-content-center"> | 101 | <div class="row mx-0 py-1 h-auto justify-content-center"> | 
| 102 | <p | 102 | <p | 
| 103 | [ngClass]="{'text-primary': articulo.PRO, 'text-secondary': !articulo.PRO}" | 103 | [ngClass]="{'text-primary': articulo.PRO, 'text-secondary': !articulo.PRO}" | 
| 104 | class="col-12 px-1 h6 h-auto text-center min-h-60"> | 104 | class="col-12 px-1 h6 h-auto text-center min-h-60"> | 
| 105 | {{articulo.DetArt.toUpperCase()}} | 105 | {{articulo.DetArt.toUpperCase()}} | 
| 106 | </p> | 106 | </p> | 
| 107 | <div class="col-12 px-1 align-self-end h-auto"> | 107 | <div class="col-12 px-1 align-self-end h-auto"> | 
| 108 | <div | 108 | <div | 
| 109 | [ngClass]="{'bg-primary': articulo.PRO, 'bg-secondary': !articulo.PRO}" | 109 | [ngClass]="{'bg-primary': articulo.PRO, 'bg-secondary': !articulo.PRO}" | 
| 110 | class="row mx-0 justify-content-between badge-pill"> | 110 | class="row mx-0 justify-content-between badge-pill"> | 
| 111 | <div class="col px-0 align-self-center text-white text-right"> | 111 | <div class="col px-0 align-self-center text-white text-right"> | 
| 112 | {{articulo.PreVen | currency}} | 112 | {{articulo.PreVen | currency}} | 
| 113 | </div> | 113 | </div> | 
| 114 | <div class="col-5 px-0"> | 114 | <div class="col-5 px-0"> | 
| 115 | <img | 115 | <img | 
| 116 | draggable="false" | 116 | draggable="false" | 
| 117 | ondragstart="return false;" | 117 | ondragstart="return false;" | 
| 118 | (contextmenu)="false" | 118 | (contextmenu)="false" | 
| 119 | class="d-block ml-auto py-1 icon-30" | 119 | class="d-block ml-auto py-1 icon-30" | 
| 120 | src="assets/img/ir.svg"> | 120 | src="assets/img/ir.svg"> | 
| 121 | </div> | 121 | </div> | 
| 122 | </div> | 122 | </div> | 
| 123 | </div> | 123 | </div> | 
| 124 | </div> | 124 | </div> | 
| 125 | </div> | 125 | </div> | 
| 126 | </div> | 126 | </div> | 
| 127 | </div> | 127 | </div> | 
| 128 | <!-- BOTON VER MAS --> | 128 | <!-- BOTON VER MAS --> | 
| 129 | <div class="row mx-0"> | 129 | <div class="row mx-0"> | 
| 130 | <div | 130 | <div | 
| 131 | *ngIf="showQuantity <= auxArticulos.slice(0, showQuantity).length" | 131 | *ngIf="showQuantity <= auxArticulos.slice(0, showQuantity).length" | 
| 132 | class="col-12 px-0 mb-2"> | 132 | class="col-12 px-0 mb-2"> | 
| 133 | <button | 133 | <button | 
| 134 | (click)="increaseShow()" | 134 | (click)="increaseShow()" | 
| 135 | class="btn btn-block btn-outline-primary"> | 135 | class="btn btn-block btn-outline-primary"> | 
| 136 | Ver Más | 136 | Ver Más | 
| 137 | </button> | 137 | </button> | 
| 138 | </div> | 138 | </div> | 
| 139 | </div> | 139 | </div> | 
| 140 | </div> | 140 | </div> | 
| 141 | </div> | 141 | </div> | 
| 142 | </div> | 142 | </div> | 
| 143 | </div> | 143 | </div> | 
| 144 | <!-- FOOTER CARRITO DE COMPRAS --> | 144 | <!-- FOOTER CARRITO DE COMPRAS --> | 
| 145 | <div class="row w-90 mx-auto h-auto justify-content-center"> | 145 | <div class="row w-90 mx-auto h-auto justify-content-center"> | 
| 146 | <div class="h-75 px-0 border border-primary rounded" #boxCarrito | 146 | <div class="h-75 px-0 border border-primary rounded" #boxCarrito | 
| 147 | [ngClass]="boxCarrito.classList.contains('media-pantalla') | 147 | [ngClass]="boxCarrito.classList.contains('media-pantalla') | 
| 148 | ? 'col-8' : 'col-12'" id="boxCarrito"> | 148 | ? 'col-8' : 'col-12'" id="boxCarrito"> | 
| 149 | <!-- CABECERA --> | 149 | <!-- CABECERA --> | 
| 150 | <div class="row mx-0 h-15 border-bottom border-primary"> | 150 | <div class="row mx-0 h-15 border-bottom border-primary"> | 
| 151 | <p class="col align-self-center text-truncate"><small>ARTÍCULOS EN TÚ CARRITO DE COMPRAS</small></p> | 151 | <p class="col align-self-center text-truncate"><small>ARTÍCULOS EN TÚ CARRITO DE COMPRAS</small></p> | 
| 152 | </div> | 152 | </div> | 
| 153 | <!-- CUERPO --> | 153 | <!-- CUERPO --> | 
| 154 | <div class="row h-85 mx-0 justify-content-around"> | 154 | <div class="row h-85 mx-0 justify-content-around"> | 
| 155 | <!-- BOTON SCROLL IZQUIERDA --> | 155 | <!-- BOTON SCROLL IZQUIERDA --> | 
| 156 | <div *ngIf="articuloService.carrito.length" class="col-auto btn-effect h-20 align-self-center"> | 156 | <div *ngIf="articuloService.carrito.length" class="col-auto btn-effect h-20 align-self-center"> | 
| 157 | <img | 157 | <img | 
| 158 | draggable="false" | 158 | draggable="false" | 
| 159 | ondragstart="return false;" | 159 | ondragstart="return false;" | 
| 160 | (contextmenu)="false" | 160 | (contextmenu)="false" | 
| 161 | class="icon-30 rotate-180-neg" | 161 | class="icon-30 rotate-180-neg" | 
| 162 | src="assets/img/ir-fondo-color.svg" | 162 | src="assets/img/ir-fondo-color.svg" | 
| 163 | (mousedown)="scrollX(templateCarrito, -100)" | 163 | (mousedown)="scrollX(templateCarrito, -100)" | 
| 164 | (mouseup)="mouseup()" | 164 | (mouseup)="mouseup()" | 
| 165 | (mouseleave)="mouseup()"> | 165 | (mouseleave)="mouseup()"> | 
| 166 | </div> | 166 | </div> | 
| 167 | <!-- CARRITO --> | 167 | <!-- CARRITO --> | 
| 168 | <div class="col-6 col-sm-8 col-lg-10 h-100"> | 168 | <div class="col-6 col-sm-8 col-lg-10 h-100"> | 
| 169 | <div | 169 | <div | 
| 170 | #templateCarrito | 170 | #templateCarrito | 
| 171 | class="row flex-row flex-nowrap h-100 mx-0 my-2 scroll-x" | 171 | class="row flex-row flex-nowrap h-100 mx-0 my-2 scroll-x" | 
| 172 | (scroll)="scrollEvent($event)"> | 172 | (scroll)="scrollEvent($event)"> | 
| 173 | <!-- MENSAJE DE ADVERTENCIA --> | ||
| 174 | <div *ngIf="!articuloService.carrito.length" class="col h-100"> | ||
| 175 | <p class="text-center py-5">No hay articulos en el carrito</p> | ||
| 176 | </div> | ||
| 177 | <!-- ARTICULOS --> | 173 | <!-- ARTICULOS --> | 
| 178 | <div | 174 | <div | 
| 179 | class="col-10 col-sm-4 col-lg-2 px-2 px-xl-4 align-self-center border-right border-primary" | 175 | class="col-10 col-sm-4 col-lg-2 px-2 px-xl-4 align-self-center border-right border-primary" | 
| 180 | *ngFor="let articulo of articuloService.carrito; let i = index;"> | 176 | *ngFor="let articulo of articuloService.carrito; let i = index;" | 
| 181 | <div class="swing-in-top-fwd"> | 177 | @EnterLeave> | 
| 182 | <img | 178 | <img | 
| 183 | class="btn-effect icon-20 position-absolute right-0" | 179 | class="btn-effect icon-20 mr-2 position-absolute right-0" | 
| 184 | src="assets/img/icono-cancelar-color.svg" | 180 | src="assets/img/icono-cancelar-color.svg" | 
| 185 | (click)="deleteArticulo(i)"> | 181 | (click)="deleteArticulo(i)"> | 
| 186 | <img | 182 | <img | 
| 187 | draggable="false" | 183 | draggable="false" | 
| 188 | ondragstart="return false;" | 184 | ondragstart="return false;" | 
| 189 | (contextmenu)="false" | 185 | (contextmenu)="false" | 
| 190 | class="d-block img-fluid p-2 mx-auto rounded" | 186 | class="d-block img-fluid p-2 mx-auto rounded" | 
| 191 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" | 187 | src="{{urlImagenes}}{{articulo.imagenes[0].imagen}}" | 
| 192 | onerror="this.src='assets/img/image-not-found.jpg'"> | 188 | onerror="this.src='assets/img/image-not-found.jpg'"> | 
| 193 | <p class="d-block mt-auto text-center text-primary text-truncate"> | 189 | <p class="d-block mt-auto text-center text-primary text-truncate"> | 
| 194 | <small>{{articulo.DetArt}}</small> | 190 | <small>{{articulo.DetArt}}</small> | 
| 195 | </p> | 191 | </p> | 
| 192 | <div class="row mx-0 justify-content-between bg-primary badge-pill"> | ||
| 193 | <!-- BOTON MENOS --> | ||
| 194 | <div class="col-auto px-0 my-auto"> | ||
| 195 | <img | ||
| 196 | draggable="false" | ||
| 197 | ondragstart="return false;" | ||
| 198 | (contextmenu)="false" | ||
| 199 | class="d-block ml-auto py-2 icon-15 btn-effect" | ||
| 200 | src="assets/img/menos-blanco.svg" | ||
| 201 | (click)="substractCant(articulo)"> | ||
| 202 | </div> | ||
| 203 | <!-- CANTIDAD --> | ||
| 204 | <div class="col px-0 my-auto text-white text-center"> | ||
| 205 | <p><small>{{articulo.cantidad}}</small></p> | ||
| 206 | </div> | ||
| 207 | <!-- BOTON MAS --> | ||
| 208 | <div class="col-auto px-0 my-auto"> | ||
| 209 | <img | ||
| 210 | draggable="false" | ||
| 211 | ondragstart="return false;" | ||
| 212 | (contextmenu)="false" | ||
| 213 | class="d-block ml-auto py-2 icon-15 btn-effect" | ||
| 214 | src="assets/img/mas-blanco.svg" | ||
| 215 | (click)="addCant(articulo)"> | ||
| 216 | </div> | ||
| 196 | </div> | 217 | </div> | 
| 197 | </div> | 218 | </div> | 
| 219 | <!-- MENSAJE DE ADVERTENCIA --> | ||
| 220 | <div *ngIf="!articuloService.carrito.length" class="col h-100"> | ||
| 221 | <p class="text-center py-5">No hay articulos en el carrito</p> | ||
| 222 | </div> | ||
| 198 | </div> | 223 | </div> | 
| 199 | </div> | 224 | </div> | 
| 200 | <!-- BOTON SCROLL DERECHA --> | 225 | <!-- BOTON SCROLL DERECHA --> | 
| 201 | <div *ngIf="articuloService.carrito.length" class="col-auto btn-effect h-20 align-self-center"> | 226 | <div *ngIf="articuloService.carrito.length" class="col-auto btn-effect h-20 align-self-center"> | 
| 202 | <img | 227 | <img | 
| 203 | draggable="false" | 228 | draggable="false" | 
| 204 | ondragstart="return false;" | 229 | ondragstart="return false;" | 
| 205 | (contextmenu)="false" | 230 | (contextmenu)="false" | 
| 206 | class="icon-30" | 231 | class="icon-30" | 
| 207 | src="assets/img/ir-fondo-color.svg" | 232 | src="assets/img/ir-fondo-color.svg" | 
| 208 | (mousedown)="scrollX(templateCarrito, 100)" | 233 | (mousedown)="scrollX(templateCarrito, 100)" | 
| 209 | (mouseup)="mouseup()" | 234 | (mouseup)="mouseup()" | 
| 210 | (mouseleave)="mouseup()"> | 235 | (mouseleave)="mouseup()"> | 
| 211 | </div> | 236 | </div> | 
| 212 | </div> | 237 | </div> | 
| 213 | </div> | 238 | </div> | 
| 214 | <!-- TOTAL--> | 239 | <!-- TOTAL--> | 
| 215 | <div | 240 | <div | 
| 216 | class="col-auto mt-2 ml-auto h-20"> | 241 | class="col-auto mt-2 ml-auto h-20"> | 
| 217 | <div class="row mx-0"> | 242 | <div class="row mx-0"> | 
| 218 | <div class="col-auto align-self-center text-primary">TOTAL</div> | 243 | <div class="col-auto align-self-center text-primary">TOTAL</div> | 
| 219 | <div class="col-auto bg-primary badge-pill"> | 244 | <div class="col-auto bg-primary badge-pill"> | 
| 220 | <p class="text-center text-white mt-1 py-1">{{articuloService.subTotal | currency}}</p> | 245 | <p class="text-center text-white mt-1 py-1">{{articuloService.subTotal | currency}}</p> | 
| 221 | </div> | 246 | </div> | 
| 222 | </div> | 247 | </div> | 
| 223 | </div> | 248 | </div> | 
| 224 | 249 | ||
| 225 | <!-- VER CARRITO --> | 250 | <!-- VER CARRITO --> | 
| 226 | <div | 251 | <div | 
| 227 | class="col-auto px-0 mt-2 h-20" | 252 | class="col-auto px-0 mt-2 h-20" | 
| 228 | *ngIf="articuloService.carrito.length" | 253 | *ngIf="articuloService.carrito.length" | 
| 229 | [ngClass]="{'ml-auto pb-3' : boxCarrito.classList.contains('media-pantalla')}"> | 254 | [ngClass]="{'ml-auto pb-3' : boxCarrito.classList.contains('media-pantalla')}"> | 
| 230 | <div | 255 | <div | 
| 231 | class="btn-effect col-auto px-0 align-self-center bg-white" | 256 | class="btn-effect col-auto px-0 align-self-center bg-white" | 
| 232 | [routerLink]="['/carrito']"> | 257 | [routerLink]="['/carrito']"> | 
| 233 | <div class="row mx-0 bg-light"> | 258 | <div class="row mx-0 bg-light"> | 
| 234 | <div class="col-auto p-0 bg-primary"> | 259 | <div class="col-auto p-0 bg-primary"> | 
| 235 | <img | 260 | <img | 
| 236 | draggable="false" | 261 | draggable="false" | 
| 237 | ondragstart="return false;" | 262 | ondragstart="return false;" | 
| 238 | (contextmenu)="false" | 263 | (contextmenu)="false" | 
| 239 | class="p-2 icon-40" | 264 | class="p-2 icon-40" | 
| 240 | src="assets/img/carrito.svg"> | 265 | src="assets/img/carrito.svg"> | 
| 241 | </div> | 266 | </div> | 
| 242 | <div class="col-auto align-self-center text-primary d-none d-sm-block">IR AL CARRITO</div> | 267 | <div class="col-auto align-self-center text-primary d-none d-sm-block">IR AL CARRITO</div> | 
| 243 | </div> | 268 | </div> | 
| 244 | </div> | 269 | </div> | 
| 245 | </div> | 270 | </div> | 
| 246 | 271 | ||
| 247 | </div> | 272 | </div> | 
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
| 1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, 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 { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 7 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 
| 8 | import { CategoriaService } from 'src/app/services/categoria/categoria.service'; | 8 | import { CategoriaService } from 'src/app/services/categoria/categoria.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 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 11 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 
| 12 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; | 12 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; | 
| 13 | import { trigger, state, style, transition, animate } from '@angular/animations'; | ||
| 13 | 14 | ||
| 14 | @Component({ | 15 | @Component({ | 
| 15 | selector: 'app-seleccion-articulos', | 16 | selector: 'app-seleccion-articulos', | 
| 16 | templateUrl: './seleccion-articulos.component.html', | 17 | templateUrl: './seleccion-articulos.component.html', | 
| 17 | styleUrls: ['./seleccion-articulos.component.scss'] | 18 | styleUrls: ['./seleccion-articulos.component.scss'], | 
| 19 | animations: [ | ||
| 20 | trigger('EnterLeave', [ | ||
| 21 | state('flyIn', style({ transform: 'translateY(0)' })), | ||
| 22 | transition(':enter', [ | ||
| 23 | style({ transform: 'translateY(-100%)' }), | ||
| 24 | animate('0.5s ease-in') | ||
| 25 | ]), | ||
| 26 | transition(':leave', [ | ||
| 27 | animate('0.5s ease-out', style({ transform: 'translateY(-100%)' })) | ||
| 28 | ]) | ||
| 29 | ]) | ||
| 30 | ] | ||
| 18 | }) | 31 | }) | 
| 19 | export class SeleccionArticulosComponent implements OnInit, OnDestroy { | 32 | export class SeleccionArticulosComponent implements OnInit, OnDestroy { | 
| 20 | showSpinner = true; | 33 | showSpinner = true; | 
| 21 | timeoutHandler: any; | 34 | timeoutHandler: any; | 
| 22 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 35 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 
| 23 | articulos: IArticulo[] = []; | 36 | articulos: IArticulo[] = []; | 
| 24 | auxArticulos: IArticulo[] = []; | 37 | auxArticulos: IArticulo[] = []; | 
| 25 | showQuantity = 100; | 38 | showQuantity = 100; | 
| 26 | queMostrar = 'todos'; | 39 | queMostrar = 'todos'; | 
| 27 | categoriaActive = null; | 40 | categoriaActive = null; | 
| 28 | categorias: ICategoria[] = []; | 41 | categorias: ICategoria[] = []; | 
| 29 | searchTerm = ''; | 42 | searchTerm = ''; | 
| 30 | ordenandoByVendidos = true; | 43 | ordenandoByVendidos = true; | 
| 31 | allActive = true; | 44 | allActive = true; | 
| 32 | modalRef: BsModalRef; | 45 | modalRef: BsModalRef; | 
| 33 | total = 0; | 46 | total = 0; | 
| 34 | 47 | ||
| 35 | constructor( | 48 | constructor( | 
| 36 | public articuloService: ArticuloService, | 49 | public articuloService: ArticuloService, | 
| 37 | private categoriaService: CategoriaService, | 50 | private categoriaService: CategoriaService, | 
| 38 | private sinonimoService: SinonimoService, | 51 | private sinonimoService: SinonimoService, | 
| 39 | private modalService: BsModalService, | 52 | private modalService: BsModalService, | 
| 40 | private inactiveScreen: InactiveScreenService, | 53 | private inactiveScreen: InactiveScreenService, | 
| 41 | ) { } | 54 | ) { } | 
| 42 | 55 | ||
| 43 | ngOnInit() { | 56 | ngOnInit() { | 
| 44 | this.getCategorias(); | 57 | this.getCategorias(); | 
| 45 | this.mediaPantalla(); | 58 | this.mediaPantalla(); | 
| 46 | } | 59 | } | 
| 47 | 60 | ||
| 48 | ngOnDestroy() { | 61 | ngOnDestroy() { | 
| 49 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 62 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 
| 50 | this.modalService.hide(i); | 63 | this.modalService.hide(i); | 
| 51 | } | 64 | } | 
| 52 | } | 65 | } | 
| 53 | 66 | ||
| 54 | getCategorias() { | 67 | getCategorias() { | 
| 55 | this.categoriaService.getAll() | 68 | this.categoriaService.getAll() | 
| 56 | .subscribe((categorias: ICategoria[]) => { | 69 | .subscribe((categorias: ICategoria[]) => { | 
| 57 | switch (this.queMostrar) { | 70 | switch (this.queMostrar) { | 
| 58 | case 'todos': | 71 | case 'todos': | 
| 59 | this.categorias = categorias; | 72 | this.categorias = categorias; | 
| 60 | this.categoriaActive = 0; | 73 | this.categoriaActive = 0; | 
| 61 | break; | 74 | break; | 
| 62 | case 'promociones': | 75 | case 'promociones': | 
| 63 | this.categorias = categorias; | 76 | this.categorias = categorias; | 
| 64 | this.categoriaActive = 19; | 77 | this.categoriaActive = 19; | 
| 65 | break; | 78 | break; | 
| 66 | case 'ordenar': | 79 | case 'ordenar': | 
| 67 | this.categorias = categorias.filter((categoria: ICategoria) => { | 80 | this.categorias = categorias.filter((categoria: ICategoria) => { | 
| 68 | return categoria.ES_PEDIDO; | 81 | return categoria.ES_PEDIDO; | 
| 69 | }); | 82 | }); | 
| 70 | this.categoriaActive = 4; | 83 | this.categoriaActive = 4; | 
| 71 | break; | 84 | break; | 
| 72 | default: | 85 | default: | 
| 73 | this.categorias = categorias; | 86 | this.categorias = categorias; | 
| 74 | this.categoriaActive = 0; | 87 | this.categoriaActive = 0; | 
| 75 | break; | 88 | break; | 
| 76 | } | 89 | } | 
| 77 | !localStorage.getItem('articulos') ? | 90 | !localStorage.getItem('articulos') ? | 
| 78 | this.getProductos() : | 91 | this.getProductos() : | 
| 79 | this.setProductos(); | 92 | this.setProductos(); | 
| 80 | }); | 93 | }); | 
| 81 | } | 94 | } | 
| 82 | 95 | ||
| 83 | getProductos() { | 96 | getProductos() { | 
| 84 | this.articuloService.getAll() | 97 | this.articuloService.getAll() | 
| 85 | .subscribe((result: IArticulo[]) => { | 98 | .subscribe((result: IArticulo[]) => { | 
| 86 | this.articuloService.setArticulosSinImagen(result); | 99 | this.articuloService.setArticulosSinImagen(result); | 
| 87 | if (this.queMostrar === 'ordenar') { | 100 | if (this.queMostrar === 'ordenar') { | 
| 88 | this.categorias.forEach((categoria: ICategoria) => { | 101 | this.categorias.forEach((categoria: ICategoria) => { | 
| 89 | const tempArticulos = result.filter((articulo: IArticulo) => { | 102 | const tempArticulos = result.filter((articulo: IArticulo) => { | 
| 90 | return articulo.categoria_selfservice === categoria.id; | 103 | return articulo.categoria_selfservice === categoria.id; | 
| 91 | }); | 104 | }); | 
| 92 | result = tempArticulos; | 105 | result = tempArticulos; | 
| 93 | }); | 106 | }); | 
| 94 | } | 107 | } | 
| 95 | localStorage.setItem('articulos', JSON.stringify(result)); | 108 | localStorage.setItem('articulos', JSON.stringify(result)); | 
| 96 | this.setProductos(); | 109 | this.setProductos(); | 
| 97 | }, (error) => { | 110 | }, (error) => { | 
| 98 | this.showSpinner = false; | 111 | this.showSpinner = false; | 
| 99 | console.error(error); | 112 | console.error(error); | 
| 100 | }); | 113 | }); | 
| 101 | } | 114 | } | 
| 102 | 115 | ||
| 103 | setProductos() { | 116 | setProductos() { | 
| 104 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 117 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 
| 105 | this.filterItems(); | 118 | this.filterItems(); | 
| 106 | } | 119 | } | 
| 107 | 120 | ||
| 108 | filterItems() { | 121 | filterItems() { | 
| 109 | if (this.categoriaActive === 0) { | 122 | if (this.categoriaActive === 0) { | 
| 110 | this.auxArticulos = this.articulos; | 123 | this.auxArticulos = this.articulos; | 
| 111 | return; | 124 | return; | 
| 112 | } | 125 | } | 
| 113 | this.auxArticulos = this.articulos.filter(x => { | 126 | this.auxArticulos = this.articulos.filter(x => { | 
| 114 | return x.categoria_selfservice === this.categoriaActive; | 127 | return x.categoria_selfservice === this.categoriaActive; | 
| 115 | }); | 128 | }); | 
| 116 | this.ordenar(); | 129 | this.ordenar(); | 
| 117 | } | 130 | } | 
| 118 | 131 | ||
| 119 | ordenar() { | 132 | ordenar() { | 
| 120 | if (this.ordenandoByVendidos) { | 133 | if (this.ordenandoByVendidos) { | 
| 121 | this.auxArticulos.sort((a, b) => { | 134 | this.auxArticulos.sort((a, b) => { | 
| 122 | return b.cantidadVendida - a.cantidadVendida; | 135 | return b.cantidadVendida - a.cantidadVendida; | 
| 123 | }); | 136 | }); | 
| 124 | } | 137 | } | 
| 125 | } | 138 | } | 
| 126 | 139 | ||
| 127 | selectCategoria(index: number, idCategoria?: number) { | 140 | selectCategoria(index: number, idCategoria?: number) { | 
| 128 | if (this.categoriaActive === idCategoria) return; | 141 | if (this.categoriaActive === idCategoria) return; | 
| 129 | this.categoriaActive = idCategoria; | 142 | this.categoriaActive = idCategoria; | 
| 130 | this.allActive = idCategoria === 0 ? true : false; | 143 | this.allActive = idCategoria === 0 ? true : false; | 
| 131 | this.categorias.forEach((categoria, i) => { | 144 | this.categorias.forEach((categoria, i) => { | 
| 132 | categoria.selected = index === i ? true : false; | 145 | categoria.selected = index === i ? true : false; | 
| 133 | }); | 146 | }); | 
| 134 | this.filterItems(); | 147 | this.filterItems(); | 
| 135 | } | 148 | } | 
| 136 | 149 | ||
| 137 | selectArticulo(articulo: IArticulo) { | 150 | selectArticulo(articulo: IArticulo) { | 
| 138 | this.getByID(articulo.id); | 151 | this.getByID(articulo.id); | 
| 139 | } | 152 | } | 
| 140 | 153 | ||
| 141 | getByID(id: number) { | 154 | getByID(id: number) { | 
| 142 | this.articuloService.getById(id) | 155 | this.articuloService.getById(id) | 
| 143 | .subscribe((res: IArticulo) => { | 156 | .subscribe((res: IArticulo) => { | 
| 144 | if (res.FPP) { | 157 | if (res.FPP) { | 
| 145 | this.openModalPromos(res); | 158 | this.openModalPromos(res); | 
| 146 | } else { | 159 | } else { | 
| 147 | this.getSinonimos(res); | 160 | this.getSinonimos(res); | 
| 148 | } | 161 | } | 
| 149 | }, err => console.error(err)); | 162 | }, err => console.error(err)); | 
| 150 | } | 163 | } | 
| 151 | 164 | ||
| 152 | getSinonimos(articulo: IArticulo) { | 165 | getSinonimos(articulo: IArticulo) { | 
| 153 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 166 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 
| 154 | .subscribe((res: ISinonimo[]) => { | 167 | .subscribe((res: ISinonimo[]) => { | 
| 155 | if (res.length) { | 168 | if (res.length) { | 
| 156 | this.openModalSinonimos(res, articulo); | 169 | this.openModalSinonimos(res, articulo); | 
| 157 | } else { | 170 | } else { | 
| 158 | this.articuloService.setArticulo(articulo); | 171 | this.articuloService.setArticulo(articulo); | 
| 159 | } | 172 | } | 
| 160 | }); | 173 | }); | 
| 161 | } | 174 | } | 
| 162 | 175 | ||
| 163 | openModalPromos(articulo: IArticulo) { | 176 | openModalPromos(articulo: IArticulo) { | 
| 164 | this.modalRef = this.modalService.show(PromocionComponent, { | 177 | this.modalRef = this.modalService.show(PromocionComponent, { | 
| 165 | initialState: { articulosPromo: [articulo] }, | 178 | initialState: { articulosPromo: [articulo] }, | 
| 166 | class: 'modal-promo modal-dialog-centered' | 179 | class: 'modal-promo modal-dialog-centered' | 
| 167 | }); | 180 | }); | 
| 168 | } | 181 | } | 
| 169 | 182 | ||
| 170 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 183 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 171 | this.modalRef = this.modalService.show(SinonimoComponent, { | 184 | this.modalRef = this.modalService.show(SinonimoComponent, { | 
| 172 | initialState: { sinonimos: sinonimosData }, | 185 | initialState: { sinonimos: sinonimosData }, | 
| 173 | class: 'modal-promo modal-dialog-centered' | 186 | class: 'modal-promo modal-dialog-centered' | 
| 174 | }); | 187 | }); | 
| 175 | 188 | ||
| 176 | this.modalRef.content.onClose | 189 | this.modalRef.content.onClose | 
| 177 | .subscribe((res: any) => { | 190 | .subscribe((res: any) => { | 
| 178 | for (const a of articulo.productos) { | 191 | for (const a of articulo.productos) { | 
| 179 | if (a.idSinonimo === res.ID_SIN) { | 192 | if (a.idSinonimo === res.ID_SIN) { | 
| 180 | a.CODA = res.articulo.CodArt; | 193 | a.CODA = res.articulo.CodArt; | 
| 181 | a.CodArt = res.articulo.CodArt; | 194 | a.CodArt = res.articulo.CodArt; | 
| 182 | a.SECA = res.articulo.CodSec; | 195 | a.SECA = res.articulo.CodSec; | 
| 183 | a.CodSec = res.articulo.CodSec; | 196 | a.CodSec = res.articulo.CodSec; | 
| 184 | a.PreVen = res.articulo.PreVen; | 197 | a.PreVen = res.articulo.PreVen; | 
| 185 | a.id = res.articulo.id; | 198 | a.id = res.articulo.id; | 
| 186 | a.DET_LAR = res.articulo.DET_LAR; | 199 | a.DET_LAR = res.articulo.DET_LAR; | 
| 187 | a.DetArt = res.articulo.DetArt; | 200 | a.DetArt = res.articulo.DetArt; | 
| 188 | } | 201 | } | 
| 189 | } | 202 | } | 
| 190 | this.articuloService.setArticulo(articulo); | 203 | this.articuloService.setArticulo(articulo); | 
| 191 | }); | 204 | }); | 
| 192 | } | 205 | } | 
| 193 | 206 | ||
| 194 | deleteArticulo(index: number) { | 207 | deleteArticulo(index: number) { | 
| 195 | this.articuloService.deleteArticulo(index); | 208 | this.articuloService.deleteArticulo(index); | 
| 196 | } | 209 | } | 
| 197 | 210 | ||
| 211 | substractCant(articulo: IArticulo) { | ||
| 212 | this.articuloService.substractCant(articulo); | ||
| 213 | } | ||
| 214 | |||
| 215 | addCant(articulo: IArticulo) { | ||
| 216 | this.articuloService.addCant(articulo); | ||
| 217 | } | ||
| 218 | |||
| 198 | increaseShow() { | 219 | increaseShow() { | 
| 199 | this.showQuantity += 100; | 220 | this.showQuantity += 100; | 
| 200 | } | 221 | } | 
| 201 | 222 | ||
| 202 | @HostListener('scroll', ['$event']) | 223 | @HostListener('scroll', ['$event']) | 
| 203 | scrollEvent(event: Event) { | 224 | scrollEvent(event: Event) { | 
| 204 | clearTimeout(this.inactiveScreen.timerReposo); | 225 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 205 | this.inactiveScreen.startTimeOutInactividad(); | 226 | this.inactiveScreen.startTimeOutInactividad(); | 
| 206 | } | 227 | } | 
| 207 | 228 | ||
| 208 | mouseup() { | 229 | mouseup() { | 
| 209 | if (!this.timeoutHandler) return; | 230 | if (!this.timeoutHandler) return; | 
| 210 | clearInterval(this.timeoutHandler); | 231 | clearInterval(this.timeoutHandler); | 
| 211 | } | 232 | } | 
| 212 | 233 | ||
| 213 | scrollY(el: HTMLElement, value) { | 234 | scrollY(el: HTMLElement, value) { | 
| 214 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 235 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 
| 215 | this.timeoutHandler = setInterval(() => { | 236 | this.timeoutHandler = setInterval(() => { | 
| 216 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 237 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 
| 217 | }, 500); | 238 | }, 500); | 
| 218 | } | 239 | } | 
| 219 | 240 | ||
| 220 | scrollX(el: HTMLElement, value) { | 241 | scrollX(el: HTMLElement, value) { | 
| 221 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 242 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 
| 222 | this.timeoutHandler = setInterval(() => { | 243 | this.timeoutHandler = setInterval(() => { | 
| 223 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 244 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 
| 224 | }, 500); | 245 | }, 500); | 
| 225 | } | 246 | } | 
| 226 | 247 | ||
| 227 | mediaPantalla() { | 248 | mediaPantalla() { | 
| 228 | if ($('body').hasClass('media-pantalla')) { | 249 | if ($('body').hasClass('media-pantalla')) { | 
| 229 | $('.cat-content,#content,.cat-btn,#boxCarrito,.cat-box,.img-categoria').addClass('media-pantalla').addBack('media-pantalla'); | 250 | $('.cat-content,#content,.cat-btn,#boxCarrito,.cat-box,.img-categoria').addClass('media-pantalla').addBack('media-pantalla'); | 
| 230 | } | 251 | } | 
| 231 | } | 252 | } | 
| 232 | } | 253 | } | 
| 233 | 254 | 
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 | export class ArticuloService { | 9 | export class ArticuloService { | 
| 10 | carrito: IArticulo[] = []; | 10 | carrito: IArticulo[] = []; | 
| 11 | articuloAcargar: IArticulo; | 11 | articuloAcargar: IArticulo; | 
| 12 | promoAcargar: IArticulo; | 12 | promoAcargar: IArticulo; | 
| 13 | mostrar: string; | 13 | mostrar: string; | 
| 14 | esPromoPersonalizada = false; | 14 | esPromoPersonalizada = false; | 
| 15 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; | 15 | urlDeboSuite = APP_SETTINGS.apiDeboSuite; | 
| 16 | medioPago: number; | 16 | medioPago: number; | 
| 17 | idComanda: number; | 17 | idComanda: number; | 
| 18 | subTotal = 0; | 18 | subTotal = 0; | 
| 19 | maxCantidad = 50; | ||
| 19 | 20 | ||
| 20 | constructor( | 21 | constructor( | 
| 21 | private http: HttpClient, | 22 | private http: HttpClient, | 
| 22 | private clienteService: ClienteService, | 23 | private clienteService: ClienteService, | 
| 23 | ) { } | 24 | ) { } | 
| 24 | 25 | ||
| 25 | getById(id) { | 26 | getById(id) { | 
| 26 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); | 27 | return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); | 
| 27 | } | 28 | } | 
| 28 | 29 | ||
| 29 | getAll() { | 30 | getAll() { | 
| 30 | return this.http.get(`${this.urlDeboSuite}/articulos/`); | 31 | return this.http.get(`${this.urlDeboSuite}/articulos/`); | 
| 31 | } | 32 | } | 
| 32 | 33 | ||
| 33 | getAllWithPaginator(page: number = 1) { | 34 | getAllWithPaginator(page: number = 1) { | 
| 34 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); | 35 | return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); | 
| 35 | } | 36 | } | 
| 36 | 37 | ||
| 38 | substractCant(articulo: IArticulo) { | ||
| 39 | if (articulo.cantidad === 1) return; | ||
| 40 | articulo.cantidad--; | ||
| 41 | this.calcularTotal(); | ||
| 42 | } | ||
| 43 | |||
| 44 | addCant(articulo: IArticulo) { | ||
| 45 | if (articulo.cantidad >= this.maxCantidad) return; | ||
| 46 | articulo.cantidad++; | ||
| 47 | this.calcularTotal(); | ||
| 48 | } | ||
| 49 | |||
| 37 | calcularTotal() { | 50 | calcularTotal() { | 
| 38 | this.subTotal = 0; | 51 | this.subTotal = 0; | 
| 39 | this.carrito.forEach(articulo => { | 52 | this.carrito.forEach(articulo => { | 
| 40 | this.subTotal += (articulo.PreVen * articulo.cantidad); | 53 | this.subTotal += (articulo.PreVen * articulo.cantidad); | 
| 41 | }); | 54 | }); | 
| 42 | } | 55 | } | 
| 43 | 56 | ||
| 44 | setArticulo(articulo: IArticulo) { | 57 | setArticulo(articulo: IArticulo) { | 
| 45 | articulo.cantidad = 1; | 58 | articulo.cantidad = 1; | 
| 46 | for (const articuloCarrito of this.carrito) { | 59 | for (const articuloCarrito of this.carrito) { | 
| 47 | if (articuloCarrito.id === articulo.id && !articulo.productos.length) { | 60 | if (articuloCarrito.id === articulo.id && !articulo.productos.length) { | 
| 48 | articuloCarrito.cantidad++; | 61 | articuloCarrito.cantidad++; | 
| 49 | this.calcularTotal(); | 62 | this.calcularTotal(); | 
| 50 | return; | 63 | return; | 
| 51 | } | 64 | } | 
| 52 | } | 65 | } | 
| 53 | this.setArticulosSinImagen([articulo]); | 66 | this.setArticulosSinImagen([articulo]); | 
| 54 | this.carrito.unshift(articulo); | 67 | this.carrito.unshift(articulo); | 
| 55 | this.calcularTotal(); | 68 | this.calcularTotal(); | 
| 56 | } | 69 | } | 
| 57 | 70 | ||
| 58 | deleteArticulo(index: number) { | 71 | deleteArticulo(index: number) { | 
| 59 | this.carrito.splice(index, 1); | 72 | this.carrito.splice(index, 1); | 
| 60 | this.calcularTotal(); | 73 | this.calcularTotal(); | 
| 61 | } | 74 | } | 
| 62 | 75 | ||
| 63 | pay(dataPago: any) { | 76 | pay(dataPago: any) { | 
| 64 | return new Observable((observer) => { | 77 | return new Observable((observer) => { | 
| 65 | this.clienteService.getById(-1) | 78 | this.clienteService.getById(-1) | 
| 66 | .subscribe(cliente => { | 79 | .subscribe(cliente => { | 
| 67 | this.markArticuloInPromoAsRemoved(); | 80 | this.markArticuloInPromoAsRemoved(); | 
| 68 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { | 81 | this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { | 
| 69 | productos: this.carrito, | 82 | productos: this.carrito, | 
| 70 | cliente, | 83 | cliente, | 
| 71 | origen: 'autoservicio', | 84 | origen: 'autoservicio', | 
| 72 | codigoVendedor: 5, | 85 | codigoVendedor: 5, | 
| 73 | puntoVenta: APP_SETTINGS.puntoVenta, | 86 | puntoVenta: APP_SETTINGS.puntoVenta, | 
| 74 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 87 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 
| 75 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, | 88 | numeroPlanilla: APP_SETTINGS.numeroPlanilla, | 
| 76 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), | 89 | pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), | 
| 77 | }) | 90 | }) | 
| 78 | .subscribe((data) => { | 91 | .subscribe((data) => { | 
| 79 | observer.next(data); | 92 | observer.next(data); | 
| 80 | observer.complete(); | 93 | observer.complete(); | 
| 81 | }); | 94 | }); | 
| 82 | }); | 95 | }); | 
| 83 | }); | 96 | }); | 
| 84 | } | 97 | } | 
| 85 | 98 | ||
| 86 | cleanShoppingCar() { | 99 | cleanShoppingCar() { | 
| 87 | this.articuloAcargar = undefined; | 100 | this.articuloAcargar = undefined; | 
| 88 | this.promoAcargar = undefined; | 101 | this.promoAcargar = undefined; | 
| 89 | this.carrito = []; | 102 | this.carrito = []; | 
| 90 | } | 103 | } | 
| 91 | 104 | ||
| 92 | setArticulosSinImagen(articulos: IArticulo[]) { | 105 | setArticulosSinImagen(articulos: IArticulo[]) { | 
| 93 | articulos.forEach((articulo: IArticulo) => { | 106 | articulos.forEach((articulo: IArticulo) => { | 
| 94 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : | 107 | articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : | 
| 95 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; | 108 | !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; | 
| 96 | }); | 109 | }); | 
| 97 | } | 110 | } | 
| 98 | 111 | ||
| 99 | markArticuloInPromoAsRemoved() { | 112 | markArticuloInPromoAsRemoved() { | 
| 100 | this.carrito.forEach((articuloCarrito: IArticulo) => { | 113 | this.carrito.forEach((articuloCarrito: IArticulo) => { | 
| 101 | if (articuloCarrito.PRO) { | 114 | if (articuloCarrito.PRO) { | 
| 102 | articuloCarrito.productos.forEach((articulo: IArticulo) => { | 115 | articuloCarrito.productos.forEach((articulo: IArticulo) => { | 
| 103 | if (articulo.cantidadAdicionada === 0) { | 116 | if (articulo.cantidadAdicionada === 0) { | 
| 104 | articulo.cantidad = 0; | 117 | articulo.cantidad = 0; | 
| 105 | articulo.importeValorExtra = 0; | 118 | articulo.importeValorExtra = 0; | 
| 106 | } | 119 | } | 
| 107 | }); | 120 | }); | 
| 108 | } | 121 | } | 
| 109 | }); | 122 | }); | 
| 110 | } | 123 | } | 
| 111 | } | 124 | } | 
| 112 | 125 | 
src/scss/icons.scss
| 1 | .icon-15 { | ||
| 2 | width: 15px; | ||
| 3 | } | ||
| 4 | |||
| 1 | .icon-20 { | 5 | .icon-20 { | 
| 2 | width: 20px; | 6 | width: 20px; | 
| 3 | } | 7 | } | 
| 4 | 8 | ||
| 5 | .icon-30 { | 9 | .icon-30 { | 
| 6 | width: 30px; | 10 | width: 30px; | 
| 7 | } | 11 | } | 
| 8 | 12 | ||
| 9 | .icon-40 { | 13 | .icon-40 { | 
| 10 | width: 40px; | 14 | width: 40px; | 
| 11 | } | 15 | } | 
| 12 | 16 | ||
| 13 | .icon-50 { | 17 | .icon-50 { | 
| 14 | width: 50px; | 18 | width: 50px; | 
| 15 | } | 19 | } | 
| 16 | 20 | ||
| 17 | .icon-60 { | 21 | .icon-60 { | 
| 18 | width: 60px; | 22 | width: 60px; | 
| 19 | } | 23 | } | 
| 20 | 24 | ||
| 21 | .icon-150 { | 25 | .icon-150 { | 
| 22 | width: 150px; | 26 | width: 150px; | 
| 23 | } | 27 | } | 
| 24 | 28 |