Commit 8c68a0e91e8685f6f097abe2672cc7cb3c363c8d

Authored by Marcelo Puebla
1 parent 14c393de40
Exists in master

Agregadas animations..

src/app/components/sidebar/sidebar.component.html
1 <div class="disable-user-select d-flex align-items-center flex-column h-100 text-center"> 1 <div class="disable-user-select d-flex align-items-center flex-column h-100 text-center">
2 2
3 <!-- ENCABEZADO --> 3 <!-- ENCABEZADO -->
4 <p class="h4 border-bottom border-white text-white pb-2"> 4 <p class="h4 border-bottom border-white text-white pb-2">
5 Mi compra 5 Mi compra
6 <i class="fa fa-shopping-cart" aria-hidden="true"></i> 6 <i class="fa fa-shopping-cart" aria-hidden="true"></i>
7 </p> 7 </p>
8 8
9 <div class="overflow-scroll px-1 mb-1 w-100"> 9 <div class="overflow-scroll px-1 mb-1 w-100">
10 <!-- PRODUCTOS CARRITO --> 10 <!-- PRODUCTOS CARRITO -->
11 <div class="row m-0" 11 <div class="row m-0"
12 *ngFor="let producto of productosCarrito; let i = index"> 12 *ngFor="let producto of productosCarrito; let i = index"
13 [@EnterLeave]="flyIn">
13 <div class="col p-0 my-1 bg-white border-0 rounded-sm"> 14 <div class="col p-0 my-1 bg-white border-0 rounded-sm">
14 <div class="row m-0"> 15 <div class="row m-0">
15 <div class="col-6 pl-1 pr-0 my-auto"> 16 <div class="col-6 pl-1 pr-0 my-auto">
16 <img 17 <img
17 class="w-100 float-left rounded-sm shadow" 18 class="w-100 float-left rounded-sm shadow"
18 src="{{apiImagenes}}/imagenes/{{producto.imagenes[0].imagen}}"> 19 src="{{apiImagenes}}/imagenes/{{producto.imagenes[0].imagen}}">
19 </div> 20 </div>
20 <div class="col-6 px-1"> 21 <div class="col-6 px-1">
21 <!-- BOTONES --> 22 <!-- BOTONES -->
22 <div class="row m-0 d-flex justify-content-between"> 23 <div class="row m-0 d-flex justify-content-between">
23 24
24 <!-- SUMAR - RESTAR CANTIDAD --> 25 <!-- SUMAR - RESTAR CANTIDAD -->
25 <div class="col p-1"> 26 <div class="col p-1">
26 <div class="btn-group-sm btn-group float-left" role="group"> 27 <div class="btn-group-sm btn-group float-left" role="group">
27 <button 28 <button
28 type="button" 29 type="button"
29 class="btn btn-light btn-sm border shadow" 30 class="btn btn-light btn-sm border shadow"
30 (click)="aumentarCantidad(producto)"> 31 (click)="aumentarCantidad(producto)">
31 <i class="fa fa-plus" aria-hidden="true"></i> 32 <i class="fa fa-plus" aria-hidden="true"></i>
32 </button> 33 </button>
33 <div class="bg-white border border-white my-auto px-2 text-dark h5 shadow"> 34 <div class="bg-white border border-white my-auto px-2 text-dark h5 shadow">
34 <small>{{producto.cantidad}}</small> 35 <small>{{producto.cantidad}}</small>
35 </div> 36 </div>
36 <button 37 <button
37 type="button" 38 type="button"
38 class="btn btn-light btn-sm border shadow" 39 class="btn btn-light btn-sm border shadow"
39 (click)="restarCantidad(producto)"> 40 (click)="restarCantidad(producto)">
40 <i class="fa fa-minus" aria-hidden="true"></i> 41 <i class="fa fa-minus" aria-hidden="true"></i>
41 </button> 42 </button>
42 </div> 43 </div>
43 </div> 44 </div>
44 45
45 <!-- PERSONALIZAR --> 46 <!-- PERSONALIZAR -->
46 <div class="col p-1"> 47 <div class="col p-1">
47 <button 48 <button
48 *ngIf="producto.tieneSinonimos" 49 *ngIf="producto.tieneSinonimos"
49 type="button" 50 type="button"
50 class="btn btn-light btn-sm float-left border shadow" 51 class="btn btn-light btn-sm float-left border shadow"
51 (click)="personalizarPromo(producto, i)"> 52 (click)="personalizarPromo(producto, i)">
52 <i class="fa fa-refresh text-purple" aria-hidden="true"></i> 53 <i class="fa fa-refresh text-purple" aria-hidden="true"></i>
53 </button> 54 </button>
54 </div> 55 </div>
55 56
56 <!-- BORRAR --> 57 <!-- BORRAR -->
57 <div class="col p-1"> 58 <div class="col p-1">
58 <button 59 <button
59 type="button" 60 type="button"
60 class="btn btn-secondary btn-sm float-right shadow" 61 class="btn btn-secondary btn-sm float-right shadow"
61 (click)="deleteProducto(producto, i)"> 62 (click)="deleteProducto(producto, i)">
62 <i class="fa fa-trash" aria-hidden="true"></i> 63 <i class="fa fa-trash" aria-hidden="true"></i>
63 </button> 64 </button>
64 </div> 65 </div>
65 </div> 66 </div>
66 </div> 67 </div>
67 </div> 68 </div>
68 <div class="row m-0 shadow rounded-sm"> 69 <div class="row m-0 shadow rounded-sm">
69 <div class="col px-2"> 70 <div class="col px-2">
70 <p class="m-0 text-left h6"><small>{{producto.DetArt}}</small></p> 71 <p class="m-0 text-left h6"><small>{{producto.DetArt}}</small></p>
71 <p class="m-0 text-right font-weight-bold h6">{{producto.PreVen | currency}}</p> 72 <p class="m-0 text-right font-weight-bold h6">{{producto.PreVen | currency}}</p>
72 </div> 73 </div>
73 </div> 74 </div>
74 </div> 75 </div>
75 </div> 76 </div>
76 </div> 77 </div>
77 78
78 <!-- TOTAL --> 79 <!-- TOTAL -->
79 <div class="card rounded-top-sm mx-2 mt-auto blue-gradient border-0"> 80 <div class="card rounded-top-sm mx-2 mt-auto blue-gradient border-0">
80 <div class="card-body p-2 pt-3 row m-0"> 81 <div class="card-body p-2 pt-3 row m-0">
81 <div class="col-12 p-0"> 82 <div class="col-12 p-0">
82 <p 83 <p
83 class="h4 border-bottom border-secondary text-secondary pb-2"> 84 class="h4 border-bottom border-secondary text-secondary pb-2">
84 ({{getCantidadProductos()}}) artículos 85 ({{getCantidadProductos()}}) artículos
85 </p> 86 </p>
86 <p class="h4 text-secondary">Total</p> 87 <p class="h4 text-secondary">Total</p>
87 <p class="h2 font-weight-bold">{{getTotal() | currency}}</p> 88 <p class="h2 font-weight-bold">{{getTotal() | currency}}</p>
88 </div> 89 </div>
89 <div class="col-12 p-0"> 90 <div class="col-12 p-0">
90 <button 91 <button
91 *ngIf="getCantidadProductos() > 0" 92 *ngIf="getCantidadProductos() > 0"
92 type="button" 93 type="button"
93 class="btn btn-block btn-light btn-lg shadow mb-2 p-1" 94 class="btn btn-block btn-light btn-lg shadow mb-2 p-1"
94 routerLink="/confirmacion-carrito"> 95 routerLink="/confirmacion-carrito">
95 <span class="font-weight-bold pr-1">Pagar</span> 96 <span class="font-weight-bold pr-1">Pagar</span>
96 <i class="fa fa-check text-success" aria-hidden="true"></i> 97 <i class="fa fa-check text-success" aria-hidden="true"></i>
97 </button> 98 </button>
98 <button 99 <button
99 type="button" 100 type="button"
100 class="btn btn-block btn-light shadow btn-sm shadow" 101 class="btn btn-block btn-light shadow btn-sm shadow"
101 [routerLink]="['/cancelar-compra']"> 102 [routerLink]="['/cancelar-compra']">
102 <span class="pr-1">Cancelar</span> 103 <span class="pr-1">Cancelar</span>
103 <i class="fa fa-times text-danger" aria-hidden="true"></i> 104 <i class="fa fa-times text-danger" aria-hidden="true"></i>
104 </button> 105 </button>
105 </div> 106 </div>
106 </div> 107 </div>
107 </div> 108 </div>
108 </div> 109 </div>
109 110
src/app/components/sidebar/sidebar.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { Producto } from 'src/app/wrappers/producto'; 2 import { Producto } from 'src/app/wrappers/producto';
3 import { appSettings } from 'src/etc/AppSettings'; 3 import { appSettings } from 'src/etc/AppSettings';
4 import { ProductoService } from 'src/app/services/producto.service'; 4 import { ProductoService } from 'src/app/services/producto.service';
5 import { Router } from '@angular/router'; 5 import { Router } from '@angular/router';
6 import { trigger, state, style, transition, animate } from '@angular/animations';
6 7
7 @Component({ 8 @Component({
8 selector: 'app-sidebar', 9 selector: 'app-sidebar',
9 templateUrl: './sidebar.component.html', 10 templateUrl: './sidebar.component.html',
10 styleUrls: ['./sidebar.component.scss'], 11 styleUrls: ['./sidebar.component.scss'],
12 animations: [
13 trigger('EnterLeave', [
14 state('flyIn', style({ transform: 'translateX(0)' })),
15 transition(':enter', [
16 style({ transform: 'translateX(-100%)' }),
17 animate('0.3s ease-in')
18 ]),
19 transition(':leave', [
20 animate('0.3s ease-out', style({ transform: 'translateX(-100%)' }))
21 ])
22 ])
23 ]
11 }) 24 })
12 export class SidebarComponent implements OnInit { 25 export class SidebarComponent implements OnInit {
13 26
14 private cantTotal: number = 0; 27 private cantTotal: number = 0;
15 private cantMin: number = 1; 28 private cantMin: number = 1;
16 private cantMax: number = 50; 29 private cantMax: number = 50;
17 private total: number = 0; 30 private total: number = 0;
18 private apiImagenes: string = appSettings.apiImagenes; 31 private apiImagenes: string = appSettings.apiImagenes;
19 32
20 public productosCarrito: Producto[] = []; 33 public productosCarrito: Producto[] = [];
21 34
22 constructor( 35 constructor(
23 private productoService: ProductoService, 36 private productoService: ProductoService,
24 private router: Router) { 37 private router: Router) {
25 this.router.routeReuseStrategy.shouldReuseRoute = function () { 38 this.router.routeReuseStrategy.shouldReuseRoute = function () {
26 return false; 39 return false;
27 } 40 }
28 } 41 }
29 42
30 ngOnInit() { 43 ngOnInit() {
31 44
32 this.productosCarrito = this.productoService.productos; 45 this.productosCarrito = this.productoService.productos;
33 } 46 }
34 47
35 getCantidadProductos() { 48 getCantidadProductos() {
36 49
37 var cantTotalAux = 0; 50 var cantTotalAux = 0;
38 this.productosCarrito.forEach(producto => { 51 this.productosCarrito.forEach(producto => {
39 52
40 cantTotalAux += producto.cantidad; 53 cantTotalAux += producto.cantidad;
41 }); 54 });
42 this.cantTotal = cantTotalAux; 55 this.cantTotal = cantTotalAux;
43 56
44 return this.cantTotal; 57 return this.cantTotal;
45 } 58 }
46 59
47 getTotal() { 60 getTotal() {
48 61
49 var subTotal = 0; 62 var subTotal = 0;
50 for (let i = 0; i < this.productosCarrito.length; i++) { 63 for (let i = 0; i < this.productosCarrito.length; i++) {
51 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); 64 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
52 } 65 }
53 return this.total = subTotal; 66 return this.total = subTotal;
54 } 67 }
55 68
56 aumentarCantidad(producto: Producto) { 69 aumentarCantidad(producto: Producto) {
57 70
58 if (producto.cantidad < this.cantMax) { 71 if (producto.cantidad < this.cantMax) {
59 producto.cantidad++; 72 producto.cantidad++;
60 this.cantTotal++ 73 this.cantTotal++
61 } 74 }
62 } 75 }
63 76
64 restarCantidad(producto: Producto) { 77 restarCantidad(producto: Producto) {
65 78
66 if (producto.cantidad > this.cantMin) { 79 if (producto.cantidad > this.cantMin) {
67 producto.cantidad--; 80 producto.cantidad--;
68 this.cantTotal--; 81 this.cantTotal--;
69 } 82 }
70 } 83 }
71 84
72 deleteProducto(producto: Producto, index: number) { 85 deleteProducto(producto: Producto, index: number) {
73 86
74 this.cantTotal -= producto.cantidad; 87 this.cantTotal -= producto.cantidad;
75 this.total -= producto.PreVen * producto.cantidad; 88 this.total -= producto.PreVen * producto.cantidad;
76 this.productosCarrito.splice(index, 1); 89 this.productosCarrito.splice(index, 1);
77 return;
78 } 90 }
79 91
80 personalizarPromo(producto: Producto, index) { 92 personalizarPromo(producto: Producto, index) {
81 93
82 this.productoService.productoAcargar = producto; 94 this.productoService.productoAcargar = producto;
83 this.productoService.esPromoPersonalizada = true; 95 this.productoService.esPromoPersonalizada = true;
84 this.deleteProducto(producto, index); 96 this.deleteProducto(producto, index);
85 this.router.navigate(['inicio']); 97 this.router.navigate(['inicio']);
86 } 98 }
87 99
88 } 100 }