Commit 94610cc5cc92408a3384da70848a2722dc5b6bc5
Exists in
develop
Merge branch 'master' into 'develop'
Master(benjamin) See merge request !100
Showing
1 changed file
 
Show diff stats
src/app/modules/pago-tarjeta/pago-tarjeta.component.ts
| 1 | import { Component, OnInit, TemplateRef, OnDestroy, ViewChild } from '@angular/core'; | 1 | import { Component, OnInit, TemplateRef, OnDestroy, ViewChild } from '@angular/core'; | 
| 2 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 2 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 
| 3 | import { Router } from '@angular/router'; | 3 | import { Router } from '@angular/router'; | 
| 4 | import { BsModalService } from 'ngx-bootstrap/modal'; | 4 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; | 
| 5 | import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; | 5 | import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; | 
| 6 | 6 | ||
| 7 | @Component({ | 7 | @Component({ | 
| 8 | selector: 'app-pago-tarjeta', | 8 | selector: 'app-pago-tarjeta', | 
| 9 | templateUrl: './pago-tarjeta.component.html', | 9 | templateUrl: './pago-tarjeta.component.html', | 
| 10 | styleUrls: ['./pago-tarjeta.component.scss'] | 10 | styleUrls: ['./pago-tarjeta.component.scss'] | 
| 11 | }) | 11 | }) | 
| 12 | export class PagoTarjetaComponent implements OnInit, OnDestroy { | 12 | export class PagoTarjetaComponent implements OnInit, OnDestroy { | 
| 13 | timer: any; | 13 | timer: any; | 
| 14 | @ViewChild('template', {static: true}) public template: TemplateRef<any>; | 14 | @ViewChild('template', {static: true}) public template: TemplateRef<any>; | 
| 15 | modalRef: BsModalRef; | ||
| 15 | 16 | ||
| 16 | constructor( | 17 | constructor( | 
| 17 | private articuloService: ArticuloService, | 18 | private articuloService: ArticuloService, | 
| 18 | private router: Router, | 19 | private router: Router, | 
| 19 | private modalService: BsModalService, | 20 | private modalService: BsModalService, | 
| 20 | ) { } | 21 | ) { } | 
| 21 | 22 | ||
| 22 | ngOnInit() { | 23 | ngOnInit() { | 
| 23 | if (!this.articuloService.carrito.length) { | 24 | if (!this.articuloService.carrito.length) { | 
| 24 | this.router.navigate(['']); | 25 | this.router.navigate(['']); | 
| 25 | return; | 26 | return; | 
| 26 | } | 27 | } | 
| 27 | this.openModalEspera(this.template); | 28 | this.openModalEspera(this.template); | 
| 28 | const dataPago = { | 29 | const dataPago = { | 
| 29 | pedidoAnombreDe: '' | 30 | pedidoAnombreDe: '' | 
| 30 | }; | 31 | }; | 
| 31 | this.articuloService.pay(dataPago) | 32 | this.articuloService.pay(dataPago) | 
| 32 | .subscribe((res: any) => { | 33 | .subscribe((res: any) => { | 
| 34 | this.modalRef.hide(); | ||
| 33 | this.articuloService.idComanda = res.data; | 35 | this.articuloService.idComanda = res.data; | 
| 34 | this.router.navigate(['mensaje-final']); | 36 | this.router.navigate(['mensaje-final']); | 
| 35 | }, (err) => { | 37 | }, (err) => { | 
| 38 | this.modalRef.hide(); | ||
| 36 | this.modalService.show(ErrorFormaPagoComponent, { | 39 | this.modalService.show(ErrorFormaPagoComponent, { | 
| 37 | class: 'modal-lg modal-dialog-centered', | 40 | class: 'modal-lg modal-dialog-centered', | 
| 38 | ignoreBackdropClick: true, | 41 | ignoreBackdropClick: true, | 
| 39 | }); | 42 | }); | 
| 40 | }); | 43 | }); | 
| 41 | this.mediaPantalla(); | 44 | this.mediaPantalla(); | 
| 42 | } | 45 | } | 
| 43 | 46 | ||
| 44 | ngOnDestroy() { | 47 | ngOnDestroy() { | 
| 45 | if (this.timer) clearTimeout(this.timer); | 48 | if (this.timer) clearTimeout(this.timer); | 
| 46 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 49 | for (let i = 1; i <= this.modalService.getModalsCount(); i++) { | 
| 47 | this.modalService.hide(i); | 50 | this.modalService.hide(i); | 
| 48 | } | 51 | } | 
| 49 | } | 52 | } | 
| 50 | 53 | ||
| 51 | mediaPantalla() { | 54 | mediaPantalla() { | 
| 52 | if ($('body').hasClass('media-pantalla')) { | 55 | if ($('body').hasClass('media-pantalla')) { | 
| 53 | $('.pago-tarjeta').addClass('media-pantalla'); | 56 | $('.pago-tarjeta').addClass('media-pantalla'); | 
| 54 | } | 57 | } | 
| 55 | } | 58 | } | 
| 56 | 59 | ||
| 57 | openModalEspera(templateRef: TemplateRef<any>) { | 60 | openModalEspera(templateRef: TemplateRef<any>) { | 
| 58 | const modalRef = this.modalService.show(templateRef, { class: 'modal-lg modal-dialog-centered' }); | 61 | this.modalRef = this.modalService.show(templateRef, { class: 'modal-lg modal-dialog-centered' }); | 
| 59 | this.timer = setTimeout(() => { | ||
| 60 | modalRef.hide(); | ||
| 61 | }, 5000); |