pago-electronico.component.ts 1.7 KB
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ArticuloService } from 'src/app/services/articulo/articulo.service';
import { Router } from '@angular/router';
import { APP_SETTINGS } from 'src/etc/AppSettings';
import { BsModalService } from 'ngx-bootstrap/modal';
import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';

@Component({
  selector: 'app-pago-electronico',
  templateUrl: './pago-electronico.component.html',
  styleUrls: ['./pago-electronico.component.scss']
})
export class PagoElectronicoComponent implements OnInit, OnDestroy {
  urlQr = `${APP_SETTINGS.apiImagenes}/qr/${APP_SETTINGS.deploy}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`;

  constructor(
    private articuloService: ArticuloService,
    private router: Router,
    private modalService: BsModalService,
  ) { }

  ngOnInit() {
    if (!this.articuloService.carrito.length) {
      this.router.navigate(['']);
      return;
    }
    const dataPago = {
      pedidoAnombreDe: ''
    };
    dataPago.pedidoAnombreDe = '';
    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() {
    for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
      this.modalService.hide(i);
    }
  }

  mediaPantalla() {
    if ($('body').hasClass('media-pantalla')) {
      $('.qr-mt').addClass('media-pantalla');
    }
  }
}