Commit f1c447c3021b76a592a590dc71d30fa399ef71b2
Exists in
develop
Merge branch 'master' into 'develop'
Master(benjamin) See merge request !92
Showing
2 changed files
 
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 | loading = true; | 23 | loading = true; | 
| 24 | timeoutHandler: any; | 24 | timeoutHandler: any; | 
| 25 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 25 | urlImagenes = `${APP_SETTINGS.apiImagenes}/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 | console.error(error); | 70 | console.error(error); | 
| 71 | }); | 71 | }); | 
| 72 | } | 72 | } | 
| 73 | 73 | ||
| 74 | setProductos() { | 74 | setProductos() { | 
| 75 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 75 | this.articulos = JSON.parse(localStorage.getItem('articulos')); | 
| 76 | this.filterItems(); | 76 | this.filterItems(); | 
| 77 | this.loading = false; | 77 | this.loading = false; | 
| 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.articuloService.setArticulosSinImagen([articulo]); | ||
| 132 | this.modalRef = this.modalService.show(PromocionComponent, { | 133 | this.modalRef = this.modalService.show(PromocionComponent, { | 
| 133 | initialState: { articulosPromo: [articulo] }, | 134 | initialState: { articulosPromo: [articulo] }, | 
| 134 | class: 'modal-dialog-centered' | 135 | class: 'modal-dialog-centered' | 
| 135 | }); | 136 | }); | 
| 136 | this.mediaPantalla(); | 137 | this.mediaPantalla(); | 
| 137 | } | 138 | } | 
| 138 | 139 | ||
| 139 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 140 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 140 | this.modalRef = this.modalService.show(SinonimoComponent, { | 141 | this.modalRef = this.modalService.show(SinonimoComponent, { | 
| 141 | initialState: { | 142 | initialState: { | 
| 142 | sinonimos: sinonimosData, | 143 | sinonimos: sinonimosData, | 
| 143 | articulo | 144 | articulo | 
| 144 | }, | 145 | }, | 
| 145 | class: 'modal-dialog-centered' | 146 | class: 'modal-dialog-centered' | 
| 146 | }); | 147 | }); | 
| 147 | 148 | ||
| 148 | this.modalRef.content.onClose | 149 | this.modalRef.content.onClose | 
| 149 | .subscribe((res: any) => { | 150 | .subscribe((res: any) => { | 
| 150 | for (const a of articulo.productos) { | 151 | for (const a of articulo.productos) { | 
| 151 | for (const aRes of res.articulos) { | 152 | for (const aRes of res.articulos) { | 
| 152 | if (a.idSinonimo === aRes.ID_SIN) { | 153 | if (a.idSinonimo === aRes.ID_SIN) { | 
| 153 | a.CODA = aRes.CodArt; | 154 | a.CODA = aRes.CodArt; | 
| 154 | a.CodArt = aRes.CodArt; | 155 | a.CodArt = aRes.CodArt; | 
| 155 | a.SECA = aRes.CodSec; | 156 | a.SECA = aRes.CodSec; | 
| 156 | aRes.CodSec = aRes.CodSec; | 157 | aRes.CodSec = aRes.CodSec; | 
| 157 | a.PreVen = aRes.PreVen; | 158 | a.PreVen = aRes.PreVen; | 
| 158 | a.id = aRes.id; | 159 | a.id = aRes.id; | 
| 159 | a.DET_LAR = aRes.DET_LAR; | 160 | a.DET_LAR = aRes.DET_LAR; | 
| 160 | a.DetArt = aRes.DetArt; | 161 | a.DetArt = aRes.DetArt; | 
| 161 | } | 162 | } | 
| 162 | } | 163 | } | 
| 163 | } | 164 | } | 
| 164 | this.articuloService.setArticulo(articulo); | 165 | this.articuloService.setArticulo(articulo); | 
| 165 | }); | 166 | }); | 
| 166 | this.mediaPantalla(); | 167 | this.mediaPantalla(); | 
| 167 | } | 168 | } | 
| 168 | 169 | ||
| 169 | deleteArticulo(index: number) { | 170 | deleteArticulo(index: number) { | 
| 170 | this.articuloService.deleteArticulo(index); | 171 | this.articuloService.deleteArticulo(index); | 
| 171 | } | 172 | } | 
| 172 | 173 | ||
| 173 | increaseShow() { | 174 | increaseShow() { | 
| 174 | this.showQuantity += 100; | 175 | this.showQuantity += 100; | 
| 175 | } | 176 | } | 
| 176 | 177 | ||
| 177 | @HostListener('scroll', ['$event']) | 178 | @HostListener('scroll', ['$event']) | 
| 178 | scrollEvent(event: Event) { | 179 | scrollEvent(event: Event) { | 
| 179 | clearTimeout(this.inactiveScreen.timerReposo); | 180 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 180 | this.inactiveScreen.startTimeOutInactividad(); | 181 | this.inactiveScreen.startTimeOutInactividad(); | 
| 181 | } | 182 | } | 
| 182 | 183 | ||
| 183 | mouseup() { | 184 | mouseup() { | 
| 184 | if (!this.timeoutHandler) return; | 185 | if (!this.timeoutHandler) return; | 
| 185 | clearInterval(this.timeoutHandler); | 186 | clearInterval(this.timeoutHandler); | 
| 186 | } | 187 | } | 
| 187 | 188 | ||
| 188 | scrollY(el: HTMLElement, value) { | 189 | scrollY(el: HTMLElement, value) { | 
| 189 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 190 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 
| 190 | this.timeoutHandler = setInterval(() => { | 191 | this.timeoutHandler = setInterval(() => { | 
| 191 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 192 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 
| 192 | }, 500); | 193 | }, 500); | 
| 193 | } | 194 | } | 
| 194 | 195 | ||
| 195 | scrollX(el: HTMLElement, value) { | 196 | scrollX(el: HTMLElement, value) { | 
| 196 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 197 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 
| 197 | this.timeoutHandler = setInterval(() => { | 198 | this.timeoutHandler = setInterval(() => { | 
| 198 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 199 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 
| 199 | }, 500); | 200 | }, 500); | 
| 200 | } | 201 | } | 
| 201 | 202 | ||
| 202 | mediaPantalla() { | 203 | mediaPantalla() { | 
| 203 | if ($('body').hasClass('media-pantalla')) { | 204 | if ($('body').hasClass('media-pantalla')) { | 
| 204 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 205 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 
| 205 | .cat-box,.img-categoria, .modal-content`) | 206 | .cat-box,.img-categoria, .modal-content`) | 
| 206 | .addClass('media-pantalla') | 207 | .addClass('media-pantalla') | 
| 207 | .addBack('media-pantalla'); | 208 | .addBack('media-pantalla'); | 
| 208 | } | 209 | } | 
| 209 | } | 210 | } | 
| 210 | } | 211 | } | 
| 211 | 212 | 
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.apiImagenes}/imagenes/`; | 21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/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-dialog-centered' | 67 | class: 'modal-dialog-centered' | 
| 68 | }); | 68 | }); | 
| 69 | } | 69 | } | 
| 70 | 70 | ||
| 71 | openModalConfirmacion(articulo: IArticulo) { | 71 | openModalConfirmacion(articulo: IArticulo) { | 
| 72 | this.articuloService.setArticulosSinImagen([articulo]); | ||
| 72 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 73 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 
| 73 | { | 74 | { | 
| 74 | initialState: { | 75 | initialState: { | 
| 75 | titleMessage: articulo.DET_LAR, | 76 | titleMessage: articulo.DET_LAR, | 
| 76 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 77 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 
| 77 | footerMessageFirst: `¿DESEA AGREGAR ESTE COMBO`, | 78 | footerMessageFirst: `¿DESEA AGREGAR ESTE COMBO`, | 
| 78 | footerMessageSecond: `a su carrito?`, | 79 | footerMessageSecond: `a su carrito?`, | 
| 79 | footerConfirmation: articulo.PreVen, | 80 | footerConfirmation: articulo.PreVen, | 
| 80 | footerClose: `volver` | 81 | footerClose: `volver` | 
| 81 | }, | 82 | }, | 
| 82 | class: 'modal-dialog-centered' | 83 | class: 'modal-dialog-centered' | 
| 83 | }); | 84 | }); | 
| 84 | this.modalRef.content.onClose.subscribe(() => { | 85 | this.modalRef.content.onClose.subscribe(() => { | 
| 85 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 86 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 
| 86 | .subscribe((res: ISinonimo[]) => { | 87 | .subscribe((res: ISinonimo[]) => { | 
| 87 | if (res.length) { | 88 | if (res.length) { | 
| 88 | const sinonimos = []; | 89 | const sinonimos = []; | 
| 89 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 90 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 
| 90 | Object.keys(gruposArticulos).forEach(key => { | 91 | Object.keys(gruposArticulos).forEach(key => { | 
| 91 | sinonimos.push({ productos: gruposArticulos[key] }); | 92 | sinonimos.push({ productos: gruposArticulos[key] }); | 
| 92 | }); | 93 | }); | 
| 93 | res = sinonimos; | 94 | res = sinonimos; | 
| 94 | this.openModalSinonimos(res, articulo); | 95 | this.openModalSinonimos(res, articulo); | 
| 95 | } else { | 96 | } else { | 
| 96 | articulo.cantidad = 1; | 97 | articulo.cantidad = 1; | 
| 97 | this.articuloService.setArticulo(articulo); | 98 | this.articuloService.setArticulo(articulo); | 
| 98 | } | 99 | } | 
| 99 | }, err => console.error(err)); | 100 | }, err => console.error(err)); | 
| 100 | }); | 101 | }); | 
| 101 | this.mediaPantalla(); | 102 | this.mediaPantalla(); | 
| 102 | } | 103 | } | 
| 103 | 104 | ||
| 104 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 105 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 105 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 106 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 
| 106 | initialState: { | 107 | initialState: { | 
| 107 | sinonimos: sinonimosData, | 108 | sinonimos: sinonimosData, | 
| 108 | articulo | 109 | articulo | 
| 109 | }, | 110 | }, | 
| 110 | class: 'modal-dialog-centered' | 111 | class: 'modal-dialog-centered' | 
| 111 | }); | 112 | }); | 
| 112 | modalSinonimo.content.onClose | 113 | modalSinonimo.content.onClose | 
| 113 | .subscribe((res: any) => { | 114 | .subscribe((res: any) => { | 
| 114 | for (const a of articulo.productos) { | 115 | for (const a of articulo.productos) { | 
| 115 | for (const aRes of res.articulos) { | 116 | for (const aRes of res.articulos) { | 
| 116 | if (a.idSinonimo === aRes.ID_SIN) { | 117 | if (a.idSinonimo === aRes.ID_SIN) { | 
| 117 | a.CODA = aRes.CodArt; | 118 | a.CODA = aRes.CodArt; | 
| 118 | a.CodArt = aRes.CodArt; | 119 | a.CodArt = aRes.CodArt; | 
| 119 | a.SECA = aRes.CodSec; | 120 | a.SECA = aRes.CodSec; | 
| 120 | aRes.CodSec = aRes.CodSec; | 121 | aRes.CodSec = aRes.CodSec; | 
| 121 | a.PreVen = aRes.PreVen; | 122 | a.PreVen = aRes.PreVen; | 
| 122 | a.id = aRes.id; | 123 | a.id = aRes.id; | 
| 123 | a.DET_LAR = aRes.DET_LAR; | 124 | a.DET_LAR = aRes.DET_LAR; | 
| 124 | a.DetArt = aRes.DetArt; | 125 | a.DetArt = aRes.DetArt; | 
| 125 | } | 126 | } | 
| 126 | } | 127 | } | 
| 127 | } | 128 | } | 
| 128 | this.articuloService.setArticulo(articulo); | 129 | this.articuloService.setArticulo(articulo); | 
| 129 | }); | 130 | }); | 
| 130 | } | 131 | } | 
| 131 | 132 | ||
| 132 | mediaPantalla() { | 133 | mediaPantalla() { | 
| 133 | if ($('body').hasClass('media-pantalla')) { | 134 | if ($('body').hasClass('media-pantalla')) { | 
| 134 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 135 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 
| 135 | } | 136 | } | 
| 136 | } | 137 | } | 
| 137 | } | 138 | } | 
| 138 | 139 |