Commit 1a63ba6d41b56b7fd83431ee8dcfff76d616f326
1 parent
609df1b541
Exists in
develop
Fix
Lint rules
Showing
3 changed files
with
3 additions
and
3 deletions
Show diff stats
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: { | 141 | initialState: { |
| 142 | sinonimos: sinonimosData, | 142 | sinonimos: sinonimosData, |
| 143 | articulo: articulo | 143 | articulo |
| 144 | }, | 144 | }, |
| 145 | class: 'modal-promo modal-dialog-centered' | 145 | class: 'modal-promo modal-dialog-centered' |
| 146 | }); | 146 | }); |
| 147 | 147 | ||
| 148 | this.modalRef.content.onClose | 148 | this.modalRef.content.onClose |
| 149 | .subscribe((res: any) => { | 149 | .subscribe((res: any) => { |
| 150 | for (const a of articulo.productos) { | 150 | for (const a of articulo.productos) { |
| 151 | for (const aRes of res.articulos) { | 151 | for (const aRes of res.articulos) { |
| 152 | if (a.idSinonimo === aRes.ID_SIN) { | 152 | if (a.idSinonimo === aRes.ID_SIN) { |
| 153 | a.CODA = aRes.CodArt; | 153 | a.CODA = aRes.CodArt; |
| 154 | a.CodArt = aRes.CodArt; | 154 | a.CodArt = aRes.CodArt; |
| 155 | a.SECA = aRes.CodSec; | 155 | a.SECA = aRes.CodSec; |
| 156 | aRes.CodSec = aRes.CodSec; | 156 | aRes.CodSec = aRes.CodSec; |
| 157 | a.PreVen = aRes.PreVen; | 157 | a.PreVen = aRes.PreVen; |
| 158 | a.id = aRes.id; | 158 | a.id = aRes.id; |
| 159 | a.DET_LAR = aRes.DET_LAR; | 159 | a.DET_LAR = aRes.DET_LAR; |
| 160 | a.DetArt = aRes.DetArt; | 160 | a.DetArt = aRes.DetArt; |
| 161 | } | 161 | } |
| 162 | } | 162 | } |
| 163 | } | 163 | } |
| 164 | this.articuloService.setArticulo(articulo); | 164 | this.articuloService.setArticulo(articulo); |
| 165 | }); | 165 | }); |
| 166 | this.mediaPantalla(); | 166 | this.mediaPantalla(); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | deleteArticulo(index: number) { | 169 | deleteArticulo(index: number) { |
| 170 | this.articuloService.deleteArticulo(index); | 170 | this.articuloService.deleteArticulo(index); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | increaseShow() { | 173 | increaseShow() { |
| 174 | this.showQuantity += 100; | 174 | this.showQuantity += 100; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | @HostListener('scroll', ['$event']) | 177 | @HostListener('scroll', ['$event']) |
| 178 | scrollEvent(event: Event) { | 178 | scrollEvent(event: Event) { |
| 179 | clearTimeout(this.inactiveScreen.timerReposo); | 179 | clearTimeout(this.inactiveScreen.timerReposo); |
| 180 | this.inactiveScreen.startTimeOutInactividad(); | 180 | this.inactiveScreen.startTimeOutInactividad(); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | mouseup() { | 183 | mouseup() { |
| 184 | if (!this.timeoutHandler) return; | 184 | if (!this.timeoutHandler) return; |
| 185 | clearInterval(this.timeoutHandler); | 185 | clearInterval(this.timeoutHandler); |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | scrollY(el: HTMLElement, value) { | 188 | scrollY(el: HTMLElement, value) { |
| 189 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 189 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 190 | this.timeoutHandler = setInterval(() => { | 190 | this.timeoutHandler = setInterval(() => { |
| 191 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 191 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
| 192 | }, 500); | 192 | }, 500); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | scrollX(el: HTMLElement, value) { | 195 | scrollX(el: HTMLElement, value) { |
| 196 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 196 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 197 | this.timeoutHandler = setInterval(() => { | 197 | this.timeoutHandler = setInterval(() => { |
| 198 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 198 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); |
| 199 | }, 500); | 199 | }, 500); |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | mediaPantalla() { | 202 | mediaPantalla() { |
| 203 | if ($('body').hasClass('media-pantalla')) { | 203 | if ($('body').hasClass('media-pantalla')) { |
| 204 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 204 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, |
| 205 | .cat-box,.img-categoria, .modal-content`) | 205 | .cat-box,.img-categoria, .modal-content`) |
| 206 | .addClass('media-pantalla') | 206 | .addClass('media-pantalla') |
| 207 | .addBack('media-pantalla'); | 207 | .addBack('media-pantalla'); |
| 208 | } | 208 | } |
| 209 | } | 209 | } |
| 210 | } | 210 | } |
| 211 | 211 |
src/app/shared/header-publicidad/header-publicidad.component.ts
| 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; | 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; |
| 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
| 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; | 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; |
| 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; | 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; |
| 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 6 | import { PromocionComponent } from '../promocion/promocion.component'; | 6 | import { PromocionComponent } from '../promocion/promocion.component'; |
| 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; | 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; |
| 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; | 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; |
| 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
| 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
| 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
| 13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; |
| 14 | 14 | ||
| 15 | @Component({ | 15 | @Component({ |
| 16 | selector: 'app-header-publicidad', | 16 | selector: 'app-header-publicidad', |
| 17 | templateUrl: './header-publicidad.component.html', | 17 | templateUrl: './header-publicidad.component.html', |
| 18 | styleUrls: ['./header-publicidad.component.scss'] | 18 | styleUrls: ['./header-publicidad.component.scss'] |
| 19 | }) | 19 | }) |
| 20 | export class HeaderPublicidadComponent implements OnInit { | 20 | export class HeaderPublicidadComponent implements OnInit { |
| 21 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 21 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
| 22 | publicidades: IPublicidad[] = []; | 22 | publicidades: IPublicidad[] = []; |
| 23 | modalRef: BsModalRef; | 23 | modalRef: BsModalRef; |
| 24 | 24 | ||
| 25 | constructor( | 25 | constructor( |
| 26 | private publicidadService: PublicidadService, | 26 | private publicidadService: PublicidadService, |
| 27 | private articuloService: ArticuloService, | 27 | private articuloService: ArticuloService, |
| 28 | private modalService: BsModalService, | 28 | private modalService: BsModalService, |
| 29 | private sinonimoService: SinonimoService | 29 | private sinonimoService: SinonimoService |
| 30 | ) { } | 30 | ) { } |
| 31 | 31 | ||
| 32 | ngOnInit() { | 32 | ngOnInit() { |
| 33 | this.getPublicidades(); | 33 | this.getPublicidades(); |
| 34 | this.mediaPantalla(); | 34 | this.mediaPantalla(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | getPublicidades() { | 37 | getPublicidades() { |
| 38 | this.publicidadService.getAll() | 38 | this.publicidadService.getAll() |
| 39 | .subscribe((res: IPublicidad[]) => { | 39 | .subscribe((res: IPublicidad[]) => { |
| 40 | this.publicidades = res; | 40 | this.publicidades = res; |
| 41 | }, err => console.error(err)); | 41 | }, err => console.error(err)); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | elegirArticulo(publicidad: IPublicidad) { | 44 | elegirArticulo(publicidad: IPublicidad) { |
| 45 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 45 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | getByID(id: number) { | 48 | getByID(id: number) { |
| 49 | this.articuloService.getById(id) | 49 | this.articuloService.getById(id) |
| 50 | .subscribe((res: IArticulo) => { | 50 | .subscribe((res: IArticulo) => { |
| 51 | if (res.FPP) { | 51 | if (res.FPP) { |
| 52 | this.openModalPromos(res); | 52 | this.openModalPromos(res); |
| 53 | return; | 53 | return; |
| 54 | } else { | 54 | } else { |
| 55 | this.openModalConfirmacion(res); | 55 | this.openModalConfirmacion(res); |
| 56 | return; | 56 | return; |
| 57 | } | 57 | } |
| 58 | }, err => console.error(err)); | 58 | }, err => console.error(err)); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | openModalPromos(articulo: IArticulo) { | 61 | openModalPromos(articulo: IArticulo) { |
| 62 | this.modalRef = this.modalService.show(PromocionComponent, | 62 | this.modalRef = this.modalService.show(PromocionComponent, |
| 63 | { | 63 | { |
| 64 | initialState: { | 64 | initialState: { |
| 65 | idArticulo: articulo.id | 65 | idArticulo: articulo.id |
| 66 | }, | 66 | }, |
| 67 | class: 'modal-promo modal-dialog-centered' | 67 | class: 'modal-promo modal-dialog-centered' |
| 68 | }); | 68 | }); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | openModalConfirmacion(articulo: IArticulo) { | 71 | openModalConfirmacion(articulo: IArticulo) { |
| 72 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 72 | this.modalRef = this.modalService.show(ConfirmacionComponent, |
| 73 | { | 73 | { |
| 74 | initialState: { | 74 | initialState: { |
| 75 | titleMessage: articulo.DET_LAR, | 75 | titleMessage: articulo.DET_LAR, |
| 76 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 76 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', |
| 77 | footerMessageFirst: `¿DESEA AGREGAR ESTE ARTÍCULO`, | 77 | footerMessageFirst: `¿DESEA AGREGAR ESTE ARTÍCULO`, |
| 78 | footerMessageSecond: `a su carrito?`, | 78 | footerMessageSecond: `a su carrito?`, |
| 79 | footerConfirmation: articulo.PreVen, | 79 | footerConfirmation: articulo.PreVen, |
| 80 | footerClose: `volver` | 80 | footerClose: `volver` |
| 81 | }, | 81 | }, |
| 82 | class: 'modal-promo modal-dialog-centered' | 82 | class: 'modal-promo modal-dialog-centered' |
| 83 | }); | 83 | }); |
| 84 | this.modalRef.content.onClose.subscribe(() => { | 84 | this.modalRef.content.onClose.subscribe(() => { |
| 85 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 85 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) |
| 86 | .subscribe((res: ISinonimo[]) => { | 86 | .subscribe((res: ISinonimo[]) => { |
| 87 | if (res.length) { | 87 | if (res.length) { |
| 88 | const sinonimos = []; | 88 | const sinonimos = []; |
| 89 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 89 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 90 | Object.keys(gruposArticulos).forEach(key => { | 90 | Object.keys(gruposArticulos).forEach(key => { |
| 91 | sinonimos.push({ productos: gruposArticulos[key] }); | 91 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 92 | }); | 92 | }); |
| 93 | res = sinonimos; | 93 | res = sinonimos; |
| 94 | this.openModalSinonimos(res, articulo); | 94 | this.openModalSinonimos(res, articulo); |
| 95 | } else { | 95 | } else { |
| 96 | articulo.cantidad = 1; | 96 | articulo.cantidad = 1; |
| 97 | this.articuloService.setArticulo(articulo); | 97 | this.articuloService.setArticulo(articulo); |
| 98 | } | 98 | } |
| 99 | }, err => console.error(err)); | 99 | }, err => console.error(err)); |
| 100 | }); | 100 | }); |
| 101 | this.mediaPantalla(); | 101 | this.mediaPantalla(); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 104 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 105 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 105 | const modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 106 | initialState: { | 106 | initialState: { |
| 107 | sinonimos: sinonimosData, | 107 | sinonimos: sinonimosData, |
| 108 | articulo: articulo | 108 | articulo |
| 109 | }, | 109 | }, |
| 110 | class: 'modal-promo modal-dialog-centered' | 110 | class: 'modal-promo modal-dialog-centered' |
| 111 | }); | 111 | }); |
| 112 | modalSinonimo.content.onClose | 112 | modalSinonimo.content.onClose |
| 113 | .subscribe((res: any) => { | 113 | .subscribe((res: any) => { |
| 114 | for (const a of articulo.productos) { | 114 | for (const a of articulo.productos) { |
| 115 | for (const aRes of res.articulos) { | 115 | for (const aRes of res.articulos) { |
| 116 | if (a.idSinonimo === aRes.ID_SIN) { | 116 | if (a.idSinonimo === aRes.ID_SIN) { |
| 117 | a.CODA = aRes.CodArt; | 117 | a.CODA = aRes.CodArt; |
| 118 | a.CodArt = aRes.CodArt; | 118 | a.CodArt = aRes.CodArt; |
| 119 | a.SECA = aRes.CodSec; | 119 | a.SECA = aRes.CodSec; |
| 120 | aRes.CodSec = aRes.CodSec; | 120 | aRes.CodSec = aRes.CodSec; |
| 121 | a.PreVen = aRes.PreVen; | 121 | a.PreVen = aRes.PreVen; |
| 122 | a.id = aRes.id; | 122 | a.id = aRes.id; |
| 123 | a.DET_LAR = aRes.DET_LAR; | 123 | a.DET_LAR = aRes.DET_LAR; |
| 124 | a.DetArt = aRes.DetArt; | 124 | a.DetArt = aRes.DetArt; |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | this.articuloService.setArticulo(articulo); | 128 | this.articuloService.setArticulo(articulo); |
| 129 | }); | 129 | }); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | mediaPantalla() { | 132 | mediaPantalla() { |
| 133 | if ($('body').hasClass('media-pantalla')) { | 133 | if ($('body').hasClass('media-pantalla')) { |
| 134 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 134 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | 138 |
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 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 61 | const modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 62 | initialState: { | 62 | initialState: { |
| 63 | sinonimos: sinonimosData, | 63 | sinonimos: sinonimosData, |
| 64 | articulo: articulo | 64 | articulo |
| 65 | }, | 65 | }, |
| 66 | class: 'modal-promo modal-dialog-centered' | 66 | class: 'modal-promo modal-dialog-centered' |
| 67 | }); | 67 | }); |
| 68 | 68 | ||
| 69 | modalSinonimo.content.onClose | 69 | modalSinonimo.content.onClose |
| 70 | .subscribe((res: any) => { | 70 | .subscribe((res: any) => { |
| 71 | for (const a of articulo.productos) { | 71 | for (const a of articulo.productos) { |
| 72 | for (const aRes of res.articulos) { | 72 | for (const aRes of res.articulos) { |
| 73 | if (a.idSinonimo === aRes.ID_SIN) { | 73 | if (a.idSinonimo === aRes.ID_SIN) { |
| 74 | a.CODA = aRes.CodArt; | 74 | a.CODA = aRes.CodArt; |
| 75 | a.CodArt = aRes.CodArt; | 75 | a.CodArt = aRes.CodArt; |
| 76 | a.SECA = aRes.CodSec; | 76 | a.SECA = aRes.CodSec; |
| 77 | aRes.CodSec = aRes.CodSec; | 77 | aRes.CodSec = aRes.CodSec; |
| 78 | a.PreVen = aRes.PreVen; | 78 | a.PreVen = aRes.PreVen; |
| 79 | a.id = aRes.id; | 79 | a.id = aRes.id; |
| 80 | a.DET_LAR = aRes.DET_LAR; | 80 | a.DET_LAR = aRes.DET_LAR; |
| 81 | a.DetArt = aRes.DetArt; | 81 | a.DetArt = aRes.DetArt; |
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | this.articuloService.setArticulo(articulo); | 85 | this.articuloService.setArticulo(articulo); |
| 86 | this.modalPromocion.hide(); | 86 | this.modalPromocion.hide(); |
| 87 | }); | 87 | }); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | getPromociones() { | 90 | getPromociones() { |
| 91 | const sector = this.articulosPromo[0].CodSec; | 91 | const sector = this.articulosPromo[0].CodSec; |
| 92 | const codigo = this.articulosPromo[0].CodArt; | 92 | const codigo = this.articulosPromo[0].CodArt; |
| 93 | this.promocionService.getPromociones(sector, codigo) | 93 | this.promocionService.getPromociones(sector, codigo) |
| 94 | .subscribe((res: IArticulo[]) => { | 94 | .subscribe((res: IArticulo[]) => { |
| 95 | this.promociones = res; | 95 | this.promociones = res; |
| 96 | }, error => { console.error(error); }); | 96 | }, error => { console.error(error); }); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | @HostListener('document:click', ['$event']) | 99 | @HostListener('document:click', ['$event']) |
| 100 | eventListener(event: Event) { | 100 | eventListener(event: Event) { |
| 101 | clearTimeout(this.inactiveScreen.timerReposo); | 101 | clearTimeout(this.inactiveScreen.timerReposo); |
| 102 | this.inactiveScreen.startTimeOutInactividad(); | 102 | this.inactiveScreen.startTimeOutInactividad(); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | @HostListener('scroll', ['$event']) | 105 | @HostListener('scroll', ['$event']) |
| 106 | scrollEvent(event: Event) { | 106 | scrollEvent(event: Event) { |
| 107 | clearTimeout(this.inactiveScreen.timerReposo); | 107 | clearTimeout(this.inactiveScreen.timerReposo); |
| 108 | this.inactiveScreen.startTimeOutInactividad(); | 108 | this.inactiveScreen.startTimeOutInactividad(); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | mediaPantalla() { | 111 | mediaPantalla() { |
| 112 | if ($('body').hasClass('media-pantalla')) { | 112 | if ($('body').hasClass('media-pantalla')) { |
| 113 | $('.modal-content').addClass('media-pantalla'); | 113 | $('.modal-content').addClass('media-pantalla'); |
| 114 | } | 114 | } |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 |