phanquocdat123 commited on
Commit
357004a
·
verified ·
1 Parent(s): f8ceb1c

Create order-form.html

Browse files
Files changed (1) hide show
  1. public/order-form.html +116 -0
public/order-form.html ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Thông tin đơn hàng Hương Kid</title>
7
+ <style>
8
+ body { font-family: sans-serif; padding: 20px; background: #f4f4f4; margin: 0; }
9
+ .container { max-width: 600px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
10
+ .form-group { margin-bottom: 15px; }
11
+ label { display: block; margin-bottom: 5px; font-weight: bold; color: #333; }
12
+ input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; font-size: 15px; }
13
+ button { width: 100%; padding: 14px; background: #ff4757; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; font-size: 16px; transition: 0.2s; }
14
+ button:disabled { background: #ccc; cursor: not-allowed; }
15
+
16
+ /* Giao diện màn hình thành công */
17
+ .success-screen { text-align: center; padding: 40px 10px; animation: fadeIn 0.5s ease; }
18
+ .success-icon { font-size: 60px; margin-bottom: 15px; }
19
+ .success-title { color: #2ed573; margin-bottom: 10px; font-size: 22px; }
20
+ .success-desc { color: #57606f; font-size: 15px; line-height: 1.6; }
21
+ .instruction-box { background: #fff5f5; padding: 15px; border-radius: 8px; margin: 25px 0; border: 1px dashed #ff4757; }
22
+ .instruction-text { color: #ff4757; font-weight: bold; margin: 0; font-size: 15px; }
23
+
24
+ @keyframes fadeIn {
25
+ from { opacity: 0; transform: translateY(10px); }
26
+ to { opacity: 1; transform: translateY(0); }
27
+ }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <div class="container" id="form-container">
32
+ <h3>🛍️ Xác nhận đơn hàng</h3>
33
+ <div class="form-group">
34
+ <label>Tên của Mẹ/Bé:</label>
35
+ <input type="text" id="name" placeholder="Ví dụ: Mẹ Bé Bo">
36
+ </div>
37
+ <div class="form-group">
38
+ <label>Số điện thoại:</label>
39
+ <input type="tel" id="phone" placeholder="Bắt buộc 10 số">
40
+ </div>
41
+ <div class="form-group">
42
+ <label>Địa chỉ nhận hàng:</label>
43
+ <input type="text" id="address" placeholder="Số nhà, tên đường, tỉnh thành...">
44
+ </div>
45
+ <button onclick="submitForm()">XÁC NHẬN GỬI</button>
46
+ </div>
47
+
48
+ <script>
49
+ // 1. HÀM XỬ LÝ GỬI ĐƠN HÀNG
50
+ async function submitForm() {
51
+ const name = document.getElementById('name').value.trim();
52
+ const phone = document.getElementById('phone').value.trim();
53
+ const address = document.getElementById('address').value.trim();
54
+
55
+ if (!name || !phone || !address) {
56
+ alert("Mẹ vui lòng điền đầy đủ Tên, SĐT và Địa chỉ để em lên đơn nhen! ❤️");
57
+ return;
58
+ }
59
+
60
+ const urlParams = new URLSearchParams(window.location.search);
61
+ const userId = urlParams.get('userId');
62
+
63
+ if (!userId) {
64
+ alert("Không tìm thấy mã người dùng. Mẹ vui lòng mở lại link từ Messenger nhé!");
65
+ return;
66
+ }
67
+
68
+ const btn = document.querySelector('button');
69
+ btn.innerText = "⏳ ĐANG GỬI ĐƠN...";
70
+ btn.disabled = true;
71
+
72
+ try {
73
+ // 2. GỬI DỮ LIỆU VỀ SERVER NODE.JS
74
+ const response = await fetch('/api/submit-order', {
75
+ method: 'POST',
76
+ headers: {
77
+ 'Content-Type': 'application/json'
78
+ },
79
+ body: JSON.stringify({ userId, name, phone, address })
80
+ });
81
+
82
+ const result = await response.json();
83
+
84
+ if (result.success) {
85
+ // 3. THAY ĐỔI TOÀN BỘ GIAO DIỆN THÀNH MÀN HÌNH BÁO THÀNH CÔNG ĐẸP MẮT
86
+ document.getElementById('form-container').innerHTML = `
87
+ <div class="success-screen">
88
+ <div class="success-icon">🎉</div>
89
+ <h2 class="success-title">GỬI THÔNG TIN THÀNH CÔNG!</h2>
90
+ <p class="success-desc">
91
+ Hệ thống <strong>Hương Kid</strong> đã ghi nhận thông tin của Mẹ thành công ạ.
92
+ </p>
93
+ <div class="instruction-box">
94
+ <p class="instruction-text">
95
+ 👇 Mẹ vui lòng bấm nút [ X ] hoặc chữ [ ĐÓNG ] ở góc trên màn hình để quay lại ô chat nhận hóa đơn nhen!
96
+ </p>
97
+ </div>
98
+ <p style="color: #a4b0be; font-size: 13px; margin: 0;">C���m ơn Mẹ nhiều nhiều ❤️</p>
99
+ </div>
100
+ `;
101
+ } else {
102
+ alert("⚠️ Có lỗi xảy ra: " + result.message);
103
+ btn.innerText = "XÁC NHẬN GỬI";
104
+ btn.disabled = false;
105
+ }
106
+
107
+ } catch (error) {
108
+ console.error("Lỗi kết nối:", error);
109
+ alert("❌ Lỗi kết nối mạng hoặc server bận, Mẹ thử lại giúp em nhen!");
110
+ btn.innerText = "XÁC NHẬN GỬI";
111
+ btn.disabled = false;
112
+ }
113
+ }
114
+ </script>
115
+ </body>
116
+ </html>