inicio.component.ts
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Component, OnInit, ViewChild } from '@angular/core';
import { PopoverDirective } from 'ngx-bootstrap';
import { appSettings } from 'src/etc/AppSettings';
import { Producto } from 'src/app/wrappers/producto';
import { ProductoService } from 'src/app/services/producto.service';
import { Router } from '@angular/router';
import { Promocion } from 'src/app/wrappers/promocion';
import { Sinonimo } from 'src/app/wrappers/sinonimo';
@Component({
selector: 'app-inicio',
templateUrl: './inicio.component.html',
styleUrls: ['./inicio.component.scss']
})
export class InicioComponent implements OnInit {
@ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
private productoAcargar: Producto;
private promoAcargar: Promocion;
private tienePromo = false;
private productoEsPromo = false;
promociones: Promocion[] = [];
sinonimos: Sinonimo[] = [];
apiUrl: string = appSettings.apiUrl
constructor(
private router: Router,
private productoService: ProductoService) { }
ngOnInit() {
this.productoAcargar = this.productoService.productoAcargar;
if (this.productoAcargar) {
var sector = this.productoAcargar.CodSec;
var codigo = this.productoAcargar.CodArt;
this.productoService.getPromocion(sector, codigo)
.subscribe((res: Promocion[]) => {
if (res.length === 0) {
//Si no tiene promociones la cargará al carrito despues de un tiempo
setTimeout(() => {
this.productoService.productos.push(this.productoAcargar);
this.productoAcargar = undefined;
this.tienePromo = false;
}, 2000)
} else {
this.promociones = res;
this.tienePromo = true;
this.popoverDirective.show();
}
}, error => { console.error(error); })
}
}
showPopover() {
this.popoverDirective.show();
}
private goPage(pageUrl) {
this.router.navigate([pageUrl]);
}
deshacerCarga() {
if (this.productoEsPromo) {
this.promoAcargar = undefined;
this.productoEsPromo = false;
this.popoverDirective.show();
} else {
this.productoAcargar = undefined;
this.tienePromo = false;
this.popoverDirective.hide();
}
}
promoSeleccionada($event: Promocion) {
this.productoEsPromo = true;
this.promoAcargar = $event;
this.popoverDirective.hide();
if (this.promoAcargar.sinonimos) {
var sector = this.promoAcargar.sector;
var codigo = this.promoAcargar.codigo;
this.productoService.getPromocionSinonimos(sector, codigo)
.subscribe((res : Sinonimo[]) => {
this.sinonimos = res;
this.showPopover();
})
}
}
}