-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistrarPedido.html
172 lines (145 loc) · 6.46 KB
/
RegistrarPedido.html
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
<!DOCTYPE html>
<html lang="pt-pt">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registrar Pedido</title>
<link rel="stylesheet" href="stylesFormulario.css">
</head>
<body>
<section class="Background-IMG">
<a href="Home.html" class="botao-home"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" class="lucide lucide-house">
<path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8" />
<path
d="M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
</svg></a>
<a href="loginpage.html" class="LogOut"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"
fill="currentColor" class="bi bi-box-arrow-left" viewBox="0 0 16 16">
<path fill-rule="evenodd"
d="M6 12.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5h-8a.5.5 0 0 0-.5.5v2a.5.5 0 0 1-1 0v-2A1.5 1.5 0 0 1 6.5 2h8A1.5 1.5 0 0 1 16 3.5v9a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 5 12.5v-2a.5.5 0 0 1 1 0z" />
<path fill-rule="evenodd"
d="M.146 8.354a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L1.707 7.5H10.5a.5.5 0 0 1 0 1H1.707l2.147 2.146a.5.5 0 0 1-.708.708z" />
</svg></a>
<h1>Registrar Produto</h1>
</section>
<main>
<h2 class="subtitulo">Novo Pedido</h2>
<form class="formulario" id="formPedido">
<label for="cliente">Cliente</label>
<select id="cliente" name="cliente" required>
<option value="" disabled selected>Selecione um cliente</option>
</select>
<label for="produto">Produto</label>
<select id="produto" name="produto" required>
<option value="" disabled selected>Selecione um produto</option>
</select>
<label for="quantidade">Quantidade</label>
<input type="number" id="quantidade" name="quantidade" required placeholder="Digite a quantidade">
<button type="submit">Registrar Pedido</button>
</form>
</main>
<footer class="rodape">
<div class="container-rodape">
<!-- Coluna Esquerda -->
<div class="coluna-rodape">
<h3>Osande de Jesus</h3>
<ul class="links-esquerda">
<li><a href="#">Trabalhos</a></li>
<li><a href="#">Sobre Mim</a></li>
<li><a href="#">Serviços</a></li>
<li><a href="#">Contatos</a></li>
</ul>
</div>
<!-- Coluna Central -->
<div class="coluna-rodape central-rodape">
<h3>Contato</h3>
<p>hello@rddc.be</p>
<p>+244 999 999 999</p>
</div>
<div class="coluna-rodape central-rodape">
<h3>Estúdio</h3>
<p>Benguela</p>
</div>
<!-- Coluna Direita -->
<div class="coluna-rodape direita-rodape">
<h3>Redes Sociais</h3>
<ul class="links-sociais">
<li><a href="#">LinkedIn</a></li>
<li><a href="#">Behance</a></li>
<li><a href="#">Pinterest</a></li>
<li><a href="#">Instagram</a></li>
</ul>
</div>
</div>
<p id="slogan">Faça sua marca<sup>®</sup> a escolha óbvia</p>
</footer>
<script>
document.addEventListener("DOMContentLoaded", () => {
carregarClientes();
carregarProdutos();
});
async function carregarClientes() {
console.log("Carregando clientes...");
try {
const response = await fetch("http://localhost:3000/clientes");
if (!response.ok) throw new Error(`Erro HTTP: ${response.status}`);
const clientes = await response.json();
console.log("Clientes carregados:", clientes);
const select = document.getElementById("cliente");
select.innerHTML = '<option value="" disabled selected>Selecione um cliente</option>';
clientes.forEach(cliente => {
const option = document.createElement("option");
option.value = cliente.nome;
option.textContent = `${cliente.nome} - ${cliente.telefone}`;
select.appendChild(option);
});
} catch (error) {
console.error("Erro ao carregar clientes:", error);
}
}
async function carregarProdutos() {
console.log("Carregando produtos...");
try {
const response = await fetch("http://localhost:3000/produtos");
if (!response.ok) throw new Error(`Erro HTTP: ${response.status}`);
const produtos = await response.json();
console.log("Produtos carregados:", produtos);
const select = document.getElementById("produto");
select.innerHTML = '<option value="" disabled selected>Selecione um produto</option>';
produtos.forEach(produto => {
const option = document.createElement("option");
option.value = produto.nome;
option.textContent = `${produto.nome} - R$${produto.preco.toFixed(2)}`;
select.appendChild(option);
});
} catch (error) {
console.error("Erro ao carregar produtos:", error);
}
}
document.getElementById("formPedido").addEventListener("submit", async (event) => {
event.preventDefault();
const pedido = {
cliente: document.getElementById("cliente").value,
produto: document.getElementById("produto").value,
quantidade: parseInt(document.getElementById("quantidade").value)
};
console.log("Enviando pedido:", pedido);
try {
const response = await fetch("http://localhost:3000/pedidos", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(pedido)
});
if (!response.ok) throw new Error(`Erro HTTP: ${response.status}`);
alert("Pedido registrado com sucesso!");
document.getElementById("formPedido").reset();
} catch (error) {
console.error("Erro ao registrar pedido:", error);
alert("Erro ao registrar pedido. Tente novamente.");
}
});
</script>
</body>
</html>