-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetalhes.js
92 lines (55 loc) · 2.32 KB
/
detalhes.js
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
//FUNÇÃO PRONTA PARA PEGAR OS PARAMETROS
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function getId(){
url = window.location.href;
console.log("url",url)
console.log("url",url.indexOf("="))
console.log("url",url.length)
id = url.substring(url.indexOf("="),url.length)
}
async function carregaProduto(id){
fetch("https://diwserver.vps.webdock.cloud/products/"+id)
.then(res => res.json())
.then(data => {
let str = ''
let catalogo = data
let star = retornaEstrelas(catalogo.rating.rate)
str = `<div class="product-div">
<div>
<img src="${catalogo.image}" class="imagem" alt="...">
</div>
<div class="infos">
<h5 class="card-title">${catalogo.title}</h5>
<p class="card-text">${catalogo.description}</p>
${star}
<a href="#" id="precoMaisVistos" class="btn btn-outline-primary price-detail">${catalogo.price.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })}</a>
</div>
</div>`
document.getElementById('catalogo').innerHTML = str
})
}
function retornaEstrelas(number){
let num_int = parseInt(number)
let ret = "<div>"
for (var i = 0; i < num_int; i++) {
ret += `<i class="bi bi-star-fill" style="font-size: 1rem; color:rgb(220, 190, 84);"></i> `
}
if(number>num_int){
i++;
ret += `<i class="bi bi-star-half" style="font-size: 1rem; color:rgb(220, 190, 84);"></i> `
}
for (var j = 1; j < 5-num_int; j++) {
ret += `<i class="bi bi-star" style="font-size: 1rem; color:rgb(220, 190, 84);"></i> `
}
return ret+"</div>";
}
var id = getParameterByName('id');
carregaProduto(id)