Commit 001d1450d6c61f1e2a834eefafe8d231273fbc4b
1 parent
6215ca50b4
Exists in
develop
solving lint
Showing
5 changed files
with
3 additions
and
7 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 { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
| 6 | import { BsModalRef } from 'ngx-bootstrap/modal/public_api'; | 6 | import { BsModalRef } from 'ngx-bootstrap/modal/public_api'; |
| 7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
| 8 | import { ANIMATIONS } from 'src/app/utils/animations'; | 8 | import { ANIMATIONS } from 'src/app/utils/animations'; |
| 9 | 9 | ||
| 10 | @Component({ | 10 | @Component({ |
| 11 | selector: 'app-carrito', | 11 | selector: 'app-carrito', |
| 12 | templateUrl: './carrito.component.html', | 12 | templateUrl: './carrito.component.html', |
| 13 | styleUrls: ['./carrito.component.scss'], | 13 | styleUrls: ['./carrito.component.scss'], |
| 14 | animations: [ANIMATIONS.EnterLeaveX] | 14 | animations: [ANIMATIONS.EnterLeaveX] |
| 15 | }) | 15 | }) |
| 16 | export class CarritoComponent implements OnInit, OnDestroy { | 16 | export class CarritoComponent implements OnInit, OnDestroy { |
| 17 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 17 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
| 18 | maxCantidad = 50; | 18 | maxCantidad = 50; |
| 19 | modalRef: BsModalRef; | 19 | modalRef: BsModalRef; |
| 20 | 20 | ||
| 21 | constructor( | 21 | constructor( |
| 22 | public articuloService: ArticuloService, | 22 | public articuloService: ArticuloService, |
| 23 | private location: Location, | 23 | private location: Location, |
| 24 | private router: Router, | 24 | private router: Router, |
| 25 | private inactiveScreen: InactiveScreenService, | 25 | private inactiveScreen: InactiveScreenService, |
| 26 | ) { } | 26 | ) { } |
| 27 | 27 | ||
| 28 | ngOnInit() { | 28 | ngOnInit() { |
| 29 | if (!this.articuloService.carrito.length) { | 29 | if (!this.articuloService.carrito.length) { |
| 30 | this.router.navigate(['']); | 30 | this.router.navigate(['']); |
| 31 | return; | 31 | return; |
| 32 | } | 32 | } |
| 33 | // console.log('COMPONENTE INICIADO'); | ||
| 34 | |||
| 35 | this.mediaPantalla(); | 33 | this.mediaPantalla(); |
| 36 | } | 34 | } |
| 37 | 35 | ||
| 38 | ngOnDestroy() { | 36 | ngOnDestroy() { |
| 39 | if (this.modalRef) this.modalRef.hide(); | 37 | if (this.modalRef) this.modalRef.hide(); |
| 40 | } | 38 | } |
| 41 | 39 | ||
| 42 | deleteArticulo(index: number) { | 40 | deleteArticulo(index: number) { |
| 43 | this.articuloService.deleteArticulo(index); | 41 | this.articuloService.deleteArticulo(index); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | goBack() { | 44 | goBack() { |
| 47 | this.location.back(); | 45 | this.location.back(); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | @HostListener('document:click', ['$event']) | 48 | @HostListener('document:click', ['$event']) |
| 51 | eventListener(event: Event) { | 49 | eventListener(event: Event) { |
| 52 | clearTimeout(this.inactiveScreen.timerReposo); | 50 | clearTimeout(this.inactiveScreen.timerReposo); |
| 53 | this.inactiveScreen.startTimeOutInactividad(); | 51 | this.inactiveScreen.startTimeOutInactividad(); |
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | @HostListener('scroll', ['$event']) | 54 | @HostListener('scroll', ['$event']) |
| 57 | scrollEvent(event: Event) { | 55 | scrollEvent(event: Event) { |
| 58 | clearTimeout(this.inactiveScreen.timerReposo); | 56 | clearTimeout(this.inactiveScreen.timerReposo); |
| 59 | this.inactiveScreen.startTimeOutInactividad(); | 57 | this.inactiveScreen.startTimeOutInactividad(); |
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | mediaPantalla() { | 60 | mediaPantalla() { |
| 63 | if ($('body').hasClass('media-pantalla')) { | 61 | if ($('body').hasClass('media-pantalla')) { |
| 64 | $(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla'); | 62 | $(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla'); |
| 65 | } | 63 | } |
| 66 | console.log('AGARRA CONIOO'); | ||
| 67 | } | 64 | } |
| 68 | } | 65 | } |
| 69 | 66 |
src/app/modules/pago-electronico/pago-electronico.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
| 2 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 2 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 3 | import { Router } from '@angular/router'; | 3 | import { Router } from '@angular/router'; |
| 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
| 5 | 5 | ||
| 6 | @Component({ | 6 | @Component({ |
| 7 | selector: 'app-pago-electronico', | 7 | selector: 'app-pago-electronico', |
| 8 | templateUrl: './pago-electronico.component.html', | 8 | templateUrl: './pago-electronico.component.html', |
| 9 | styleUrls: ['./pago-electronico.component.scss'] | 9 | styleUrls: ['./pago-electronico.component.scss'] |
| 10 | }) | 10 | }) |
| 11 | export class PagoElectronicoComponent implements OnInit { | 11 | export class PagoElectronicoComponent implements OnInit { |
| 12 | urlQr = `${APP_SETTINGS.apiDeboSuite}/qr/${APP_SETTINGS.numeroPlanilla}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`; | 12 | urlQr = `${APP_SETTINGS.apiDeboSuite}/qr/${APP_SETTINGS.numeroPlanilla}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`; |
| 13 | 13 | ||
| 14 | constructor( | 14 | constructor( |
| 15 | private articuloService: ArticuloService, | 15 | private articuloService: ArticuloService, |
| 16 | private router: Router, | 16 | private router: Router, |
| 17 | ) { } | 17 | ) { } |
| 18 | 18 | ||
| 19 | ngOnInit() { | 19 | ngOnInit() { |
| 20 | if (!this.articuloService.carrito.length) { | 20 | if (!this.articuloService.carrito.length) { |
| 21 | this.router.navigate(['']); | 21 | this.router.navigate(['']); |
| 22 | return; | 22 | return; |
| 23 | } | 23 | } |
| 24 | const dataPago = { | 24 | const dataPago = { |
| 25 | pedidoAnombreDe: '' | 25 | pedidoAnombreDe: '' |
| 26 | }; | 26 | }; |
| 27 | dataPago.pedidoAnombreDe = ''; | 27 | dataPago.pedidoAnombreDe = ''; |
| 28 | this.articuloService.pay(dataPago) | 28 | this.articuloService.pay(dataPago) |
| 29 | .subscribe((res: any) => { | 29 | .subscribe((res: any) => { |
| 30 | this.articuloService.idComanda = res.data; | 30 | this.articuloService.idComanda = res.data; |
| 31 | this.router.navigate(['mensaje-final']); | 31 | this.router.navigate(['mensaje-final']); |
| 32 | }, err => console.error(err)); | 32 | }, err => console.error(err)); |
| 33 | this.mediaPantalla(); | 33 | this.mediaPantalla(); |
| 34 | } | 34 | } |
| 35 | mediaPantalla() { | 35 | mediaPantalla() { |
| 36 | if ($('body').hasClass('media-pantalla')) { | 36 | if ($('body').hasClass('media-pantalla')) { |
| 37 | $('.qr-mt').addClass('media-pantalla'); | 37 | $('.qr-mt').addClass('media-pantalla'); |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 |
src/app/modules/seleccion-articulos/seleccion-articulos.component.ts
| 1 | import { Component, OnInit, OnDestroy, HostListener, ViewChild, AfterViewInit } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy, HostListener, ViewChild, AfterViewInit } 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 { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; | 8 | import { PromocionComponent } from 'src/app/shared/promocion/promocion.component'; |
| 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 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
| 11 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from 'src/app/shared/sinonimo/sinonimo.component'; |
| 12 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; | 12 | import { FiltroCategoriasComponent } from './filtro-categorias/filtro-categorias.component'; |
| 13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; |
| 14 | import { ANIMATIONS } from 'src/app/utils/animations'; | 14 | import { ANIMATIONS } from 'src/app/utils/animations'; |
| 15 | 15 | ||
| 16 | @Component({ | 16 | @Component({ |
| 17 | selector: 'app-seleccion-articulos', | 17 | selector: 'app-seleccion-articulos', |
| 18 | templateUrl: './seleccion-articulos.component.html', | 18 | templateUrl: './seleccion-articulos.component.html', |
| 19 | styleUrls: ['./seleccion-articulos.component.scss'], | 19 | styleUrls: ['./seleccion-articulos.component.scss'], |
| 20 | animations: [ANIMATIONS.EnterLeaveY] | 20 | animations: [ANIMATIONS.EnterLeaveY] |
| 21 | }) | 21 | }) |
| 22 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { | 22 | export class SeleccionArticulosComponent implements OnInit, AfterViewInit, OnDestroy { |
| 23 | showSpinner = true; | 23 | showSpinner = true; |
| 24 | timeoutHandler: any; | 24 | timeoutHandler: any; |
| 25 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 25 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
| 26 | articulos: IArticulo[] = []; | 26 | articulos: IArticulo[] = []; |
| 27 | auxArticulos: IArticulo[] = []; | 27 | auxArticulos: IArticulo[] = []; |
| 28 | showQuantity = 100; | 28 | showQuantity = 100; |
| 29 | searchTerm = ''; | 29 | searchTerm = ''; |
| 30 | ordenandoByVendidos = true; | 30 | ordenandoByVendidos = true; |
| 31 | modalRef: BsModalRef; | 31 | modalRef: BsModalRef; |
| 32 | total = 0; | 32 | total = 0; |
| 33 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; | 33 | @ViewChild(FiltroCategoriasComponent, { static: false }) filtroCategorias: FiltroCategoriasComponent; |
| 34 | 34 | ||
| 35 | constructor( | 35 | constructor( |
| 36 | public articuloService: ArticuloService, | 36 | public articuloService: ArticuloService, |
| 37 | private sinonimoService: SinonimoService, | 37 | private sinonimoService: SinonimoService, |
| 38 | private modalService: BsModalService, | 38 | private modalService: BsModalService, |
| 39 | private inactiveScreen: InactiveScreenService, | 39 | private inactiveScreen: InactiveScreenService, |
| 40 | ) { } | 40 | ) { } |
| 41 | 41 | ||
| 42 | ngOnInit() { } | 42 | ngOnInit() { } |
| 43 | 43 | ||
| 44 | ngAfterViewInit(): void { | 44 | ngAfterViewInit(): void { |
| 45 | this.filtroCategorias.getCategorias(); | 45 | this.filtroCategorias.getCategorias(); |
| 46 | this.mediaPantalla(); | 46 | this.mediaPantalla(); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | ngOnDestroy() { | 49 | ngOnDestroy() { |
| 50 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 50 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { |
| 51 | this.modalService.hide(i); | 51 | this.modalService.hide(i); |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | getProductos() { | 55 | getProductos() { |
| 56 | this.articuloService.getAll() | 56 | this.articuloService.getAll() |
| 57 | .subscribe((result: IArticulo[]) => { | 57 | .subscribe((result: IArticulo[]) => { |
| 58 | this.articuloService.setArticulosSinImagen(result); | 58 | this.articuloService.setArticulosSinImagen(result); |
| 59 | if (this.filtroCategorias.queMostrar === 'ordenar') { | 59 | if (this.filtroCategorias.queMostrar === 'ordenar') { |
| 60 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { | 60 | this.filtroCategorias.categorias.forEach((categoria: ICategoria) => { |
| 61 | const tempArticulos = result.filter((articulo: IArticulo) => { | 61 | const tempArticulos = result.filter((articulo: IArticulo) => { |
| 62 | return articulo.categoria_selfservice === categoria.id; | 62 | return articulo.categoria_selfservice === categoria.id; |
| 63 | }); | 63 | }); |
| 64 | result = tempArticulos; | 64 | result = tempArticulos; |
| 65 | }); | 65 | }); |
| 66 | } | 66 | } |
| 67 | localStorage.setItem('articulos', JSON.stringify(result)); | 67 | localStorage.setItem('articulos', JSON.stringify(result)); |
| 68 | this.setProductos(); | 68 | this.setProductos(); |
| 69 | }, (error) => { | 69 | }, (error) => { |
| 70 | this.showSpinner = false; | 70 | this.showSpinner = false; |
| 71 | console.error(error); | 71 | console.error(error); |
| 72 | }); | 72 | }); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | setProductos() { | 75 | setProductos() { |
| 76 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 76 | this.articulos = JSON.parse(localStorage.getItem('articulos')); |
| 77 | this.filterItems(); | 77 | this.filterItems(); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | filterItems() { | 80 | filterItems() { |
| 81 | if (this.filtroCategorias.categoriaActive === 0) { | 81 | if (this.filtroCategorias.categoriaActive === 0) { |
| 82 | this.auxArticulos = this.articulos; | 82 | this.auxArticulos = this.articulos; |
| 83 | return; | 83 | return; |
| 84 | } | 84 | } |
| 85 | this.auxArticulos = this.articulos.filter(x => { | 85 | this.auxArticulos = this.articulos.filter(x => { |
| 86 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; | 86 | return x.categoria_selfservice === this.filtroCategorias.categoriaActive; |
| 87 | }); | 87 | }); |
| 88 | this.ordenar(); | 88 | this.ordenar(); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | ordenar() { | 91 | ordenar() { |
| 92 | if (this.ordenandoByVendidos) { | 92 | if (this.ordenandoByVendidos) { |
| 93 | this.auxArticulos.sort((a, b) => { | 93 | this.auxArticulos.sort((a, b) => { |
| 94 | return b.cantidadVendida - a.cantidadVendida; | 94 | return b.cantidadVendida - a.cantidadVendida; |
| 95 | }); | 95 | }); |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | selectArticulo(articulo: IArticulo) { | 99 | selectArticulo(articulo: IArticulo) { |
| 100 | this.getByID(articulo.id); | 100 | this.getByID(articulo.id); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | getByID(id: number) { | 103 | getByID(id: number) { |
| 104 | this.articuloService.getById(id) | 104 | this.articuloService.getById(id) |
| 105 | .subscribe((res: IArticulo) => { | 105 | .subscribe((res: IArticulo) => { |
| 106 | if (res.FPP) { | 106 | if (res.FPP) { |
| 107 | this.openModalPromos(res); | 107 | this.openModalPromos(res); |
| 108 | } else { | 108 | } else { |
| 109 | this.getSinonimos(res); | 109 | this.getSinonimos(res); |
| 110 | } | 110 | } |
| 111 | }, err => console.error(err)); | 111 | }, err => console.error(err)); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | getSinonimos(articulo: IArticulo) { | 114 | getSinonimos(articulo: IArticulo) { |
| 115 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 115 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 116 | .subscribe((res: any[]) => { | 116 | .subscribe((res: any[]) => { |
| 117 | if (res.length) { | 117 | if (res.length) { |
| 118 | const sinonimos = []; | 118 | const sinonimos = []; |
| 119 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 119 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 120 | Object.keys(gruposArticulos).forEach(key => { | 120 | Object.keys(gruposArticulos).forEach(key => { |
| 121 | sinonimos.push({ productos: gruposArticulos[key] }); | 121 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 122 | }); | 122 | }); |
| 123 | res = sinonimos; | 123 | res = sinonimos; |
| 124 | this.openModalSinonimos(res, articulo); | 124 | this.openModalSinonimos(res, articulo); |
| 125 | } else { | 125 | } else { |
| 126 | this.articuloService.setArticulo(articulo); | 126 | this.articuloService.setArticulo(articulo); |
| 127 | } | 127 | } |
| 128 | }); | 128 | }); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | openModalPromos(articulo: IArticulo) { | 131 | openModalPromos(articulo: IArticulo) { |
| 132 | this.modalRef = this.modalService.show(PromocionComponent, { | 132 | this.modalRef = this.modalService.show(PromocionComponent, { |
| 133 | initialState: { articulosPromo: [articulo] }, | 133 | initialState: { articulosPromo: [articulo] }, |
| 134 | class: 'modal-promo modal-dialog-centered' | 134 | class: 'modal-promo modal-dialog-centered' |
| 135 | }); | 135 | }); |
| 136 | this.mediaPantalla(); | 136 | this.mediaPantalla(); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 139 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 140 | this.modalRef = this.modalService.show(SinonimoComponent, { | 140 | this.modalRef = this.modalService.show(SinonimoComponent, { |
| 141 | initialState: { sinonimos: sinonimosData }, | 141 | initialState: { sinonimos: sinonimosData }, |
| 142 | class: 'modal-promo modal-dialog-centered' | 142 | class: 'modal-promo modal-dialog-centered' |
| 143 | }); | 143 | }); |
| 144 | 144 | ||
| 145 | this.modalRef.content.onClose | 145 | this.modalRef.content.onClose |
| 146 | .subscribe((res: any) => { | 146 | .subscribe((res: any) => { |
| 147 | for (const a of articulo.productos) { | 147 | for (const a of articulo.productos) { |
| 148 | for (const aRes of res.articulos) { | 148 | for (const aRes of res.articulos) { |
| 149 | if (a.idSinonimo === aRes.ID_SIN) { | 149 | if (a.idSinonimo === aRes.ID_SIN) { |
| 150 | a.CODA = aRes.CodArt; | 150 | a.CODA = aRes.CodArt; |
| 151 | a.CodArt = aRes.CodArt; | 151 | a.CodArt = aRes.CodArt; |
| 152 | a.SECA = aRes.CodSec; | 152 | a.SECA = aRes.CodSec; |
| 153 | aRes.CodSec = aRes.CodSec; | 153 | aRes.CodSec = aRes.CodSec; |
| 154 | a.PreVen = aRes.PreVen; | 154 | a.PreVen = aRes.PreVen; |
| 155 | a.id = aRes.id; | 155 | a.id = aRes.id; |
| 156 | a.DET_LAR = aRes.DET_LAR; | 156 | a.DET_LAR = aRes.DET_LAR; |
| 157 | a.DetArt = aRes.DetArt; | 157 | a.DetArt = aRes.DetArt; |
| 158 | } | 158 | } |
| 159 | } | 159 | } |
| 160 | } | 160 | } |
| 161 | this.articuloService.setArticulo(articulo); | 161 | this.articuloService.setArticulo(articulo); |
| 162 | }); | 162 | }); |
| 163 | this.mediaPantalla(); | 163 | this.mediaPantalla(); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | deleteArticulo(index: number) { | 166 | deleteArticulo(index: number) { |
| 167 | this.articuloService.deleteArticulo(index); | 167 | this.articuloService.deleteArticulo(index); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | increaseShow() { | 170 | increaseShow() { |
| 171 | this.showQuantity += 100; | 171 | this.showQuantity += 100; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | @HostListener('scroll', ['$event']) | 174 | @HostListener('scroll', ['$event']) |
| 175 | scrollEvent(event: Event) { | 175 | scrollEvent(event: Event) { |
| 176 | clearTimeout(this.inactiveScreen.timerReposo); | 176 | clearTimeout(this.inactiveScreen.timerReposo); |
| 177 | this.inactiveScreen.startTimeOutInactividad(); | 177 | this.inactiveScreen.startTimeOutInactividad(); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | mouseup() { | 180 | mouseup() { |
| 181 | if (!this.timeoutHandler) return; | 181 | if (!this.timeoutHandler) return; |
| 182 | clearInterval(this.timeoutHandler); | 182 | clearInterval(this.timeoutHandler); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | scrollY(el: HTMLElement, value) { | 185 | scrollY(el: HTMLElement, value) { |
| 186 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 186 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 187 | this.timeoutHandler = setInterval(() => { | 187 | this.timeoutHandler = setInterval(() => { |
| 188 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 188 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 189 | }, 500); | 189 | }, 500); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | scrollX(el: HTMLElement, value) { | 192 | scrollX(el: HTMLElement, value) { |
| 193 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 193 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 194 | this.timeoutHandler = setInterval(() => { | 194 | this.timeoutHandler = setInterval(() => { |
| 195 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 195 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 196 | }, 500); | 196 | }, 500); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | mediaPantalla() { | 199 | mediaPantalla() { |
| 200 | if ($('body').hasClass('media-pantalla')) { | 200 | if ($('body').hasClass('media-pantalla')) { |
| 201 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 201 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
| 202 | .cat-box,.img-categoria, .modal-content`) | 202 | .cat-box,.img-categoria, .modal-content`) |
| 203 | .addClass('media-pantalla') | 203 | .addClass('media-pantalla') |
| 204 | .addBack('media-pantalla'); | 204 | .addBack('media-pantalla'); |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | } | 207 | } |
| 208 | 208 |
src/app/shared/promocion/promocion.component.ts
| 1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; |
| 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
| 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; | 5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; |
| 6 | import { Subject } from 'rxjs'; | 6 | import { Subject } from 'rxjs'; |
| 7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
| 8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
| 9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
| 10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
| 11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
| 12 | import * as _ from 'lodash'; | 12 | import * as _ from 'lodash'; |
| 13 | 13 | ||
| 14 | @Component({ | 14 | @Component({ |
| 15 | selector: 'app-promocion', | 15 | selector: 'app-promocion', |
| 16 | templateUrl: './promocion.component.html', | 16 | templateUrl: './promocion.component.html', |
| 17 | styleUrls: ['./promocion.component.scss'] | 17 | styleUrls: ['./promocion.component.scss'] |
| 18 | }) | 18 | }) |
| 19 | export class PromocionComponent implements OnInit { | 19 | export class PromocionComponent implements OnInit { |
| 20 | articulosPromo: IArticulo[] = []; | 20 | articulosPromo: IArticulo[] = []; |
| 21 | promociones: IArticulo[] = []; | 21 | promociones: IArticulo[] = []; |
| 22 | onClose: Subject<any>; | 22 | onClose: Subject<any>; |
| 23 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 23 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
| 24 | 24 | ||
| 25 | constructor( | 25 | constructor( |
| 26 | public modalPromocion: BsModalRef, | 26 | public modalPromocion: BsModalRef, |
| 27 | private modalService: BsModalService, | 27 | private modalService: BsModalService, |
| 28 | private articuloService: ArticuloService, | 28 | private articuloService: ArticuloService, |
| 29 | private promocionService: PromocionService, | 29 | private promocionService: PromocionService, |
| 30 | private sinonimoService: SinonimoService, | 30 | private sinonimoService: SinonimoService, |
| 31 | private inactiveScreen: InactiveScreenService, | 31 | private inactiveScreen: InactiveScreenService, |
| 32 | ) { | 32 | ) { |
| 33 | this.onClose = new Subject(); | 33 | this.onClose = new Subject(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | ngOnInit() { | 36 | ngOnInit() { |
| 37 | this.getPromociones(); | 37 | this.getPromociones(); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | selectPromo(promo: IArticulo) { | 40 | selectPromo(promo: IArticulo) { |
| 41 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 41 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
| 42 | .subscribe((res: ISinonimo[]) => { | 42 | .subscribe((res: ISinonimo[]) => { |
| 43 | if (res.length) { | 43 | if (res.length) { |
| 44 | const sinonimos = []; | 44 | const sinonimos = []; |
| 45 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 45 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 46 | Object.keys(gruposArticulos).forEach(key => { | 46 | Object.keys(gruposArticulos).forEach(key => { |
| 47 | sinonimos.push({ productos: gruposArticulos[key] }); | 47 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 48 | }); | 48 | }); |
| 49 | res = sinonimos; | 49 | res = sinonimos; |
| 50 | this.openModalSinonimos(res, promo); | 50 | this.openModalSinonimos(res, promo); |
| 51 | } else { | 51 | } else { |
| 52 | promo.cantidad = 1; | 52 | promo.cantidad = 1; |
| 53 | this.articuloService.setArticulo(promo); | 53 | this.articuloService.setArticulo(promo); |
| 54 | this.modalPromocion.hide(); | 54 | this.modalPromocion.hide(); |
| 55 | } | 55 | } |
| 56 | }, err => console.error(err)); | 56 | }, err => console.error(err)); |
| 57 | this.mediaPantalla(); | 57 | this.mediaPantalla(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 60 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 61 | console.log('lanzado open sinonimos'); | ||
| 62 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 61 | const modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 63 | initialState: { sinonimos: sinonimosData }, | 62 | initialState: { sinonimos: sinonimosData }, |
| 64 | class: 'modal-promo modal-dialog-centered' | 63 | class: 'modal-promo modal-dialog-centered' |
| 65 | }); | 64 | }); |
| 66 | 65 | ||
| 67 | modalSinonimo.content.onClose | 66 | modalSinonimo.content.onClose |
| 68 | .subscribe((res: any) => { | 67 | .subscribe((res: any) => { |
| 69 | for (const a of articulo.productos) { | 68 | for (const a of articulo.productos) { |
| 70 | for (const aRes of res.articulos) { | 69 | for (const aRes of res.articulos) { |
| 71 | if (a.idSinonimo === aRes.ID_SIN) { | 70 | if (a.idSinonimo === aRes.ID_SIN) { |
| 72 | a.CODA = aRes.CodArt; | 71 | a.CODA = aRes.CodArt; |
| 73 | a.CodArt = aRes.CodArt; | 72 | a.CodArt = aRes.CodArt; |
| 74 | a.SECA = aRes.CodSec; | 73 | a.SECA = aRes.CodSec; |
| 75 | aRes.CodSec = aRes.CodSec; | 74 | aRes.CodSec = aRes.CodSec; |
| 76 | a.PreVen = aRes.PreVen; | 75 | a.PreVen = aRes.PreVen; |
| 77 | a.id = aRes.id; | 76 | a.id = aRes.id; |
| 78 | a.DET_LAR = aRes.DET_LAR; | 77 | a.DET_LAR = aRes.DET_LAR; |
| 79 | a.DetArt = aRes.DetArt; | 78 | a.DetArt = aRes.DetArt; |
| 80 | } | 79 | } |
| 81 | } | 80 | } |
| 82 | } | 81 | } |
| 83 | this.articuloService.setArticulo(articulo); | 82 | this.articuloService.setArticulo(articulo); |
| 84 | this.modalPromocion.hide(); | 83 | this.modalPromocion.hide(); |
| 85 | }); | 84 | }); |
| 86 | } | 85 | } |
| 87 | 86 | ||
| 88 | getPromociones() { | 87 | getPromociones() { |
| 89 | const sector = this.articulosPromo[0].CodSec; | 88 | const sector = this.articulosPromo[0].CodSec; |
| 90 | const codigo = this.articulosPromo[0].CodArt; | 89 | const codigo = this.articulosPromo[0].CodArt; |
| 91 | this.promocionService.getPromociones(sector, codigo) | 90 | this.promocionService.getPromociones(sector, codigo) |
| 92 | .subscribe((res: IArticulo[]) => { | 91 | .subscribe((res: IArticulo[]) => { |
| 93 | this.promociones = res; | 92 | this.promociones = res; |
| 94 | }, error => { console.error(error); }); | 93 | }, error => { console.error(error); }); |
| 95 | } | 94 | } |
| 96 | 95 | ||
| 97 | @HostListener('document:click', ['$event']) | 96 | @HostListener('document:click', ['$event']) |
| 98 | eventListener(event: Event) { | 97 | eventListener(event: Event) { |
| 99 | clearTimeout(this.inactiveScreen.timerReposo); | 98 | clearTimeout(this.inactiveScreen.timerReposo); |
| 100 | this.inactiveScreen.startTimeOutInactividad(); | 99 | this.inactiveScreen.startTimeOutInactividad(); |
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | @HostListener('scroll', ['$event']) | 102 | @HostListener('scroll', ['$event']) |
| 104 | scrollEvent(event: Event) { | 103 | scrollEvent(event: Event) { |
| 105 | clearTimeout(this.inactiveScreen.timerReposo); | 104 | clearTimeout(this.inactiveScreen.timerReposo); |
| 106 | this.inactiveScreen.startTimeOutInactividad(); | 105 | this.inactiveScreen.startTimeOutInactividad(); |
| 107 | } | 106 | } |
| 108 | 107 | ||
| 109 | mediaPantalla() { | 108 | mediaPantalla() { |
| 110 | if ($('body').hasClass('media-pantalla')) { | 109 | if ($('body').hasClass('media-pantalla')) { |
| 111 | $('.modal-content').addClass('media-pantalla'); | 110 | $('.modal-content').addClass('media-pantalla'); |
| 112 | } | 111 | } |
| 113 | } | 112 | } |
| 114 | } | 113 | } |
| 115 | 114 |
src/app/shared/sinonimo/sinonimo.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
| 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
| 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; |
| 5 | import { Subject, forkJoin } from 'rxjs'; | 5 | import { Subject, forkJoin } from 'rxjs'; |
| 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 7 | import { element } from 'protractor'; | 7 | import { element } from 'protractor'; |
| 8 | 8 | ||
| 9 | @Component({ | 9 | @Component({ |
| 10 | selector: 'app-sinonimo', | 10 | selector: 'app-sinonimo', |
| 11 | templateUrl: './sinonimo.component.html', | 11 | templateUrl: './sinonimo.component.html', |
| 12 | styleUrls: ['./sinonimo.component.scss'] | 12 | styleUrls: ['./sinonimo.component.scss'] |
| 13 | }) | 13 | }) |
| 14 | export class SinonimoComponent implements OnInit { | 14 | export class SinonimoComponent implements OnInit { |
| 15 | sinonimos: ISinonimo[] = []; | 15 | sinonimos: ISinonimo[] = []; |
| 16 | isValid: boolean; | 16 | isValid: boolean; |
| 17 | onClose: Subject<any>; | 17 | onClose: Subject<any>; |
| 18 | articulosSelected: IArticulo[] = []; | 18 | articulosSelected: IArticulo[] = []; |
| 19 | 19 | ||
| 20 | constructor( | 20 | constructor( |
| 21 | private modalRef: BsModalRef, | 21 | private modalRef: BsModalRef, |
| 22 | private articuloService: ArticuloService, | 22 | private articuloService: ArticuloService, |
| 23 | ) { | 23 | ) { |
| 24 | this.onClose = new Subject(); | 24 | this.onClose = new Subject(); |
| 25 | this.articulosSelected.length = this.sinonimos.length; | 25 | this.articulosSelected.length = this.sinonimos.length; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | ngOnInit() { } | 28 | ngOnInit() { } |
| 29 | 29 | ||
| 30 | selectSinonimo(index: number, articulo: IArticulo) { | 30 | selectSinonimo(index: number, articulo: IArticulo) { |
| 31 | for (const a of this.sinonimos[index].productos) { | 31 | for (const a of this.sinonimos[index].productos) { |
| 32 | a.seleccionado = false; | 32 | a.seleccionado = false; |
| 33 | } | 33 | } |
| 34 | articulo.seleccionado = true; | 34 | articulo.seleccionado = true; |
| 35 | this.articulosSelected[index] = articulo; | 35 | this.articulosSelected[index] = articulo; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | validate() { | 38 | validate() { |
| 39 | this.isValid = true; | 39 | this.isValid = true; |
| 40 | for (const s of this.sinonimos) { | 40 | for (const s of this.sinonimos) { |
| 41 | for (const a of s.productos) { | 41 | for (const a of s.productos) { |
| 42 | this.isValid = (!a.seleccionado) ? false : true; | 42 | this.isValid = (!a.seleccionado) ? false : true; |
| 43 | if (this.isValid) break; | 43 | if (this.isValid) break; |
| 44 | } | 44 | } |
| 45 | if (!this.isValid) break; | 45 | if (!this.isValid) break; |
| 46 | } | 46 | } |
| 47 | return !this.isValid ? 'disabled' : 'btn-effect'; | 47 | return !this.isValid ? 'disabled' : 'btn-effect'; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | continue() { | 50 | continue() { |
| 51 | if (!this.isValid) return; | 51 | if (!this.isValid) return; |
| 52 | const ID_SINS = []; | 52 | const ID_SINS = []; |
| 53 | const observables = []; | 53 | const observables = []; |
| 54 | 54 | ||
| 55 | for (const articulo of this.articulosSelected) { | 55 | for (const articulo of this.articulosSelected) { |
| 56 | ID_SINS.push(articulo.ID_SIN); | 56 | ID_SINS.push(articulo.ID_SIN); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | for (const articulo of this.articulosSelected) { | 59 | for (const articulo of this.articulosSelected) { |
| 60 | observables.push(this.articuloService.getById(articulo.id)); | 60 | observables.push(this.articuloService.getById(articulo.id)); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | forkJoin(observables) | 63 | forkJoin(observables) |
| 64 | .subscribe((res: IArticulo[]) => { | 64 | .subscribe((res: IArticulo[]) => { |
| 65 | for (const articulo of res) { | 65 | for (const articulo of res) { |
| 66 | for (const ID_SIN of ID_SINS) { | 66 | for (const ID_SIN of ID_SINS) { |
| 67 | articulo.ID_SIN = ID_SIN; | 67 | articulo.ID_SIN = ID_SIN; |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | this.modalRef.hide(); | 70 | this.modalRef.hide(); |
| 71 | this.onClose.next({ | 71 | this.onClose.next({ |
| 72 | articulos: res, | 72 | articulos: res, |
| 73 | }); | 73 | }); |
| 74 | }, err => console.error(err)); | 74 | }, err => console.error(err)); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | scrollTo(index: number) { | 77 | scrollTo(index: number) { |
| 78 | const element = document.getElementById(index.toString()); | 78 | const element = document.getElementById(index.toString()); |
| 79 | element.scrollIntoView({ behavior: "smooth", block: "center" }); | 79 | element.scrollIntoView({ behavior: 'smooth', block: 'center' }); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | } | 82 | } |
| 83 | 83 |