confirmacion-carrito.component.ts 1.46 KB
import { Component, OnInit, OnDestroy } from '@angular/core';
import { appSettings } from 'src/etc/AppSettings';
import { Location } from '@angular/common';
import { ProductoService } from 'src/app/services/producto.service';
import { Producto } from 'src/app/wrappers/producto';
import { Router } from '@angular/router';

@Component({
  selector: 'app-confirmacion-carrito',
  templateUrl: './confirmacion-carrito.component.html',
  styleUrls: ['./confirmacion-carrito.component.scss']
})
export class ConfirmacionCarritoComponent implements OnInit, OnDestroy {

  private productos: Producto[] = [];
  private total: number = 0;
  private apiUrl: string = appSettings.apiUrl;
  private timerReposo: any;

  constructor(
    private location: Location,
    private productoService: ProductoService,
    private router: Router
  ) { }

  ngOnInit() {

    this.timerReposo = setTimeout(() => {

      this.router.navigate(['cancelar-compra']);
    }, 90000)
    this.productos = this.productoService.productos;
  }

  ngOnDestroy() {

    clearTimeout(this.timerReposo);
  }

  volverPreviousPage() {

    this.location.back();
  }

  getTotal() {

    var subTotal = 0;
    this.productos.forEach(producto => {

      subTotal = subTotal + (producto.PreVen * producto.cantidad);
    });
    return this.total = subTotal;
  }

  reiniciarTimer() {

    clearTimeout(this.timerReposo);
    this.timerReposo = setTimeout(() => {

      this.router.navigate(['cancelar-compra']);
    }, 90000)
  }

}