pago-con-tarjeta.component.ts 1.41 KB
import { Component, OnInit } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap';
import { TarjetasService } from 'src/app/services/tarjetas.service';
import { Tarjeta } from 'src/app/wrappers/tarjeta';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
  selector: 'app-pago-con-tarjeta',
  templateUrl: './pago-con-tarjeta.component.html',
  styleUrls: ['./pago-con-tarjeta.component.scss'],
})
export class PagoConTarjetaComponent implements OnInit {

  private showForm = false;
  private importeTotal: number;
  private tarjetas: Tarjeta[] = [];
  private tarjetaSeleccionada: Tarjeta;
  private form: FormGroup;

  constructor(
    private modalRef: BsModalRef,
    private tarjetasService: TarjetasService,
  ) { }

  ngOnInit() {

    this.tarjetasService.getTarjetas()
      .subscribe((res: Tarjeta[]) => {

        this.tarjetas = res;
      }, err => console.error(err));

    this.setForm();
  }

  setForm() {

    this.form = new FormGroup({
      terminal: new FormControl('', [Validators.required, Validators.pattern("^[0-9]*$")]),
      numeroCupon: new FormControl('', [Validators.required, Validators.pattern("^[0-9]*$")]),
      cuotas: new FormControl('', [Validators.required, Validators.pattern("^[0-9]*$")]),
    })
  }

  seleccionarTarjeta(tarjeta: Tarjeta) {

    this.tarjetaSeleccionada = tarjeta;
    this.showForm = true;
  }

  close() {

    this.modalRef.hide()
  }
}