Commit fd918561c57de9d1cb3c90fb57fe32c5bf6bdc2d

Authored by =
1 parent 4384b790cf
Exists in master and in 1 other branch validar_pve

Funcion incrementar 2

Showing 1 changed file with 2 additions and 5 deletions   Show diff stats
src/app/sidebar/sidebar.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { timingSafeEqual } from 'crypto'; 2 import { timingSafeEqual } from 'crypto';
3 3
4 @Component({ 4 @Component({
5 selector: 'app-sidebar', 5 selector: 'app-sidebar',
6 templateUrl: './sidebar.component.html', 6 templateUrl: './sidebar.component.html',
7 styleUrls: ['./sidebar.component.scss'] 7 styleUrls: ['./sidebar.component.scss']
8 }) 8 })
9 export class SidebarComponent implements OnInit { 9 export class SidebarComponent implements OnInit {
10 10
11 private cont: number = 1; 11 private cont: number = 1;
12 private min: number = 1; 12 private min: number = 1;
13 private max: number = 50; 13 private max: number = 50;
14 private total: number = 0; 14 private total: number = 0;
15 15
16 private productos = [ 16 private productos = [
17 { 17 {
18 "id": 1, 18 "id": 1,
19 "desc": "Galletas Oreo", 19 "desc": "Galletas Oreo",
20 "cod": 225412, 20 "cod": 225412,
21 "precio": 15, 21 "precio": 15,
22 "img": "./assets/descarga.jpg", 22 "img": "./assets/descarga.jpg",
23 "cantidad": 1 23 "cantidad": 1
24 }, 24 },
25 { 25 {
26 "id": 2, 26 "id": 2,
27 "desc": "Coca cola 500ml", 27 "desc": "Coca cola 500ml",
28 "cod": 512632, 28 "cod": 512632,
29 "precio": 40, 29 "precio": 40,
30 "img": "./assets/descarga.jpg", 30 "img": "./assets/descarga.jpg",
31 "cantidad": 1 31 "cantidad": 1
32 }, 32 },
33 { 33 {
34 "id": 3, 34 "id": 3,
35 "desc": "Pancho grande", 35 "desc": "Pancho grande",
36 "cod": 775987, 36 "cod": 775987,
37 "precio": 45, 37 "precio": 45,
38 "img": "./assets/descarga.jpg", 38 "img": "./assets/descarga.jpg",
39 "cantidad": 1 39 "cantidad": 1
40 } 40 }
41 ]; 41 ];
42 42
43 constructor() { } 43 constructor() { }
44 44
45 ngOnInit() { 45 ngOnInit() {
46 this.getProductosCarrito(); 46 this.getProductosCarrito();
47 this.getCantidadProductos(); 47 this.getCantidadProductos();
48 this.getTotal(); 48 this.getTotal();
49 } 49 }
50 50
51 getCantidadProductos(){ 51 getCantidadProductos(){
52 var aux = 0; 52 var aux = 0;
53 for (let i = 0; i < this.productos.length; i++) { 53 for (let i = 0; i < this.productos.length; i++) {
54 ++aux; 54 ++aux;
55 } 55 }
56 return this.cont = aux; 56 return this.cont = aux;
57 57
58 } 58 }
59 59
60 getProductosCarrito() { 60 getProductosCarrito() {
61 return this.productos; 61 return this.productos;
62 } 62 }
63 63
64 getTotal(){ 64 getTotal(){
65 var subTotal; 65 var subTotal;
66 for (const pr of this.productos) { 66 for (let i = 0; i < this.productos.length; i++) {
67 subTotal = pr.cantidad * pr.precio; 67 this.productos[i].cantidad;
68 } 68 }
69 this.total = this.total + subTotal;
70 this.total = this.total * this.cont;
71 return this.total;
72 } 69 }
73 70
74 public aumentarContador(index) { 71 public aumentarContador(index) {
75 ++this.cont; 72 ++this.cont;
76 for (let i = 0; i < this.productos.length; i++) { 73 for (let i = 0; i < this.productos.length; i++) {
77 if (i === index) { 74 if (i === index) {
78 return (this.productos[i].cantidad === this.max) ? 75 return (this.productos[i].cantidad === this.max) ?
79 this.productos[i].cantidad : ++this.productos[i].cantidad; 76 this.productos[i].cantidad : ++this.productos[i].cantidad;
80 77
81 } 78 }
82 } 79 }
83 } 80 }
84 81
85 decrementarContador(index) { 82 decrementarContador(index) {
86 --this.cont; 83 --this.cont;
87 for (let i = 0; i < this.productos.length; i++) { 84 for (let i = 0; i < this.productos.length; i++) {
88 if (i === index) { 85 if (i === index) {
89 return (this.productos[i].cantidad === this.min) ? 86 return (this.productos[i].cantidad === this.min) ?
90 this.productos[i].cantidad : --this.productos[i].cantidad; 87 this.productos[i].cantidad : --this.productos[i].cantidad;
91 } 88 }
92 } 89 }
93 } 90 }
94 91
95 deleteProducto(index) { 92 deleteProducto(index) {
96 --this.cont; 93 --this.cont;
97 for (let i = 0; i < this.productos.length; i++) 94 for (let i = 0; i < this.productos.length; i++)
98 if (i === index) { 95 if (i === index) {
99 this.productos.splice(i, 1); 96 this.productos.splice(i, 1);
100 return this.productos; 97 return this.productos;
101 } 98 }
102 99
103 } 100 }
104 } 101 }
105 102