inicio.component.ts
1.95 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
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';
@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 tienePromo = false;
popoverContent: Promocion[] = []
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((promociones: Promocion[]) => {
if (promociones.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.popoverContent = promociones;
this.tienePromo = true;
this.popoverDirective.show();
}
}, error => { console.error(error); })
}
}
showPopover() {
this.popoverDirective.show();
}
private goPage(pageUrl) {
this.router.navigate([pageUrl]);
}
deshacerCarga() {
this.productoAcargar = undefined;
this.tienePromo = false;
this.popoverDirective.hide();
}
}