Commit 2faef52ed0128c936c0e8bcc970db4421fc59028
1 parent
411952c8b2
Exists in
develop
Fix
en seleccion de sinonimo
Showing
4 changed files
with
13 additions
and
28 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 | 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, i) => { | 120 | Object.keys(gruposArticulos).forEach((key, i) => { | 
| 121 | sinonimos.push({ productos: gruposArticulos[key] }); | 121 | sinonimos.push({ productos: gruposArticulos[key] }); | 
| 122 | sinonimos[i].cantidad = articulo.productos[i].cantidad; | 122 | sinonimos[i].cantidad = articulo.productos[i].cantidad; | 
| 123 | sinonimos[i].cantidadRestante = articulo.productos[i].cantidad; | 123 | sinonimos[i].cantidadRestante = articulo.productos[i].cantidad; | 
| 124 | }); | 124 | }); | 
| 125 | res = sinonimos; | 125 | res = sinonimos; | 
| 126 | this.openModalSinonimos(res, articulo); | 126 | this.openModalSinonimos(res, articulo); | 
| 127 | } else { | 127 | } else { | 
| 128 | this.articuloService.setArticulo(articulo); | 128 | this.articuloService.setArticulo(articulo); | 
| 129 | } | 129 | } | 
| 130 | }); | 130 | }); | 
| 131 | } | 131 | } | 
| 132 | 132 | ||
| 133 | openModalPromos(articulo: IArticulo) { | 133 | openModalPromos(articulo: IArticulo) { | 
| 134 | if (this.modalRef) return; | 134 | if (this.modalRef) return; | 
| 135 | this.articuloService.setArticulosSinImagen([articulo]); | 135 | this.articuloService.setArticulosSinImagen([articulo]); | 
| 136 | this.modalRef = this.modalService.show(PromocionComponent, { | 136 | this.modalRef = this.modalService.show(PromocionComponent, { | 
| 137 | initialState: { articulosPromo: [articulo] }, | 137 | initialState: { articulosPromo: [articulo] }, | 
| 138 | class: 'modal-dialog-centered', | 138 | class: 'modal-dialog-centered', | 
| 139 | ignoreBackdropClick: true, | 139 | ignoreBackdropClick: true, | 
| 140 | }); | 140 | }); | 
| 141 | this.modalRef.content.onClose | 141 | this.modalRef.content.onClose | 
| 142 | .subscribe(() => this.modalRef = null); | 142 | .subscribe(() => this.modalRef = null); | 
| 143 | this.mediaPantalla(); | 143 | this.mediaPantalla(); | 
| 144 | } | 144 | } | 
| 145 | 145 | ||
| 146 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 146 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 147 | if (this.modalRef) return; | 147 | if (this.modalRef) return; | 
| 148 | this.modalRef = this.modalService.show(SinonimoComponent, { | 148 | this.modalRef = this.modalService.show(SinonimoComponent, { | 
| 149 | initialState: { | 149 | initialState: { | 
| 150 | sinonimos: sinonimosData, | 150 | sinonimos: sinonimosData, | 
| 151 | articulo | 151 | articulo | 
| 152 | }, | 152 | }, | 
| 153 | class: 'modal-dialog-centered', | 153 | class: 'modal-dialog-centered', | 
| 154 | ignoreBackdropClick: true, | 154 | ignoreBackdropClick: true, | 
| 155 | }); | 155 | }); | 
| 156 | 156 | ||
| 157 | this.modalRef.content.onClose | 157 | this.modalRef.content.onClose | 
| 158 | .subscribe((res: any) => { | 158 | .subscribe((res: any) => { | 
| 159 | this.modalRef = null; | 159 | this.modalRef = null; | 
| 160 | if (!res) return; | 160 | if (!res) return; | 
| 161 | for (const a of articulo.productos) { | 161 | articulo.productos = res.articulos; | 
| 162 | for (const aRes of res.articulos) { | ||
| 163 | if (a.idSinonimo === aRes.ID_SIN) { | ||
| 164 | this.articuloService.changeArticulo(a, aRes); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | } | ||
| 168 | this.articuloService.setArticulo(articulo); | 162 | this.articuloService.setArticulo(articulo); | 
| 169 | }); | 163 | }); | 
| 170 | this.mediaPantalla(); | 164 | this.mediaPantalla(); | 
| 171 | } | 165 | } | 
| 172 | 166 | ||
| 173 | deleteArticulo(index: number) { | 167 | deleteArticulo(index: number) { | 
| 174 | this.articuloService.deleteArticulo(index); | 168 | this.articuloService.deleteArticulo(index); | 
| 175 | } | 169 | } | 
| 176 | 170 | ||
| 177 | increaseShow() { | 171 | increaseShow() { | 
| 178 | this.showQuantity += 100; | 172 | this.showQuantity += 100; | 
| 179 | } | 173 | } | 
| 180 | 174 | ||
| 181 | @HostListener('scroll', ['$event']) | 175 | @HostListener('scroll', ['$event']) | 
| 182 | scrollEvent(event: Event) { | 176 | scrollEvent(event: Event) { | 
| 183 | clearTimeout(this.inactiveScreen.timerReposo); | 177 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 184 | this.inactiveScreen.startTimeOutInactividad(); | 178 | this.inactiveScreen.startTimeOutInactividad(); | 
| 185 | } | 179 | } | 
| 186 | 180 | ||
| 187 | mouseup() { | 181 | mouseup() { | 
| 188 | if (!this.timeoutHandler) return; | 182 | if (!this.timeoutHandler) return; | 
| 189 | clearInterval(this.timeoutHandler); | 183 | clearInterval(this.timeoutHandler); | 
| 190 | } | 184 | } | 
| 191 | 185 | ||
| 192 | scrollY(el: HTMLElement, value) { | 186 | scrollY(el: HTMLElement, value) { | 
| 193 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 187 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 
| 194 | this.timeoutHandler = setInterval(() => { | 188 | this.timeoutHandler = setInterval(() => { | 
| 195 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 189 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 
| 196 | }, 500); | 190 | }, 500); | 
| 197 | } | 191 | } | 
| 198 | 192 | ||
| 199 | scrollX(el: HTMLElement, value) { | 193 | scrollX(el: HTMLElement, value) { | 
| 200 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 194 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 
| 201 | this.timeoutHandler = setInterval(() => { | 195 | this.timeoutHandler = setInterval(() => { | 
| 202 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 196 | el.scroll({ behavior: 'smooth', left: value + el.scrollLeft }); | 
| 203 | }, 500); | 197 | }, 500); | 
| 204 | } | 198 | } | 
| 205 | 199 | ||
| 206 | mediaPantalla() { | 200 | mediaPantalla() { | 
| 207 | if ($('body').hasClass('media-pantalla')) { | 201 | if ($('body').hasClass('media-pantalla')) { | 
| 208 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 202 | $(`.cat-content,#cat-content,#content,.cat-btn,#boxCarrito, | 
| 209 | .cat-box,.img-categoria, .modal-content`) | 203 | .cat-box,.img-categoria, .modal-content`) | 
| 210 | .addClass('media-pantalla') | 204 | .addClass('media-pantalla') | 
| 211 | .addBack('media-pantalla'); | 205 | .addBack('media-pantalla'); | 
| 212 | } | 206 | } | 
| 213 | } | 207 | } | 
| 214 | } | 208 | } | 
| 215 | 209 | 
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 | modalSinonimo: BsModalRef; | 24 | modalSinonimo: BsModalRef; | 
| 25 | 25 | ||
| 26 | constructor( | 26 | constructor( | 
| 27 | private publicidadService: PublicidadService, | 27 | private publicidadService: PublicidadService, | 
| 28 | private articuloService: ArticuloService, | 28 | private articuloService: ArticuloService, | 
| 29 | private modalService: BsModalService, | 29 | private modalService: BsModalService, | 
| 30 | private sinonimoService: SinonimoService | 30 | private sinonimoService: SinonimoService | 
| 31 | ) { } | 31 | ) { } | 
| 32 | 32 | ||
| 33 | ngOnInit() { | 33 | ngOnInit() { | 
| 34 | this.getPublicidades(); | 34 | this.getPublicidades(); | 
| 35 | this.mediaPantalla(); | 35 | this.mediaPantalla(); | 
| 36 | } | 36 | } | 
| 37 | 37 | ||
| 38 | getPublicidades() { | 38 | getPublicidades() { | 
| 39 | this.publicidadService.getAll() | 39 | this.publicidadService.getAll() | 
| 40 | .subscribe((res: IPublicidad[]) => { | 40 | .subscribe((res: IPublicidad[]) => { | 
| 41 | this.publicidades = res; | 41 | this.publicidades = res; | 
| 42 | }, err => console.error(err)); | 42 | }, err => console.error(err)); | 
| 43 | } | 43 | } | 
| 44 | 44 | ||
| 45 | elegirArticulo(publicidad: IPublicidad) { | 45 | elegirArticulo(publicidad: IPublicidad) { | 
| 46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 
| 47 | } | 47 | } | 
| 48 | 48 | ||
| 49 | getByID(id: number) { | 49 | getByID(id: number) { | 
| 50 | this.articuloService.getById(id) | 50 | this.articuloService.getById(id) | 
| 51 | .subscribe((res: IArticulo) => { | 51 | .subscribe((res: IArticulo) => { | 
| 52 | if (res.FPP) { | 52 | if (res.FPP) { | 
| 53 | this.openModalPromos(res); | 53 | this.openModalPromos(res); | 
| 54 | return; | 54 | return; | 
| 55 | } else { | 55 | } else { | 
| 56 | this.openModalConfirmacion(res); | 56 | this.openModalConfirmacion(res); | 
| 57 | return; | 57 | return; | 
| 58 | } | 58 | } | 
| 59 | }, err => console.error(err)); | 59 | }, err => console.error(err)); | 
| 60 | } | 60 | } | 
| 61 | 61 | ||
| 62 | openModalPromos(articulo: IArticulo) { | 62 | openModalPromos(articulo: IArticulo) { | 
| 63 | if (this.modalRef) return; | 63 | if (this.modalRef) return; | 
| 64 | this.modalRef = this.modalService.show(PromocionComponent, | 64 | this.modalRef = this.modalService.show(PromocionComponent, | 
| 65 | { | 65 | { | 
| 66 | initialState: { | 66 | initialState: { | 
| 67 | idArticulo: articulo.id | 67 | idArticulo: articulo.id | 
| 68 | }, | 68 | }, | 
| 69 | class: 'modal-dialog-centered' | 69 | class: 'modal-dialog-centered' | 
| 70 | }); | 70 | }); | 
| 71 | } | 71 | } | 
| 72 | 72 | ||
| 73 | openModalConfirmacion(articulo: IArticulo) { | 73 | openModalConfirmacion(articulo: IArticulo) { | 
| 74 | if (this.modalRef) return; | 74 | if (this.modalRef) return; | 
| 75 | this.articuloService.setArticulosSinImagen([articulo]); | 75 | this.articuloService.setArticulosSinImagen([articulo]); | 
| 76 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 76 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 
| 77 | { | 77 | { | 
| 78 | initialState: { | 78 | initialState: { | 
| 79 | titleMessage: articulo.DET_LAR, | 79 | titleMessage: articulo.DET_LAR, | 
| 80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 
| 81 | footerMessageFirst: `ยฟQUERรS AGREGAR ESTE COMBO`, | 81 | footerMessageFirst: `ยฟQUERรS AGREGAR ESTE COMBO`, | 
| 82 | footerMessageSecond: `a tu carrito?`, | 82 | footerMessageSecond: `a tu carrito?`, | 
| 83 | footerConfirmation: articulo.PreVen | 83 | footerConfirmation: articulo.PreVen | 
| 84 | }, | 84 | }, | 
| 85 | ignoreBackdropClick: true, | 85 | ignoreBackdropClick: true, | 
| 86 | class: 'modal-dialog-centered' | 86 | class: 'modal-dialog-centered' | 
| 87 | }); | 87 | }); | 
| 88 | this.modalRef.content.onClose.subscribe((resClose) => { | 88 | this.modalRef.content.onClose.subscribe((resClose) => { | 
| 89 | this.modalRef = null; | 89 | this.modalRef = null; | 
| 90 | if (!resClose) return; | 90 | if (!resClose) return; | 
| 91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 
| 92 | .subscribe((res: ISinonimo[]) => { | 92 | .subscribe((res: ISinonimo[]) => { | 
| 93 | if (res.length) { | 93 | if (res.length) { | 
| 94 | const sinonimos = []; | 94 | const sinonimos = []; | 
| 95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 
| 96 | Object.keys(gruposArticulos).forEach(key => { | 96 | Object.keys(gruposArticulos).forEach(key => { | 
| 97 | sinonimos.push({ productos: gruposArticulos[key] }); | 97 | sinonimos.push({ productos: gruposArticulos[key] }); | 
| 98 | }); | 98 | }); | 
| 99 | res = sinonimos; | 99 | res = sinonimos; | 
| 100 | this.openModalSinonimos(res, articulo); | 100 | this.openModalSinonimos(res, articulo); | 
| 101 | } else { | 101 | } else { | 
| 102 | articulo.cantidad = 1; | 102 | articulo.cantidad = 1; | 
| 103 | this.articuloService.setArticulo(articulo); | 103 | this.articuloService.setArticulo(articulo); | 
| 104 | } | 104 | } | 
| 105 | }, err => console.error(err)); | 105 | }, err => console.error(err)); | 
| 106 | }); | 106 | }); | 
| 107 | this.mediaPantalla(); | 107 | this.mediaPantalla(); | 
| 108 | } | 108 | } | 
| 109 | 109 | ||
| 110 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 110 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 111 | if (this.modalSinonimo) return; | 111 | if (this.modalSinonimo) return; | 
| 112 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 112 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 
| 113 | initialState: { | 113 | initialState: { | 
| 114 | sinonimos: sinonimosData, | 114 | sinonimos: sinonimosData, | 
| 115 | articulo | 115 | articulo | 
| 116 | }, | 116 | }, | 
| 117 | class: 'modal-dialog-centered' | 117 | class: 'modal-dialog-centered' | 
| 118 | }); | 118 | }); | 
| 119 | this.modalSinonimo.content.onClose | 119 | this.modalSinonimo.content.onClose | 
| 120 | .subscribe((res: any) => { | 120 | .subscribe((res: any) => { | 
| 121 | this.modalSinonimo = null; | 121 | this.modalSinonimo = null; | 
| 122 | for (const a of articulo.productos) { | 122 | if (!res) return; | 
| 123 | for (const aRes of res.articulos) { | 123 | articulo.productos = res.articulos; | 
| 124 | if (a.idSinonimo === aRes.ID_SIN) { | ||
| 125 | this.articuloService.changeArticulo(a, aRes); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } | ||
| 129 | this.articuloService.setArticulo(articulo); | 124 | this.articuloService.setArticulo(articulo); | 
| 130 | }); | 125 | }); | 
| 131 | } | 126 | } | 
| 132 | 127 | ||
| 133 | mediaPantalla() { | 128 | mediaPantalla() { | 
| 134 | if ($('body').hasClass('media-pantalla')) { | 129 | if ($('body').hasClass('media-pantalla')) { | 
| 135 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 130 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 
| 136 | } | 131 | } | 
| 137 | } | 132 | } | 
| 138 | } | 133 | } | 
| 139 | 134 | 
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.apiImagenes}/imagenes/`; | 23 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 
| 24 | loading = true; | 24 | loading = true; | 
| 25 | modalSinonimo: BsModalRef; | 25 | modalSinonimo: BsModalRef; | 
| 26 | isPromoSelected = false; | 26 | isPromoSelected = false; | 
| 27 | 27 | ||
| 28 | constructor( | 28 | constructor( | 
| 29 | private modalPromocion: BsModalRef, | 29 | private modalPromocion: BsModalRef, | 
| 30 | private modalService: BsModalService, | 30 | private modalService: BsModalService, | 
| 31 | private articuloService: ArticuloService, | 31 | private articuloService: ArticuloService, | 
| 32 | private promocionService: PromocionService, | 32 | private promocionService: PromocionService, | 
| 33 | private sinonimoService: SinonimoService, | 33 | private sinonimoService: SinonimoService, | 
| 34 | private inactiveScreen: InactiveScreenService, | 34 | private inactiveScreen: InactiveScreenService, | 
| 35 | ) { | 35 | ) { | 
| 36 | this.onClose = new Subject(); | 36 | this.onClose = new Subject(); | 
| 37 | } | 37 | } | 
| 38 | 38 | ||
| 39 | ngOnInit() { | 39 | ngOnInit() { | 
| 40 | this.getPromociones(); | 40 | this.getPromociones(); | 
| 41 | } | 41 | } | 
| 42 | 42 | ||
| 43 | selectPromo(promo: IArticulo) { | 43 | selectPromo(promo: IArticulo) { | 
| 44 | if (this.isPromoSelected) return; | 44 | if (this.isPromoSelected) return; | 
| 45 | this.isPromoSelected = true; | 45 | this.isPromoSelected = true; | 
| 46 | this.articuloService.getById(promo.id) | 46 | this.articuloService.getById(promo.id) | 
| 47 | .subscribe((resPromo: IArticulo) => { | 47 | .subscribe((resPromo: IArticulo) => { | 
| 48 | promo = resPromo; | 48 | promo = resPromo; | 
| 49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 49 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 
| 50 | .subscribe((res: ISinonimo[]) => { | 50 | .subscribe((res: ISinonimo[]) => { | 
| 51 | if (res.length) { | 51 | if (res.length) { | 
| 52 | const sinonimos = []; | 52 | const sinonimos = []; | 
| 53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 53 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 
| 54 | Object.keys(gruposArticulos).forEach(key => { | 54 | Object.keys(gruposArticulos).forEach(key => { | 
| 55 | sinonimos.push({ productos: gruposArticulos[key] }); | 55 | sinonimos.push({ productos: gruposArticulos[key] }); | 
| 56 | }); | 56 | }); | 
| 57 | res = sinonimos; | 57 | res = sinonimos; | 
| 58 | this.openModalSinonimos(res, promo); | 58 | this.openModalSinonimos(res, promo); | 
| 59 | } else { | 59 | } else { | 
| 60 | promo.cantidad = 1; | 60 | promo.cantidad = 1; | 
| 61 | this.articuloService.setArticulo(promo); | 61 | this.articuloService.setArticulo(promo); | 
| 62 | this.onClose.next(); | 62 | this.onClose.next(); | 
| 63 | this.modalPromocion.hide(); | 63 | this.modalPromocion.hide(); | 
| 64 | } | 64 | } | 
| 65 | }, err => console.error(err)); | 65 | }, err => console.error(err)); | 
| 66 | }, err => console.error(err)); | 66 | }, err => console.error(err)); | 
| 67 | this.mediaPantalla(); | 67 | this.mediaPantalla(); | 
| 68 | } | 68 | } | 
| 69 | 69 | ||
| 70 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 70 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 71 | if (this.modalSinonimo) return; | 71 | if (this.modalSinonimo) return; | 
| 72 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 72 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | 
| 73 | initialState: { | 73 | initialState: { | 
| 74 | sinonimos: sinonimosData, | 74 | sinonimos: sinonimosData, | 
| 75 | articulo | 75 | articulo | 
| 76 | }, | 76 | }, | 
| 77 | class: 'modal-dialog-centered', | 77 | class: 'modal-dialog-centered', | 
| 78 | ignoreBackdropClick: true, | 78 | ignoreBackdropClick: true, | 
| 79 | }); | 79 | }); | 
| 80 | 80 | ||
| 81 | this.modalSinonimo.content.onClose | 81 | this.modalSinonimo.content.onClose | 
| 82 | .subscribe((res: any) => { | 82 | .subscribe((res: any) => { | 
| 83 | this.modalSinonimo = null; | 83 | this.modalSinonimo = null; | 
| 84 | if (!res) { | 84 | if (!res) { | 
| 85 | this.onClose.next(); | 85 | this.onClose.next(); | 
| 86 | this.modalPromocion.hide(); | 86 | this.modalPromocion.hide(); | 
| 87 | return; | 87 | return; | 
| 88 | } | 88 | } | 
| 89 | for (const a of articulo.productos) { | 89 | articulo.productos = res.articulos; | 
| 90 | for (const aRes of res.articulos) { | ||
| 91 | if (a.idSinonimo === aRes.ID_SIN) { | ||
| 92 | this.articuloService.changeArticulo(a, aRes); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | } | ||
| 96 | this.articuloService.setArticulo(articulo); | 90 | this.articuloService.setArticulo(articulo); | 
| 97 | this.onClose.next(); | 91 | this.onClose.next(); | 
| 98 | this.modalPromocion.hide(); | 92 | this.modalPromocion.hide(); | 
| 99 | }); | 93 | }); | 
| 100 | } | 94 | } | 
| 101 | 95 | ||
| 102 | getPromociones() { | 96 | getPromociones() { | 
| 103 | const sector = this.articulosPromo[0].CodSec; | 97 | const sector = this.articulosPromo[0].CodSec; | 
| 104 | const codigo = this.articulosPromo[0].CodArt; | 98 | const codigo = this.articulosPromo[0].CodArt; | 
| 105 | this.promocionService.getPromociones(sector, codigo) | 99 | this.promocionService.getPromociones(sector, codigo) | 
| 106 | .subscribe((res: IArticulo[]) => { | 100 | .subscribe((res: IArticulo[]) => { | 
| 107 | this.promociones = res; | 101 | this.promociones = res; | 
| 108 | this.loading = false; | 102 | this.loading = false; | 
| 109 | }, error => { console.error(error); }); | 103 | }, error => { console.error(error); }); | 
| 110 | } | 104 | } | 
| 111 | 105 | ||
| 112 | @HostListener('document:click', ['$event']) | 106 | @HostListener('document:click', ['$event']) | 
| 113 | eventListener(event: Event) { | 107 | eventListener(event: Event) { | 
| 114 | clearTimeout(this.inactiveScreen.timerReposo); | 108 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 115 | this.inactiveScreen.startTimeOutInactividad(); | 109 | this.inactiveScreen.startTimeOutInactividad(); | 
| 116 | } | 110 | } | 
| 117 | 111 | ||
| 118 | @HostListener('scroll', ['$event']) | 112 | @HostListener('scroll', ['$event']) | 
| 119 | scrollEvent(event: Event) { | 113 | scrollEvent(event: Event) { | 
| 120 | clearTimeout(this.inactiveScreen.timerReposo); | 114 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 121 | this.inactiveScreen.startTimeOutInactividad(); | 115 | this.inactiveScreen.startTimeOutInactividad(); | 
| 122 | } | 116 | } | 
| 123 | 117 | ||
| 124 | mediaPantalla() { | 118 | mediaPantalla() { | 
| 125 | if ($('body').hasClass('media-pantalla')) { | 119 | if ($('body').hasClass('media-pantalla')) { | 
| 126 | $('.modal-content').addClass('media-pantalla'); | 120 | $('.modal-content').addClass('media-pantalla'); | 
| 127 | } | 121 | } | 
| 128 | } | 122 | } | 
| 129 | } | 123 | } | 
| 130 | 124 | 
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 | articulo: IArticulo; | 18 | articulo: IArticulo; | 
| 19 | isSinonimoSelected = false; | 19 | isSinonimoSelected = false; | 
| 20 | currentIndex = 0; | 20 | currentIndex = 0; | 
| 21 | 21 | ||
| 22 | constructor( | 22 | constructor( | 
| 23 | private modalRef: BsModalRef, | 23 | private modalRef: BsModalRef, | 
| 24 | private articuloService: ArticuloService, | 24 | private articuloService: ArticuloService, | 
| 25 | ) { | 25 | ) { | 
| 26 | this.onClose = new Subject(); | 26 | this.onClose = new Subject(); | 
| 27 | } | 27 | } | 
| 28 | 28 | ||
| 29 | ngOnInit() { | 29 | ngOnInit() { | 
| 30 | for (const s of this.sinonimos) { | 30 | for (const s of this.sinonimos) { | 
| 31 | for (const a of s.productos) { | 31 | for (const a of s.productos) { | 
| 32 | a.cantidad = 0; | 32 | a.cantidad = 0; | 
| 33 | } | 33 | } | 
| 34 | } | 34 | } | 
| 35 | } | 35 | } | 
| 36 | 36 | ||
| 37 | validate() { | 37 | validate() { | 
| 38 | this.isValid = true; | 38 | this.isValid = true; | 
| 39 | for (const s of this.sinonimos) { | 39 | for (const s of this.sinonimos) { | 
| 40 | if (s.cantidadRestante > 0) { | 40 | if (s.cantidadRestante > 0) { | 
| 41 | this.isValid = false; | 41 | this.isValid = false; | 
| 42 | break; | 42 | break; | 
| 43 | } | 43 | } | 
| 44 | } | 44 | } | 
| 45 | return !this.isValid ? 'disabled' : 'btn-effect'; | 45 | return !this.isValid ? 'disabled' : 'btn-effect'; | 
| 46 | } | 46 | } | 
| 47 | 47 | ||
| 48 | continue() { | 48 | continue() { | 
| 49 | if (!this.isValid) return; | 49 | if (!this.isValid) return; | 
| 50 | if (this.isSinonimoSelected) return; | 50 | if (this.isSinonimoSelected) return; | 
| 51 | this.isSinonimoSelected = true; | 51 | this.isSinonimoSelected = true; | 
| 52 | const ID_SINS = []; | ||
| 53 | const observables = []; | 52 | const observables = []; | 
| 53 | const cantidades = []; | ||
| 54 | 54 | ||
| 55 | // for (const articulo of this.articulosSelected) { | 55 | for (const s of this.sinonimos) { | 
| 56 | // ID_SINS.push(articulo.ID_SIN); | 56 | for (const articulo of s.productos) { | 
| 57 | // observables.push(this.articuloService.getById(articulo.id)); | 57 | if (articulo.cantidad === 0) continue; | 
| 58 | // } | 58 | cantidades.push(articulo.cantidad); | 
| 59 | 59 | observables.push(this.articuloService.getById(articulo.id)); | |
| 60 | } | ||
| 61 | } | ||
| 60 | forkJoin(observables) | 62 | forkJoin(observables) | 
| 61 | .subscribe((res: IArticulo[]) => { | 63 | .subscribe((res: IArticulo[]) => { | 
| 62 | res.forEach((articulo, i) => { | 64 | res.forEach((articulo, i) => { | 
| 63 | articulo.ID_SIN = ID_SINS[i]; | 65 | articulo.cantidad = cantidades[i]; | 
| 64 | }); | 66 | }); | 
| 65 | this.modalRef.hide(); | 67 | this.modalRef.hide(); | 
| 66 | this.onClose.next({ | 68 | this.onClose.next({ | 
| 67 | articulos: res, | 69 | articulos: res, | 
| 68 | }); | 70 | }); | 
| 69 | }, err => console.error(err)); | 71 | }, err => console.error(err)); | 
| 70 | } | 72 | } | 
| 71 | 73 | ||
| 72 | sumarCantidadSinonimo(articulo: IArticulo, i: number) { | 74 | sumarCantidadSinonimo(articulo: IArticulo, i: number) { | 
| 73 | if (this.sinonimos[i].cantidadRestante === 0) return; | 75 | if (this.sinonimos[i].cantidadRestante === 0) return; | 
| 74 | articulo.cantidad++; | 76 | articulo.cantidad++; | 
| 75 | this.sinonimos[i].cantidadRestante--; | 77 | this.sinonimos[i].cantidadRestante--; | 
| 76 | } | 78 | } | 
| 77 | 79 | ||
| 78 | restarCantidadSinonimo(articulo: IArticulo, i: number) { | 80 | restarCantidadSinonimo(articulo: IArticulo, i: number) { | 
| 79 | if (this.sinonimos[i].cantidadRestante === this.sinonimos[i].cantidad) return; | 81 | if (this.sinonimos[i].cantidadRestante === this.sinonimos[i].cantidad) return; | 
| 80 | if (articulo.cantidad === 0) return; | 82 | if (articulo.cantidad === 0) return; | 
| 81 | articulo.cantidad--; | 83 | articulo.cantidad--; | 
| 82 | this.sinonimos[i].cantidadRestante++; | 84 | this.sinonimos[i].cantidadRestante++; | 
| 83 | } | 85 | } | 
| 84 | 86 | ||
| 85 | scrollTo(index: number) { | 87 | scrollTo(index: number) { | 
| 86 | const el = document.getElementById(index.toString()); | 88 | const el = document.getElementById(index.toString()); | 
| 87 | el.scrollIntoView({ behavior: 'smooth' }); | 89 | el.scrollIntoView({ behavior: 'smooth' }); | 
| 88 | } | 90 | } | 
| 89 | 91 | ||
| 90 | close() { | 92 | close() { | 
| 91 | this.modalRef.hide(); | 93 | this.modalRef.hide(); | 
| 92 | this.onClose.next(); | 94 | this.onClose.next(); | 
| 93 | } | 95 | } | 
| 94 | 96 | ||
| 95 | } | 97 | } |