Commit 3552d0e45226d3ee491d75cf0b2d968cba1d4bbf
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !113
Showing
1 changed file
Show diff stats
src/app/components/confirmacion-carrito/confirmacion-carrito.component.ts
1 | import { Component, OnInit, OnDestroy } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy } 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 { Producto } from 'src/app/wrappers/producto'; | 5 | import { Producto } from 'src/app/wrappers/producto'; |
6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
7 | import { Subscription } from 'rxjs'; | ||
7 | 8 | ||
8 | @Component({ | 9 | @Component({ |
9 | selector: 'app-confirmacion-carrito', | 10 | selector: 'app-confirmacion-carrito', |
10 | templateUrl: './confirmacion-carrito.component.html', | 11 | templateUrl: './confirmacion-carrito.component.html', |
11 | styleUrls: ['./confirmacion-carrito.component.scss'] | 12 | styleUrls: ['./confirmacion-carrito.component.scss'] |
12 | }) | 13 | }) |
13 | export class ConfirmacionCarritoComponent implements OnInit, OnDestroy { | 14 | export class ConfirmacionCarritoComponent implements OnInit, OnDestroy { |
14 | 15 | ||
15 | private productos: Producto[] = []; | 16 | private productos: Producto[] = []; |
16 | private total: number = 0; | 17 | private total: number = 0; |
17 | private apiImagenes: string = appSettings.apiImagenes; | 18 | private apiImagenes: string = appSettings.apiImagenes; |
18 | private timerReposo: any; | 19 | private timerReposo: any; |
19 | private compraConEfectivofinalizada: boolean = false; | 20 | private compraConEfectivofinalizada: boolean = false; |
20 | private compraConQRfinalizada: boolean = false; | 21 | private compraConQRfinalizada: boolean = false; |
21 | private verQR: boolean = false; | 22 | private verQR: boolean = false; |
23 | private subscribePago: Subscription; | ||
22 | 24 | ||
23 | constructor( | 25 | constructor( |
24 | private location: Location, | 26 | private location: Location, |
25 | private productoService: ProductoService, | 27 | private productoService: ProductoService, |
26 | private router: Router | 28 | private router: Router |
27 | ) { } | 29 | ) { } |
28 | 30 | ||
29 | ngOnInit() { | 31 | ngOnInit() { |
30 | 32 | ||
31 | this.timerReposo = setTimeout(() => { | 33 | this.timerReposo = setTimeout(() => { |
32 | 34 | ||
33 | this.router.navigate(['cancelar-compra']); | 35 | this.router.navigate(['cancelar-compra']); |
34 | }, 90000) | 36 | }, 90000) |
35 | this.productos = this.productoService.productos; | 37 | this.productos = this.productoService.productos; |
36 | } | 38 | } |
37 | 39 | ||
38 | ngOnDestroy() { | 40 | ngOnDestroy() { |
39 | 41 | ||
42 | this.subscribePago.unsubscribe(); | ||
40 | clearTimeout(this.timerReposo); | 43 | clearTimeout(this.timerReposo); |
41 | } | 44 | } |
42 | 45 | ||
43 | volverPreviousPage() { | 46 | volverPreviousPage() { |
44 | 47 | ||
48 | this.subscribePago.unsubscribe(); | ||
49 | |||
45 | if (this.verQR) { | 50 | if (this.verQR) { |
46 | this.verQR = !this.verQR; | 51 | this.verQR = !this.verQR; |
47 | return; | 52 | return; |
48 | } | 53 | } |
54 | |||
49 | this.location.back(); | 55 | this.location.back(); |
50 | } | 56 | } |
51 | 57 | ||
52 | getTotal() { | 58 | getTotal() { |
53 | 59 | ||
54 | var subTotal = 0; | 60 | var subTotal = 0; |
55 | this.productos.forEach(producto => { | 61 | this.productos.forEach(producto => { |
56 | 62 | ||
57 | subTotal = subTotal + (producto.PreVen * producto.cantidad); | 63 | subTotal = subTotal + (producto.PreVen * producto.cantidad); |
58 | }); | 64 | }); |
59 | return this.total = subTotal; | 65 | return this.total = subTotal; |
60 | } | 66 | } |
61 | 67 | ||
62 | reiniciarTimer() { | 68 | reiniciarTimer() { |
63 | 69 | ||
64 | clearTimeout(this.timerReposo); | 70 | clearTimeout(this.timerReposo); |
65 | this.timerReposo = setTimeout(() => { | 71 | this.timerReposo = setTimeout(() => { |
66 | 72 | ||
67 | this.router.navigate(['cancelar-compra']); | 73 | this.router.navigate(['cancelar-compra']); |
68 | }, 90000) | 74 | }, 90000) |
69 | } | 75 | } |
70 | 76 | ||
71 | //#region METODOS PARA LA FORMA DE PAGO | 77 | //#region METODOS PARA LA FORMA DE PAGO |
72 | pagar(medioPago: string) { | 78 | pagar(medioPago: string) { |
73 | 79 | ||
74 | if (medioPago == 'electronico') { | 80 | if (medioPago == 'electronico') { |
75 | 81 | ||
76 | this.verQR = true; | 82 | this.verQR = true; |
77 | } | 83 | } |
78 | 84 | ||
79 | this.productoService.pagar(medioPago) | 85 | this.subscribePago = this.productoService.pagar(medioPago) |
80 | .subscribe(() => { | 86 | .subscribe(() => { |
81 | 87 | ||
82 | clearTimeout(this.timerReposo); | 88 | clearTimeout(this.timerReposo); |
83 | 89 | ||
84 | if (medioPago == 'efectivo') { | 90 | if (medioPago == 'efectivo') { |
85 | 91 | ||
86 | this.compraConEfectivofinalizada = true; | 92 | this.compraConEfectivofinalizada = true; |
87 | } else if (medioPago == 'electronico') { | 93 | } else if (medioPago == 'electronico') { |
88 | 94 | ||
89 | this.compraConQRfinalizada = true; | 95 | this.compraConQRfinalizada = true; |
90 | } | 96 | } |
91 | 97 | ||
92 | setTimeout(() => { | 98 | setTimeout(() => { |
93 | 99 | ||
94 | this.router.navigate(['mensaje-final']); | 100 | this.router.navigate(['mensaje-final']); |
95 | }, 10000); | 101 | }, 10000); |
96 | }, err => { | 102 | }, err => { |
97 | console.log(err); | 103 | console.log(err); |
98 | alert('algo salió mal'); | 104 | alert('algo salió mal'); |
99 | }) | 105 | }) |
100 | } | 106 | } |
101 | //#endregion | 107 | //#endregion |
102 | 108 | ||
103 | } | 109 | } |
104 | 110 |