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