pago-tarjeta.component.ts
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Component, OnInit, TemplateRef, OnDestroy, ViewChild } from '@angular/core';
import { ArticuloService } from 'src/app/services/articulo/articulo.service';
import { Router, ActivatedRoute } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-pago-tarjeta',
templateUrl: './pago-tarjeta.component.html',
styleUrls: ['./pago-tarjeta.component.scss']
})
export class PagoTarjetaComponent implements OnInit, OnDestroy {
timer: any;
@ViewChild('template', { static: true }) public template: TemplateRef<any>;
subscription: Subscription;
constructor(
private articuloService: ArticuloService,
private router: Router,
private route: ActivatedRoute,
private modalService: BsModalService,
) { }
ngOnInit() {
if (!this.articuloService.carrito.length) {
this.router.navigate(['']);
return;
}
const dataPago = {
pedidoAnombreDe: '',
contactLess: this.route.snapshot.params.contactLess
};
this.openModalEspera(this.template);
this.subscription = this.articuloService.pay(dataPago)
.subscribe((res: any) => {
this.articuloService.idComanda = res.data;
this.router.navigate(['mensaje-final']);
}, (err) => {
this.modalService.show(ErrorFormaPagoComponent, {
class: 'modal-lg modal-dialog-centered',
ignoreBackdropClick: true,
});
});
this.mediaPantalla();
}
ngOnDestroy() {
if (this.subscription) this.subscription.unsubscribe();
if (this.timer) clearTimeout(this.timer);
for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
this.modalService.hide(i);
}
}
mediaPantalla() {
if ($('body').hasClass('media-pantalla')) {
$('.pago-tarjeta').addClass('media-pantalla');
}
}
openModalEspera(templateRef: TemplateRef<any>) {
const modalRef = this.modalService.show(templateRef, { class: 'modal-lg modal-dialog-centered' });
this.timer = setTimeout(() => {
modalRef.hide();
}, 6000);
}
}