forked from GRANCodigo/PraticaDeProgramacao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnidade4Aula1c
240 lines (223 loc) · 9.92 KB
/
Unidade4Aula1c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
-------------------- index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="carrinho.css">
<script src="carrinho.js"></script>
<title>Carrinho de Compras</title>
</head>
<body>
<div class="container bg-white rounded-top mt-5" id="zero-pad">
<div class="row d-flex justify-content-center">
<div class="col-lg-10 col-12 pt-3">
<div class="d-flex">
<div><img src="https://loja.grancursosonline.com.br/wp-content/themes/base-framework/assets/logo-loja-gran-no-background.png" width="200" height="100"></div>
<div class="ml-auto p-2"><a href="#" class="text-dark text-decoration-none" id="mobile-font">ENTRAR</a></div>
<div class="p-2"><a href="#" class="text-dark text-decoration-none a" id="mobile-font">AJUDA</a></div>
</div>
<div class="d-flex flex-column pt-4">
<div><h5 class="text-uppercase font-weight-normal">Lojinha da GranCursos</h5></div>
<div class="font-weight-normal">3 itens</div>
</div>
<div class="d-flex flex-row px-lg-5 mx-lg-5 mobile" id="heading">
<div class="px-lg-5 mr-lg-5" id="produc">PRODUTOS</div>
<div class="px-lg-5 ml-lg-5" id="prc">PREÇO</div>
<div class="px-lg-5 ml-lg-1" id="quantity">QUANTIDADE</div>
<div class="px-lg-5 ml-lg-3" id="total">TOTAL</div>
</div>
<div id="produto0" class="d-flex flex-row justify-content-between align-items-center pt-lg-4 pt-2 pb-3 border-bottom mobile">
<div class="d-flex flex-row align-items-center">
<div><img src="https://grancursos-blog-loja-prd.s3.amazonaws.com/wp-content/uploads/2022/10/01150955/900x900_9.jpg" width="150" height="150" alt="" id="image"></div>
<div class="d-flex flex-column pl-md-3 pl-1">
<div><h6>Caneca Eu dou Conta</h6></div>
<div>Código:<span class="pl-2">091091001</span></div>
<div>Cor:<span class="pl-3">Branco</span></div>
</div>
</div>
<div class="pl-md-0 pl-1"><b>R$45,00</b></div>
<div class="pl-md-0 pl-2">
<span class="fa fa-minus-square text-secondary" onclick="removerItem(0)"></span>
<span class="px-md-3 px-1" id="quantidade0">0</span>
<span class="fa fa-plus-square text-secondary" onclick="adicionarItem(0)"></span>
</div>
<div class="pl-md-0 pl-1">
<b><span id="total0">R$</span></b>
</div>
<div class="close">×</div>
</div>
<div id="produto1" class="d-flex flex-row justify-content-between align-items-center pt-4 pb-3 mobile">
<div class="d-flex flex-row align-items-center">
<div><img src="https://grancursos-blog-loja-prd.s3.amazonaws.com/wp-content/uploads/2022/10/01151137/900x900_11.jpg" width="150" height="150" alt="" id="image"></div>
<div class="d-flex flex-column pl-md-3 pl-1">
<div><h6>Moleskine</h6></div>
<div>Código:<span class="pl-2">056289891</span></div>
<div>Cor:<span class="pl-3">Vermelho</span></div>
</div>
</div>
<div class="pl-md-0 pl-1"><b>R$39,90</b></div>
<div class="pl-md-0 pl-2">
<span class="fa fa-minus-square text-secondary" onclick="removerItem(1)"></span>
<span class="px-md-3 px-1" id="quantidade1">0</span>
<span class="fa fa-plus-square text-secondary" onclick="adicionarItem(1)"></span>
</div>
<div class="pl-md-0 pl-1">
<b><span id="total1">R$</span></b>
</div>
<div class="close">×</div>
</div>
<div id="produto2" class="d-flex flex-row justify-content-between align-items-center pt-lg-4 pt-2 pb-3 border-bottom mobile">
<div class="d-flex flex-row align-items-center">
<div><img src="https://grancursos-blog-loja-prd.s3.amazonaws.com/wp-content/uploads/2022/10/01151653/900x900_19.jpg" width="150" height="150" alt="" id="image"></div>
<div class="d-flex flex-column pl-md-3 pl-1">
<div><h6>Caneca Mágica</h6></div>
<div>Código:<span class="pl-2">091091001</span></div>
<div>Cor:<span class="pl-3">Bege</span></div>
</div>
</div>
<div class="pl-md-0 pl-1"><b>R$49,90</b></div>
<div class="pl-md-0 pl-2">
<span class="fa fa-minus-square text-secondary" onclick="removerItem(2)"></span>
<span class="px-md-3 px-1" id="quantidade2">0</span>
<span class="fa fa-plus-square text-secondary" onclick="adicionarItem(2)"></span>
</div>
<div class="pl-md-0 pl-1">
<b><span id="total2">R$</span></b>
</div>
<div class="close">×</div>
</div>
</div>
</div>
</div>
<div class="container bg-light rounded-bottom py-4" id="zero-pad">
<div class="row d-flex justify-content-center">
<div class="col-lg-10 col-12">
<div class="d-flex justify-content-between align-items-center">
<div>
<button class="btn btn-sm bg-light border border-dark">VOLTAR</button>
</div>
<div class="px-md-0 px-1" id="footer-font">
<b class="pl-md-4">SUBTOTAL R$<span class="pl-md-4" id="valorTotalCompra"></span></b>
</div>
<div>
<button class="btn btn-sm bg-dark text-white px-lg-5 px-3">CONTINUAR</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
------------------------------- carrinho.css
body{
background-color: #eeeeee;
}
.footer-background{
background-color: rgb(204, 199, 199);
}
@media(max-width:991px){
#heading{
padding-left: 50px;
}
#prc{
margin-left: 70px;
padding-left: 110px;
}
#quantity{
padding-left: 48px;
}
#produc{
padding-left: 40px;
}
#total{
padding-left: 54px;
}
}
@media(max-width:767px){
.mobile{
font-size: 10px;
}
h5{
font-size: 14px;
}
h6{
font-size: 9px;
}
#mobile-font{
font-size: 11px;
}
#prc{
font-weight: 700;
margin-left: -45px;
padding-left: 105px;
}
#quantity{
font-weight: 700;
padding-left: 6px;
}
#produc{
font-weight: 700;
padding-left: 0px;
}
#total{
font-weight: 700;
padding-left: 9px;
}
#image{
width: 60px;
height: 60px;
}
.col{
width: 100%;
}
#zero-pad{
padding: 2%;
margin-left: 10px;
}
#footer-font{
font-size: 12px;
}
#heading{
padding-top: 15px;
}
}
----------------------------- carrinho.js
var qtd = [0,0,0]; //quantidade de cada produto
var valorProduto = [45.00,39.90, 49.90]; //valor unitário de cada produto
var valorTotal = [0,0,0]; //valor total de cada produto
function adicionarItem(item){
var quantidade = document.getElementById('quantidade' + item);
qtd[item] = qtd[item] + 1; //cálculo que adiciona +1 na quantidade
quantidade.innerHTML = qtd[item]; //exibe o valor da quantidade na tela
var total = document.getElementById("total" + item);
valorTotal[item] = Number.parseFloat(valorProduto[item]) * qtd[item];
//multiplica o valor unitário pela quantidade
total.innerHTML = valorTotal[item].toFixed(2); //exibe o valor total do produto na tela
valorCompra();
}
function removerItem(item){
if(qtd[item] > 0){
var quantidade = document.getElementById('quantidade' + item);
qtd[item] = qtd[item] - 1; //cálculo que remove -1 na quantidade
quantidade.innerHTML = qtd[item]; //exibe o valor da quantidade na tela
var total = document.getElementById("total" + item);
valorTotal[item] = Number.parseFloat(valorProduto[item]) * qtd[item];
//multiplica o valor unitário pela quantidade
total.innerHTML = valorTotal[item].toFixed(2);//exibe o valor total do produto na tela
valorCompra();
}
}
function valorCompra(){
var valorTotalCompra = document.getElementById('valorTotalCompra');
var valor = 0;
for(var i=0; i<valorTotal.length;i++){
valor+=valorTotal[i];
}
valorTotalCompra.innerHTML = valor.toFixed(2);
}