Commit eaba826af9d70821b4e9ebbc139013f63dc9703b
Exists in
master
Merge branch 'master' of http://git.focasoftware.com/angular/autoservicio
Showing
1 changed file
 
Show diff stats
src/app/components/pago/pago.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; | 
| 2 | import { appSettings } from 'src/etc/AppSettings'; | 2 | import { appSettings } from 'src/etc/AppSettings'; | 
| 3 | import { Location } from '@angular/common'; | 3 | import { Location } from '@angular/common'; | 
| 4 | import { ProductoService } from 'src/app/services/producto.service'; | 4 | import { ProductoService } from 'src/app/services/producto.service'; | 
| 5 | import { RouterLink, Router } from '@angular/router'; | 5 | import { RouterLink, Router } from '@angular/router'; | 
| 6 | import { Producto } from 'src/app/wrappers/producto'; | 6 | import { Producto } from 'src/app/wrappers/producto'; | 
| 7 | 7 | ||
| 8 | @Component({ | 8 | @Component({ | 
| 9 | selector: 'app-pago', | 9 | selector: 'app-pago', | 
| 10 | templateUrl: './pago.component.html', | 10 | templateUrl: './pago.component.html', | 
| 11 | styleUrls: ['./pago.component.scss'] | 11 | styleUrls: ['./pago.component.scss'] | 
| 12 | }) | 12 | }) | 
| 13 | export class PagoComponent implements OnInit { | 13 | export class PagoComponent implements OnInit { | 
| 14 | 14 | ||
| 15 | private apiUrl: string = appSettings.apiUrl; | 15 | private apiUrl: string = appSettings.apiUrl; | 
| 16 | private verQR: boolean = false; | 16 | private verQR: boolean = false; | 
| 17 | private productos: Producto[] = []; | 17 | private productos: Producto[] = []; | 
| 18 | private total: number = 0; | 18 | private total: number = 0; | 
| 19 | 19 | ||
| 20 | private compraConQRfinalizada: boolean = false; | 20 | private compraConQRfinalizada: boolean = false; | 
| 21 | private compraConEfectivofinalizada: boolean = false; | 21 | private compraConEfectivofinalizada: boolean = false; | 
| 22 | 22 | ||
| 23 | constructor( | 23 | constructor( | 
| 24 | private productoService: ProductoService, | 24 | private productoService: ProductoService, | 
| 25 | private location: Location, | 25 | private location: Location, | 
| 26 | private router: Router, | 26 | private router: Router, | 
| 27 | ) { } | 27 | ) { } | 
| 28 | 28 | ||
| 29 | ngOnInit() { | 29 | ngOnInit() { | 
| 30 | 30 | ||
| 31 | this.productos = this.productoService.productos; | 31 | this.productos = this.productoService.productos; | 
| 32 | } | 32 | } | 
| 33 | 33 | ||
| 34 | pagar() { | 34 | pagar() { | 
| 35 | 35 | ||
| 36 | this.verQR = true; | 36 | this.verQR = true; | 
| 37 | |||
| 38 | this.productoService.pagar() | 37 | |
| 39 | .subscribe(() => { | 38 | this.productoService.pagar() | 
| 40 | 39 | .subscribe(() => { | |
| 41 | // alert('Compra finalizada'); | 40 | |
| 42 | this.compraConQRfinalizada = true; | 41 | // alert('Compra finalizada'); | 
| 43 | setTimeout(() => { | 42 | this.compraConQRfinalizada = true; | 
| 44 | 43 | setTimeout(() => { | |
| 45 | this.router.navigate(['mensaje-final']); | 44 | |
| 46 | }, 3000); | 45 | this.router.navigate(['mensaje-final']); | 
| 47 | }, err => { | 46 | }, 3000); | 
| 48 | console.log(err); | 47 | }, err => { | 
| 49 | alert('algo salió mal'); | 48 | console.log(err); | 
| 50 | }) | 49 | alert('algo salió mal'); | 
| 51 | } | 50 | }) | 
| 52 | 51 | } | |
| 53 | volverPreviousPage() { | 52 | |
| 54 | 53 | volverPreviousPage() { | |
| 55 | if (this.verQR) { | 54 | |
| 56 | this.verQR = false; | 55 | if (this.verQR) { | 
| 57 | return; | 56 | this.verQR = false; | 
| 58 | } | 57 | return; | 
| 59 | this.location.back(); | 58 | } | 
| 60 | } | 59 | this.location.back(); | 
| 61 | 60 | } | |
| 62 | getTotal() { | 61 | |
| 63 | 62 | getTotal() { | |
| 64 | var subTotal = 0; | 63 | |
| 65 | this.productos.forEach(producto => { | 64 | var subTotal = 0; | 
| 66 | 65 | this.productos.forEach(producto => { | |
| 67 | subTotal = subTotal + (producto.PreVen * producto.cantidad); | 66 | |
| 68 | }); | 67 | subTotal = subTotal + (producto.PreVen * producto.cantidad); | 
| 69 | return this.total = subTotal; | 68 | }); | 
| 70 | } | 69 | return this.total = subTotal; | 
| 71 | 70 | } | |
| 72 | } | 71 | |
| 73 | 72 | } |