Commit ac0476557b8e66d7708ecf48ca9c5c486947924a

Authored by Marcelo Puebla
1 parent 736faa380a
Exists in master

Agregado logica para traer los sinonimos de promociones.

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