Commit da27feb175c65cf5d00cfaa3ae99373d13ee7c84
1 parent
f1d3943fe0
Exists in
master
and in
1 other branch
Arreglo en promos sin imagen, arreglo para abrir popover cuando se selecciona un…
…a promo sin sinonimo.
Showing
2 changed files
with
71 additions
and
66 deletions
Show diff stats
src/app/components/inicio/inicio.component.html
| 1 | <div class="row m-0 fade-in"> | 1 | <div class="row m-0 fade-in"> |
| 2 | <div class="col-12 p-0"> | 2 | <div class="col-12 p-0"> |
| 3 | 3 | ||
| 4 | <!-- NOMBRE DE SECCION --> | 4 | <!-- NOMBRE DE SECCION --> |
| 5 | <div class="row m-0"> | 5 | <div class="row m-0"> |
| 6 | <div class="col-12 p-0"> | 6 | <div class="col-12 p-0"> |
| 7 | <p class="h5 py-1 bg-gray text-muted text-center">Inicio</p> | 7 | <p class="h5 py-1 bg-gray text-muted text-center">Inicio</p> |
| 8 | </div> | 8 | </div> |
| 9 | </div> | 9 | </div> |
| 10 | 10 | ||
| 11 | <div class="row m-3 d-flex align-items-start disable-user-select"> | 11 | <div class="row m-3 d-flex align-items-start disable-user-select"> |
| 12 | <div class="col-md-5 d-flex align-items-end flex-column"> | 12 | <div class="col-md-5 d-flex align-items-end flex-column"> |
| 13 | 13 | ||
| 14 | <!-- PROMOCIONES --> | 14 | <!-- PROMOCIONES --> |
| 15 | <div | 15 | <div |
| 16 | (click)="irBusquedaProductos('promociones')" | 16 | (click)="irBusquedaProductos('promociones')" |
| 17 | class="card card-effect bg-white border-0 shadow rounded w-100 mb-auto"> | 17 | class="card card-effect bg-white border-0 shadow rounded w-100 mb-auto"> |
| 18 | <div class="card-body text-left px-4 py-3"> | 18 | <div class="card-body text-left px-4 py-3"> |
| 19 | <div class="row"> | 19 | <div class="row"> |
| 20 | <div class="col-auto"> | 20 | <div class="col-auto"> |
| 21 | <p class="h3 card-title">Promociones</p> | 21 | <p class="h3 card-title">Promociones</p> |
| 22 | </div> | 22 | </div> |
| 23 | <div class="col-auto p-0"> | 23 | <div class="col-auto p-0"> |
| 24 | <img src="{{apiUrl}}/imagenes/primario.promociones.png" class="icon-dim m-0"> | 24 | <img src="{{apiUrl}}/imagenes/primario.promociones.png" class="icon-dim m-0"> |
| 25 | </div> | 25 | </div> |
| 26 | </div> | 26 | </div> |
| 27 | <p class="h5 card-text text-muted font-weight-light">Conozca las ofertas del momento.</p> | 27 | <p class="h5 card-text text-muted font-weight-light">Conozca las ofertas del momento.</p> |
| 28 | </div> | 28 | </div> |
| 29 | <div id="carouselIndicators" class="carousel slide" data-ride="carousel"> | 29 | <div id="carouselIndicators" class="carousel slide" data-ride="carousel"> |
| 30 | <div class="carousel-inner"> | 30 | <div class="carousel-inner"> |
| 31 | <div class="carousel-item active"> | 31 | <div class="carousel-item active"> |
| 32 | <img src="{{apiUrl}}/imagenes/beldent.jpg" class="d-block w-75 m-auto rounded"> | 32 | <img src="{{apiUrl}}/imagenes/beldent.jpg" class="d-block w-75 m-auto rounded"> |
| 33 | </div> | 33 | </div> |
| 34 | <div class="carousel-item"> | 34 | <div class="carousel-item"> |
| 35 | <img src="{{apiUrl}}/imagenes/cafe con leche y medialunas.jpg" class="d-block w-75 m-auto rounded"> | 35 | <img src="{{apiUrl}}/imagenes/cafe con leche y medialunas.jpg" class="d-block w-75 m-auto rounded"> |
| 36 | </div> | 36 | </div> |
| 37 | <div class="carousel-item"> | 37 | <div class="carousel-item"> |
| 38 | <img src="{{apiUrl}}/imagenes/Surtido bagley.jpg" class="d-block w-75 m-auto rounded"> | 38 | <img src="{{apiUrl}}/imagenes/Surtido bagley.jpg" class="d-block w-75 m-auto rounded"> |
| 39 | </div> | 39 | </div> |
| 40 | <div class="carousel-item"> | 40 | <div class="carousel-item"> |
| 41 | <img src="{{apiUrl}}/imagenes/yogurisimo.jpg" class="d-block w-75 m-auto rounded"> | 41 | <img src="{{apiUrl}}/imagenes/yogurisimo.jpg" class="d-block w-75 m-auto rounded"> |
| 42 | </div> | 42 | </div> |
| 43 | </div> | 43 | </div> |
| 44 | </div> | 44 | </div> |
| 45 | </div> | 45 | </div> |
| 46 | 46 | ||
| 47 | <!-- ORDENAR --> | 47 | <!-- ORDENAR --> |
| 48 | <div (click)="irBusquedaProductos('ordenar')" | 48 | <div (click)="irBusquedaProductos('ordenar')" |
| 49 | class="card card-effect bg-white border-0 shadow rounded w-100 mt-4"> | 49 | class="card card-effect bg-white border-0 shadow rounded w-100 mt-4"> |
| 50 | <div class="card-body text-left px-4 py-3"> | 50 | <div class="card-body text-left px-4 py-3"> |
| 51 | <div class="row"> | 51 | <div class="row"> |
| 52 | <div class="col-auto"> | 52 | <div class="col-auto"> |
| 53 | <p class="h3 card-title">Ordenar Pedido</p> | 53 | <p class="h3 card-title">Ordenar Pedido</p> |
| 54 | </div> | 54 | </div> |
| 55 | <div class="col-auto p-0"> | 55 | <div class="col-auto p-0"> |
| 56 | <img src="{{apiUrl}}/imagenes/primario.ordenar.png" class="icon-dim"> | 56 | <img src="{{apiUrl}}/imagenes/primario.ordenar.png" class="icon-dim"> |
| 57 | </div> | 57 | </div> |
| 58 | </div> | 58 | </div> |
| 59 | <p class="h5 card-text text-muted font-weight-light">Arme su pedido y solo pase a retirar.</p> | 59 | <p class="h5 card-text text-muted font-weight-light">Arme su pedido y solo pase a retirar.</p> |
| 60 | </div> | 60 | </div> |
| 61 | <img | 61 | <img |
| 62 | class="card-img-bottom d-block w-100 mx-auto rounded" | 62 | class="card-img-bottom d-block w-100 mx-auto rounded" |
| 63 | src="{{apiUrl}}/imagenes/cafe.jpg"> | 63 | src="{{apiUrl}}/imagenes/cafe.jpg"> |
| 64 | </div> | 64 | </div> |
| 65 | </div> | 65 | </div> |
| 66 | 66 | ||
| 67 | <div class="col-md-7 d-flex align-items-end flex-column mt-4 mt-md-0"> | 67 | <div class="col-md-7 d-flex align-items-end flex-column mt-4 mt-md-0"> |
| 68 | 68 | ||
| 69 | <!-- CARGAR PRODUCTOS --> | 69 | <!-- CARGAR PRODUCTOS --> |
| 70 | <ng-template #popTemplate> | 70 | <ng-template #popTemplate> |
| 71 | <app-popover-promos | 71 | <app-popover-promos |
| 72 | *ngIf="promociones.length > 0 && sinonimos.length === 0" | 72 | *ngIf="promociones.length > 0 && sinonimos.length === 0" |
| 73 | [popover]="popoverDirective" | 73 | [popover]="popoverDirective" |
| 74 | [popoverContent]="promociones" | 74 | [popoverContent]="promociones" |
| 75 | (promoSeleccionada)="promoSeleccionada($event)" | 75 | (promoSeleccionada)="promoSeleccionada($event, false)" |
| 76 | class="text-white rounded-sm border-0"> | 76 | class="text-white rounded-sm border-0"> |
| 77 | </app-popover-promos> | 77 | </app-popover-promos> |
| 78 | <app-popover-sinonimos | 78 | <app-popover-sinonimos |
| 79 | *ngIf="sinonimos.length > 0" | 79 | *ngIf="sinonimos.length > 0" |
| 80 | [popover]="popoverDirective" | 80 | [popover]="popoverDirective" |
| 81 | [popoverContent]="sinonimos" | 81 | [popoverContent]="sinonimos" |
| 82 | (productosPersonalizados)="productosPersonalizados($event)" | 82 | (productosPersonalizados)="productosPersonalizados($event)" |
| 83 | class="text-white rounded-sm border-0"> | 83 | class="text-white rounded-sm border-0"> |
| 84 | </app-popover-sinonimos> | 84 | </app-popover-sinonimos> |
| 85 | </ng-template> | 85 | </ng-template> |
| 86 | <div | 86 | <div |
| 87 | placement="left" | 87 | placement="left" |
| 88 | triggers="" | 88 | triggers="" |
| 89 | [popover]="popTemplate" | 89 | [popover]="popTemplate" |
| 90 | class="w-100" | 90 | class="w-100" |
| 91 | #pop="bs-popover"> | 91 | #pop="bs-popover"> |
| 92 | <div class="card bg-white border-0 shadow rounded mb-auto"> | 92 | <div class="card bg-white border-0 shadow rounded mb-auto"> |
| 93 | <div class="card-body text-left px-4 py-3"> | 93 | <div class="card-body text-left px-4 py-3"> |
| 94 | <div class="row"> | 94 | <div class="row"> |
| 95 | <div class="col-auto"> | 95 | <div class="col-auto"> |
| 96 | <p class="h3 card-title">Cargar Productos</p> | 96 | <p class="h3 card-title">Cargar Productos</p> |
| 97 | </div> | 97 | </div> |
| 98 | <div class="col-auto p-0"> | 98 | <div class="col-auto p-0"> |
| 99 | <img src="{{apiUrl}}/imagenes/escanear.png" class="icon-dim mb-2"> | 99 | <img src="{{apiUrl}}/imagenes/escanear.png" class="icon-dim mb-2"> |
| 100 | </div> | 100 | </div> |
| 101 | </div> | 101 | </div> |
| 102 | <p class="h5 card-text text-muted font-weight-light"> | 102 | <p class="h5 card-text text-muted font-weight-light"> |
| 103 | Coloque un producto frente<br> | 103 | Coloque un producto frente<br> |
| 104 | al lector de códigos o selecciónelo en pantalla. | 104 | al lector de códigos o selecciónelo en pantalla. |
| 105 | </p> | 105 | </p> |
| 106 | </div> | 106 | </div> |
| 107 | <div class="row m-4"> | 107 | <div class="row m-4"> |
| 108 | <div class="col card bg-white shadow border-0 w-75 p-0 mx-auto rounded-sm"> | 108 | <div class="col card bg-white shadow border-0 w-75 p-0 mx-auto rounded-sm"> |
| 109 | <!-- IMAGEN DE ESCANER --> | 109 | <!-- IMAGEN DE ESCANER --> |
| 110 | <img | 110 | <img |
| 111 | *ngIf="!productoAcargar" | 111 | *ngIf="!productoAcargar" |
| 112 | class="card-img-top d-block w-100 mx-auto rounded-sm" | 112 | class="card-img-top d-block w-100 mx-auto rounded-sm" |
| 113 | src="{{apiUrl}}/imagenes/escanner.jpg"> | 113 | src="{{apiUrl}}/imagenes/escanner.jpg"> |
| 114 | 114 | ||
| 115 | <!-- PRODUCTO A CARGAR --> | 115 | <!-- PRODUCTO A CARGAR --> |
| 116 | <div class="fade-in m-0" *ngIf="productoAcargar && !promoAcargar"> | 116 | <div class="fade-in m-0" *ngIf="productoAcargar && !promoAcargar"> |
| 117 | <img | 117 | <img |
| 118 | class="card-img-top d-block w-75 mx-auto rounded-sm" | 118 | class="card-img-top d-block w-75 mx-auto rounded-sm" |
| 119 | src="{{apiUrl}}/imagenes/{{productoAcargar.imagenes[0].imagen}}"> | 119 | src="{{apiUrl}}/imagenes/{{productoAcargar.imagenes[0].imagen}}"> |
| 120 | 120 | ||
| 121 | <div class="row justify-content-between m-3"> | 121 | <div class="row justify-content-between m-3"> |
| 122 | <div class="col-12 text-left px-1"> | 122 | <div class="col-12 text-left px-1"> |
| 123 | <p class="h6 font-weight-bold mb-0">{{productoAcargar.DET_LAR}}</p> | 123 | <p class="h6 font-weight-bold mb-0">{{productoAcargar.DET_LAR}}</p> |
| 124 | </div> | 124 | </div> |
| 125 | <div class="col-12 text-right mt-2"> | 125 | <div class="col-12 text-right mt-2"> |
| 126 | <p class="h5 font-weight-bold mb-0">{{productoAcargar.PreVen | currency}}</p> | 126 | <p class="h5 font-weight-bold mb-0">{{productoAcargar.PreVen | currency}}</p> |
| 127 | </div> | 127 | </div> |
| 128 | </div> | 128 | </div> |
| 129 | </div> | 129 | </div> |
| 130 | 130 | ||
| 131 | <!-- PROMO A CARGAR --> | 131 | <!-- PROMO A CARGAR --> |
| 132 | <div class="fade-in m-0" *ngIf="promoAcargar"> | 132 | <div class="fade-in m-0" *ngIf="promoAcargar"> |
| 133 | <img | 133 | <img |
| 134 | class="card-img-top d-block w-100 mx-auto rounded-sm" | 134 | class="card-img-top d-block w-100 mx-auto rounded-sm" |
| 135 | src="{{apiUrl}}/imagenes/{{promoAcargar.imagenes[0].imagen}}"> | 135 | src="{{apiUrl}}/imagenes/{{promoAcargar.imagenes[0].imagen}}"> |
| 136 | 136 | ||
| 137 | <div class="row justify-content-between m-3"> | 137 | <div class="row justify-content-between m-3"> |
| 138 | <div class="col-12 text-left px-1"> | 138 | <div class="col-12 text-left px-1"> |
| 139 | <p class="h6 font-weight-bold mb-0">{{promoAcargar.DET_LAR}}</p> | 139 | <p class="h6 font-weight-bold mb-0">{{promoAcargar.DET_LAR}}</p> |
| 140 | </div> | 140 | </div> |
| 141 | <div class="col-12 text-right mt-2 align-self-end"> | 141 | <div class="col-12 text-right mt-2 align-self-end"> |
| 142 | <p class="h5 font-weight-bold mb-0">{{promoAcargar.PreVen | currency}}</p> | 142 | <p class="h5 font-weight-bold mb-0">{{promoAcargar.PreVen | currency}}</p> |
| 143 | </div> | 143 | </div> |
| 144 | </div> | 144 | </div> |
| 145 | </div> | 145 | </div> |
| 146 | 146 | ||
| 147 | </div> | 147 | </div> |
| 148 | <!-- BOTONES DE CARGAR PRODUCTOS--> | 148 | <!-- BOTONES DE CARGAR PRODUCTOS--> |
| 149 | <div | 149 | <div |
| 150 | class="col-5 pr-0" | 150 | class="col-5 pr-0" |
| 151 | *ngIf="promociones.length > 0"> | 151 | *ngIf="promociones.length > 0"> |
| 152 | <button | 152 | <button |
| 153 | *ngIf="!promoAcargar || sinonimos.length == 0" | 153 | *ngIf="!promoAcargar || sinonimos.length == 0" |
| 154 | type="button" | 154 | type="button" |
| 155 | class="btn btn-primary btn-block shadow-sm" | 155 | class="btn btn-primary btn-block shadow-sm" |
| 156 | (click)="pop.show()"> | 156 | (click)="pop.show()"> |
| 157 | <span class="pr-2">Mostrar promociones</span> | 157 | <span class="pr-2">Mostrar promociones</span> |
| 158 | <i class="fa fa-bullhorn fa-flip-horizontal" aria-hidden="true"></i> | 158 | <i class="fa fa-bullhorn fa-flip-horizontal" aria-hidden="true"></i> |
| 159 | </button> | 159 | </button> |
| 160 | <button | 160 | <button |
| 161 | type="button" | 161 | type="button" |
| 162 | class="btn btn-light btn-block shadow-sm my-3" | 162 | class="btn btn-light btn-block shadow-sm my-3" |
| 163 | (click)="confirmarProducto()"> | 163 | (click)="confirmarProducto()"> |
| 164 | <span class="pr-2 font-weight-bold">Confirmar</span> | 164 | <span class="pr-2 font-weight-bold">Confirmar</span> |
| 165 | <i class="fa fa-check text-success" aria-hidden="true"></i> | 165 | <i class="fa fa-check text-success" aria-hidden="true"></i> |
| 166 | </button> | 166 | </button> |
| 167 | <button | 167 | <button |
| 168 | type="button" | 168 | type="button" |
| 169 | class="btn btn-light btn-block shadow-sm" | 169 | class="btn btn-light btn-block shadow-sm" |
| 170 | (click)="deshacerCarga()"> | 170 | (click)="deshacerCarga()"> |
| 171 | <span class="pr-2">Deshacer</span> | 171 | <span class="pr-2">Deshacer</span> |
| 172 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> | 172 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> |
| 173 | </button> | 173 | </button> |
| 174 | </div> | 174 | </div> |
| 175 | </div> | 175 | </div> |
| 176 | </div> | 176 | </div> |
| 177 | </div> | 177 | </div> |
| 178 | 178 | ||
| 179 | <!-- BUSCAR PRODUCTOS --> | 179 | <!-- BUSCAR PRODUCTOS --> |
| 180 | <div (click)="irBusquedaProductos('todos')" | 180 | <div (click)="irBusquedaProductos('todos')" |
| 181 | class="card card-effect bg-white border-0 shadow rounded w-100 mt-4"> | 181 | class="card card-effect bg-white border-0 shadow rounded w-100 mt-4"> |
| 182 | <div class="card-body text-left px-4 py-3"> | 182 | <div class="card-body text-left px-4 py-3"> |
| 183 | <div class="row"> | 183 | <div class="row"> |
| 184 | <div class="col-auto"> | 184 | <div class="col-auto"> |
| 185 | <p class="h3 card-title">Buscar Productos</p> | 185 | <p class="h3 card-title">Buscar Productos</p> |
| 186 | <p class="h5 card-text text-muted font-weight-light"> | 186 | <p class="h5 card-text text-muted font-weight-light"> |
| 187 | Busque aquí los productos<br> | 187 | Busque aquí los productos<br> |
| 188 | que no tienen código.</p> | 188 | que no tienen código.</p> |
| 189 | </div> | 189 | </div> |
| 190 | <div class="col-auto p-0"> | 190 | <div class="col-auto p-0"> |
| 191 | <img src="{{apiUrl}}/imagenes/primario.buscar.png" class="icon-dim mb-2"> | 191 | <img src="{{apiUrl}}/imagenes/primario.buscar.png" class="icon-dim mb-2"> |
| 192 | </div> | 192 | </div> |
| 193 | </div> | 193 | </div> |
| 194 | 194 | ||
| 195 | </div> | 195 | </div> |
| 196 | </div> | 196 | </div> |
| 197 | 197 | ||
| 198 | </div> | 198 | </div> |
| 199 | 199 | ||
| 200 | </div> | 200 | </div> |
| 201 | 201 | ||
| 202 | </div> | 202 | </div> |
| 203 | </div> | 203 | </div> |
| 204 | 204 |
src/app/components/inicio/inicio.component.ts
| 1 | import { Component, OnInit, ViewChild, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, ViewChild, HostListener, AfterViewInit } 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 { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
| 5 | import { ProductoService } from 'src/app/services/producto.service'; | 5 | import { ProductoService } from 'src/app/services/producto.service'; |
| 6 | import { Producto } from 'src/app/wrappers/producto'; | 6 | import { Producto } from 'src/app/wrappers/producto'; |
| 7 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; | 7 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
| 8 | 8 | ||
| 9 | @Component({ | 9 | @Component({ |
| 10 | selector: 'app-inicio', | 10 | selector: 'app-inicio', |
| 11 | templateUrl: './inicio.component.html', | 11 | templateUrl: './inicio.component.html', |
| 12 | styleUrls: ['./inicio.component.scss'] | 12 | styleUrls: ['./inicio.component.scss'] |
| 13 | }) | 13 | }) |
| 14 | export class InicioComponent implements OnInit { | 14 | export class InicioComponent implements OnInit, AfterViewInit { |
| 15 | 15 | ||
| 16 | private tienePromo = false; | 16 | private tienePromo = false; |
| 17 | private productoEsPromo = false; | 17 | private productoEsPromo = false; |
| 18 | private busqueda: string = ''; | 18 | private busqueda: string = ''; |
| 19 | private productoAcargar: Producto; | 19 | private productoAcargar: Producto; |
| 20 | private promoAcargar: Producto; | 20 | private promoAcargar: Producto; |
| 21 | private productos: Producto[] = []; | 21 | private productos: Producto[] = []; |
| 22 | private promociones: Producto[] = []; | 22 | private promociones: Producto[] = []; |
| 23 | private sinonimos: Sinonimo[] = []; | 23 | private sinonimos: Sinonimo[] = []; |
| 24 | private apiUrl: string = appSettings.apiUrl | 24 | private apiUrl: string = appSettings.apiUrl |
| 25 | 25 | ||
| 26 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; | 26 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; |
| 27 | 27 | ||
| 28 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { | 28 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { |
| 29 | 29 | ||
| 30 | if (e.keyCode == 13) { | 30 | if (e.keyCode == 13) { |
| 31 | this.buscarByCodigoBarras(this.busqueda); | 31 | this.buscarByCodigoBarras(this.busqueda); |
| 32 | this.busqueda = ''; | 32 | this.busqueda = ''; |
| 33 | } else { | 33 | } else { |
| 34 | this.busqueda += e.key; | 34 | this.busqueda += e.key; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | constructor( | 39 | constructor( |
| 40 | private router: Router, | 40 | private router: Router, |
| 41 | private productoService: ProductoService) { } | 41 | private productoService: ProductoService |
| 42 | ) { } | ||
| 42 | 43 | ||
| 43 | ngOnInit() { | 44 | ngOnInit() { |
| 44 | 45 | ||
| 45 | this.productoAcargar = this.productoService.productoAcargar; | 46 | this.productoAcargar = this.productoService.productoAcargar; |
| 46 | if (this.productoAcargar) { | 47 | this.getProductos(); |
| 48 | } | ||
| 49 | |||
| 50 | ngAfterViewInit() { | ||
| 51 | |||
| 52 | setTimeout(() => { | ||
| 53 | if (!this.productoAcargar) return; | ||
| 54 | |||
| 47 | if (this.productoAcargar.PRO) { | 55 | if (this.productoAcargar.PRO) { |
| 48 | this.promociones.push(this.productoAcargar); | 56 | this.promociones.push(this.productoAcargar); |
| 49 | this.promoSeleccionada(this.productoAcargar); | 57 | this.promoSeleccionada(this.productoAcargar, true); |
| 50 | } | 58 | } |
| 51 | else | 59 | else { |
| 52 | this.getPromociones(); | 60 | this.getPromociones(); |
| 53 | } | 61 | } |
| 54 | this.getProductos(); | 62 | }) |
| 63 | } | ||
| 64 | |||
| 65 | getProductos() { | ||
| 66 | |||
| 67 | this.productoService.getAll() | ||
| 68 | .subscribe((productos: Producto[]) => { | ||
| 69 | this.productos = productos; | ||
| 70 | }); | ||
| 55 | } | 71 | } |
| 56 | 72 | ||
| 57 | getPromociones() { | 73 | getPromociones() { |
| 58 | 74 | ||
| 59 | var sector = this.productoAcargar.CodSec; | 75 | var sector = this.productoAcargar.CodSec; |
| 60 | var codigo = this.productoAcargar.CodArt; | 76 | var codigo = this.productoAcargar.CodArt; |
| 61 | this.productoService.getPromociones(sector, codigo) | 77 | this.productoService.getPromociones(sector, codigo) |
| 62 | .subscribe((res: Producto[]) => { | 78 | .subscribe((res: Producto[]) => { |
| 63 | 79 | ||
| 64 | if (res.length === 0) { | 80 | if (res.length === 0) { |
| 65 | //Si no tiene promociones la cargará al carrito despues de un tiempo | 81 | |
| 66 | // setTimeout(() => { | ||
| 67 | this.productoAcargar.cantidad = 1; | 82 | this.productoAcargar.cantidad = 1; |
| 68 | this.productoService.productos.push(this.productoAcargar); | 83 | this.productoService.productos.push(this.productoAcargar); |
| 69 | this.productoAcargar = this.productoService.productoAcargar = undefined; | 84 | this.productoAcargar = this.productoService.productoAcargar = undefined; |
| 70 | // }, 2000) | ||
| 71 | } else { | 85 | } else { |
| 72 | 86 | ||
| 73 | this.promociones = res; | 87 | this.promociones = res; |
| 74 | this.popoverDirective.show(); | 88 | this.popoverDirective.show(); |
| 75 | } | 89 | } |
| 76 | }, error => { console.error(error); }) | 90 | }, error => { console.error(error); }) |
| 77 | } | 91 | } |
| 78 | 92 | ||
| 79 | getProductos() { | ||
| 80 | |||
| 81 | this.productoService.getAll() | ||
| 82 | .subscribe((productos: Producto[]) => { | ||
| 83 | this.productos = productos; | ||
| 84 | }); | ||
| 85 | } | ||
| 86 | |||
| 87 | irBusquedaProductos(value) { | ||
| 88 | |||
| 89 | this.productoService.mostrar = value; | ||
| 90 | this.router.navigate(['busqueda-productos']); | ||
| 91 | } | ||
| 92 | |||
| 93 | confirmarProducto() { | 93 | confirmarProducto() { |
| 94 | |||
| 94 | var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; | 95 | var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; |
| 95 | producto.cantidad = 1; | 96 | producto.cantidad = 1; |
| 96 | this.productoService.productos.push(producto); | 97 | this.productoService.productos.push(producto); |
| 97 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; | 98 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; |
| 98 | this.promociones = []; | 99 | this.promociones = []; |
| 99 | this.popoverDirective.hide(); | 100 | this.popoverDirective.hide(); |
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | deshacerCarga() { | 103 | promoSeleccionada($event: Producto, showPopover: boolean) { |
| 103 | 104 | ||
| 104 | if (this.sinonimos.length > 0) { | 105 | this.productoService.getProductoById($event.id) |
| 105 | this.sinonimos = []; | 106 | .subscribe((res: Producto) => { |
| 106 | this.popoverDirective.hide(); | 107 | |
| 107 | } | 108 | $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; |
| 109 | this.promoAcargar = $event; | ||
| 108 | 110 | ||
| 109 | if (this.promoAcargar) { | 111 | if ($event.tieneSinonimos) { |
| 110 | this.promoAcargar = undefined; | ||
| 111 | if (this.productoAcargar.PRO) { | ||
| 112 | this.productoAcargar = undefined; | ||
| 113 | this.promociones = []; | ||
| 114 | this.popoverDirective.hide(); | ||
| 115 | } else { | ||
| 116 | this.popoverDirective.show(); | ||
| 117 | } | ||
| 118 | } else { | ||
| 119 | this.productoAcargar = undefined; | ||
| 120 | this.promociones = []; | ||
| 121 | this.popoverDirective.hide(); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | promoSeleccionada($event: Producto) { | ||
| 126 | |||
| 127 | if ($event.tieneSinonimos) { | ||
| 128 | |||
| 129 | this.productoService.getProductoById($event.id) | ||
| 130 | .subscribe((res: Producto) => { | ||
| 131 | |||
| 132 | $event.imagenes = res.imagenes; | ||
| 133 | this.promoAcargar = $event; | ||
| 134 | this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); | 112 | this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); |
| 135 | }, | 113 | } else if (showPopover) { |
| 136 | error => { console.log(error); }) | 114 | this.popoverDirective.show(); |
| 137 | 115 | } else { | |
| 116 | this.popoverDirective.hide(); | ||
| 117 | } | ||
| 138 | 118 | ||
| 139 | } else if (this.popoverDirective) { | 119 | }, |
| 140 | this.popoverDirective.hide(); | 120 | error => { console.log(error); }) |
| 141 | } | ||
| 142 | } | 121 | } |
| 143 | 122 | ||
| 144 | getSinonimos(sector, codigo) { | 123 | getSinonimos(sector, codigo) { |
| 145 | 124 | ||
| 146 | this.productoService.getPromocionSinonimos(sector, codigo) | 125 | this.productoService.getPromocionSinonimos(sector, codigo) |
| 147 | .subscribe((res: Sinonimo[]) => { | 126 | .subscribe((res: Sinonimo[]) => { |
| 148 | 127 | ||
| 149 | res.forEach(sinonimo => { | 128 | res.forEach(sinonimo => { |
| 150 | 129 | ||
| 151 | sinonimo.productos.forEach(productoSinonimo => { | 130 | sinonimo.productos.forEach(productoSinonimo => { |
| 152 | 131 | ||
| 153 | this.promoAcargar.productos.forEach(productoPromo => { | 132 | this.promoAcargar.productos.forEach(productoPromo => { |
| 154 | 133 | ||
| 155 | if (productoSinonimo.id === productoPromo.id) { | 134 | if (productoSinonimo.id === productoPromo.id) { |
| 156 | sinonimo.cantidad = productoPromo.cantidad; | 135 | sinonimo.cantidad = productoPromo.cantidad; |
| 157 | sinonimo.productoPadre = productoPromo.id; | 136 | sinonimo.productoPadre = productoPromo.id; |
| 158 | } | 137 | } |
| 159 | }) | 138 | }) |
| 160 | }) | 139 | }) |
| 161 | }) | 140 | }) |
| 162 | 141 | ||
| 163 | this.sinonimos = res; | 142 | this.sinonimos = res; |
| 164 | if (res.length > 0) | 143 | (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); |
| 165 | this.popoverDirective.show(); | ||
| 166 | else | ||
| 167 | this.popoverDirective.hide(); | ||
| 168 | }) | 144 | }) |
| 169 | } | 145 | } |
| 170 | 146 | ||
| 171 | productosPersonalizados($event: Producto[]) { | 147 | productosPersonalizados($event: Producto[]) { |
| 172 | 148 | ||
| 173 | var productosPersonalizados = $event; | 149 | var productosPersonalizados = $event; |
| 174 | 150 | ||
| 175 | this.promoAcargar.productos.forEach(productoPromo => { | 151 | this.promoAcargar.productos.forEach(productoPromo => { |
| 176 | 152 | ||
| 177 | if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); | 153 | if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); |
| 178 | }) | 154 | }) |
| 179 | 155 | ||
| 180 | this.promoAcargar.productos = productosPersonalizados; | 156 | this.promoAcargar.productos = productosPersonalizados; |
| 181 | this.confirmarProducto(); | 157 | this.confirmarProducto(); |
| 182 | } | 158 | } |
| 183 | 159 | ||
| 184 | buscarByCodigoBarras(busqueda) { | 160 | buscarByCodigoBarras(busqueda) { |
| 185 | 161 | ||
| 186 | let producto = this.productos.filter(producto => { | 162 | let producto = this.productos.filter(producto => { |
| 187 | return producto.codigoBarra == busqueda; | 163 | return producto.codigoBarra == busqueda; |