-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
367 lines (329 loc) · 15.7 KB
/
script.js
File metadata and controls
367 lines (329 loc) · 15.7 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
document.addEventListener('DOMContentLoaded', () => {
// Smooth scrolling for navigation links
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId.startsWith('#')) {
document.querySelector(targetId).scrollIntoView({
behavior: 'smooth'
});
} else {
// Handle non-hash links like admin login
window.location.href = targetId;
}
});
});
// Handle order modal
const orderModal = document.getElementById('order-modal');
const closeButton = orderModal.querySelector('.close-button');
const orderButtons = document.querySelectorAll('.order-btn');
const modalProductName = document.getElementById('modal-product-name');
const modalProductPrice = document.getElementById('modal-product-price');
const confirmOrderBtn = document.getElementById('confirm-order-btn');
const cancelOrderBtn = document.getElementById('cancel-order-btn');
const paymentOptionsContainer = document.getElementById('modal-step-2');
const paymentButtons = paymentOptionsContainer.querySelectorAll('.payment-btn');
const paymentProcessContainer = document.getElementById('modal-step-3');
const paymentInstruction = document.getElementById('payment-instruction');
const qrCodeDisplay = document.getElementById('qr-code-display');
const downloadQrBtn = document.getElementById('download-qr-btn');
const paymentStatusMessage = document.getElementById('payment-status-message');
const checkPaymentBtn = document.getElementById('check-payment-btn');
const failedPaymentBtn = document.getElementById('failed-payment-btn');
const finalStatusContainer = document.getElementById('modal-step-4');
const finalStatusTitle = document.getElementById('final-status-title');
const finalStatusMessage = document.getElementById('final-status-message');
const transferDetailsArea = document.getElementById('transfer-details-area');
const transferDetailsOutput = document.getElementById('transfer-details-output');
const printReceiptBtn = document.getElementById('print-receipt-btn');
const closeModalBtn = document.getElementById('close-modal-btn');
const loadingSpinner = orderModal.querySelector('.loading-spinner');
const backToStep1Btn = document.getElementById('back-to-step-1');
const backToStep2Btn = document.getElementById('back-to-step-2');
let currentProduct = null;
let paymentCheckInterval = null; // Interval for simulating payment status check
let currentPaymentMethod = null;
const showStep = (stepNumber) => {
document.querySelectorAll('[id^="modal-step-"]').forEach(step => {
step.style.display = 'none';
step.classList.remove('fade-in'); // Remove animation class for smooth transitions
});
document.getElementById(`modal-step-${stepNumber}`).style.display = 'block';
document.getElementById(`modal-step-${stepNumber}`).classList.add('fade-in'); // Add animation
// Hide spinner by default unless needed
loadingSpinner.classList.remove('active');
qrCodeDisplay.style.display = 'none';
downloadQrBtn.style.display = 'none';
paymentStatusMessage.textContent = '';
paymentStatusMessage.classList.remove('success', 'error');
// Clear any ongoing payment checks
clearInterval(paymentCheckInterval);
};
const resetModal = () => {
orderModal.classList.remove('active');
setTimeout(() => {
orderModal.style.display = 'none'; // Hide completely after animation
showStep(1); // Always go back to step 1
}, 300); // Wait for fade-out animation
};
orderButtons.forEach(button => {
button.addEventListener('click', function() {
currentProduct = {
id: this.dataset.productId,
name: this.dataset.productName,
price: this.dataset.productPrice
};
modalProductName.textContent = currentProduct.name;
modalProductPrice.textContent = currentProduct.price;
orderModal.style.display = 'flex'; // Display flex to center
setTimeout(() => orderModal.classList.add('active'), 10); // Trigger fade-in
showStep(1);
});
});
closeButton.addEventListener('click', resetModal);
closeModalBtn.addEventListener('click', resetModal);
window.addEventListener('click', (event) => {
if (event.target === orderModal) {
resetModal();
}
});
confirmOrderBtn.addEventListener('click', () => {
showStep(2);
});
cancelOrderBtn.addEventListener('click', () => {
alert('Pesanan dibatalkan.');
resetModal();
});
backToStep1Btn.addEventListener('click', () => showStep(1));
backToStep2Btn.addEventListener('click', () => showStep(2));
paymentButtons.forEach(button => {
button.addEventListener('click', function() {
currentPaymentMethod = this.dataset.payment;
showStep(3);
paymentInstruction.textContent = `Menyiapkan detail pembayaran untuk ${currentProduct.name} melalui ${currentPaymentMethod.toUpperCase()}...`;
loadingSpinner.classList.add('active'); // Show spinner for process effect
// Simulate API call to get QR/payment details
setTimeout(() => {
loadingSpinner.classList.remove('active');
let qrData = '';
let instText = '';
let transferDetailFormat = '';
switch (currentPaymentMethod) {
case 'dana':
qrData = `PAY:DANA_ANNASSHCOLLITE_${currentProduct.price.replace(/\D/g,'')}`;
instText = `Scan QR ini dengan aplikasi DANA atau transfer ke nomor DANA: +6281234567890 (Annasshcollite).`;
transferDetailFormat = `
Metode Pembayaran: DANA
Jumlah: ${currentProduct.price}
Nomor Tujuan: +6281234567890
Nama Penerima: Annasshcollite Official
Status: Menunggu Konfirmasi
Tanggal: ${new Date().toLocaleDateString()}
Waktu: ${new Date().toLocaleTimeString()}
`;
break;
case 'ovo':
qrData = `PAY:OVO_ANNASSHCOLLITE_${currentProduct.price.replace(/\D/g,'')}`;
instText = `Scan QR ini dengan aplikasi OVO atau transfer ke nomor OVO: +6289876543210 (Annasshcollite).`;
transferDetailFormat = `
Metode Pembayaran: OVO
Jumlah: ${currentProduct.price}
Nomor Tujuan: +6289876543210
Nama Penerima: Annasshcollite Official
Status: Menunggu Konfirmasi
Tanggal: ${new Date().toLocaleDateString()}
Waktu: ${new Date().toLocaleTimeString()}
`;
break;
case 'gopay':
qrData = `PAY:GOPAY_ANNASSHCOLLITE_${currentProduct.price.replace(/\D/g,'')}`;
instText = `Scan QR ini dengan aplikasi GoPay atau transfer ke nomor GoPay: +6287654321098 (Annasshcollite).`;
transferDetailFormat = `
Metode Pembayaran: GoPay
Jumlah: ${currentProduct.price}
Nomor Tujuan: +6287654321098
Nama Penerima: Annasshcollite Official
Status: Menunggu Konfirmasi
Tanggal: ${new Date().toLocaleDateString()}
Waktu: ${new Date().toLocaleTimeString()}
`;
break;
case 'qris':
qrData = `QRIS_PAYMENT_SIMULATION_ANNASSHCOLLITE_${currentProduct.price.replace(/\D/g,'')}_ORDER_${currentProduct.id}`;
instText = `Scan QRIS ini dengan aplikasi pembayaran (DANA, OVO, GoPay, LinkAja, dll.).`;
transferDetailFormat = `
Metode Pembayaran: QRIS (Universal)
Jumlah: ${currentProduct.price}
Merchant ID: ANNSCHOLITE_QRIS_MERCH
Status: Menunggu Konfirmasi
Tanggal: ${new Date().toLocaleDateString()}
Waktu: ${new Date().toLocaleTimeString()}
`;
break;
}
qrCodeDisplay.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrData)}`;
qrCodeDisplay.style.display = 'block';
downloadQrBtn.style.display = 'block';
paymentInstruction.textContent = instText;
paymentStatusMessage.textContent = "Menunggu pembayaran Anda...";
paymentStatusMessage.classList.add('status-message');
// Simulate payment check
startPaymentCheck(transferDetailFormat);
}, 1500); // Simulate network delay for QR generation
});
});
downloadQrBtn.addEventListener('click', () => {
const qrImage = qrCodeDisplay.src;
if (qrImage) {
const a = document.createElement('a');
a.href = qrImage;
a.download = `Annasshcollite_${currentPaymentMethod}_QR_Payment_${currentProduct.id}.png`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
alert('QR Code belum tersedia.');
}
});
const startPaymentCheck = (transferDetailFormat) => {
clearInterval(paymentCheckInterval); // Clear any existing interval
paymentCheckInterval = setInterval(() => {
console.log("Checking payment status...");
// In a real app, this would be an AJAX call to your backend to check payment gateway status
const isSuccess = Math.random() > 0.7; // 30% chance of success per check
if (isSuccess) {
clearInterval(paymentCheckInterval);
showPaymentSuccess(transferDetailFormat);
} else {
paymentStatusMessage.textContent = "Pembayaran belum terdeteksi. Silakan pastikan Anda sudah melakukan transfer.";
paymentStatusMessage.classList.remove('success', 'error');
}
}, 5000); // Check every 5 seconds
};
checkPaymentBtn.addEventListener('click', () => {
paymentStatusMessage.textContent = "Memeriksa status pembayaran secara manual...";
paymentStatusMessage.classList.remove('success', 'error');
// Simulate immediate check
setTimeout(() => {
const isSuccess = Math.random() > 0.5; // Higher chance on manual check
if (isSuccess) {
clearInterval(paymentCheckInterval);
// Placeholder transfer details, would be from backend in real app
const tempTransferDetails = `
Pembayaran Berhasil!
Produk: ${currentProduct.name}
Jumlah: ${currentProduct.price}
Metode: ${currentPaymentMethod.toUpperCase()}
Status: Lunas
ID Transaksi: TRX${Date.now()}
`;
showPaymentSuccess(tempTransferDetails);
} else {
paymentStatusMessage.textContent = "Pembayaran belum terdeteksi. Mohon cek kembali status transfer Anda.";
paymentStatusMessage.classList.add('error');
}
}, 1500);
});
failedPaymentBtn.addEventListener('click', () => {
clearInterval(paymentCheckInterval); // Stop automatic checks
showPaymentFailed();
});
const showPaymentSuccess = (transferDetailFormat) => {
showStep(4);
finalStatusTitle.textContent = "Pembayaran Berhasil!";
finalStatusMessage.textContent = "Terima kasih atas pesanan Anda. Produk akan segera diproses oleh admin.";
finalStatusTitle.style.color = '#28a745';
transferDetailsArea.style.display = 'block';
transferDetailsOutput.textContent = transferDetailFormat.replace('Menunggu Konfirmasi', 'BERHASIL');
paymentStatusMessage.classList.remove('error');
paymentStatusMessage.classList.add('success');
alert("Pembayaran Berhasil! Detail transfer tersedia.");
};
const showPaymentFailed = () => {
showStep(4);
finalStatusTitle.textContent = "Pembayaran Gagal!";
finalStatusMessage.textContent = "Terjadi kesalahan pada pembayaran atau pembayaran dibatalkan. Silakan coba lagi atau hubungi admin.";
finalStatusTitle.style.color = '#dc3545';
transferDetailsArea.style.display = 'none'; // Hide transfer details for failed payment
paymentStatusMessage.classList.remove('success');
paymentStatusMessage.classList.add('error');
};
printReceiptBtn.addEventListener('click', () => {
window.print();
});
// AI Bot floating action button
const aiBotFab = document.getElementById('ai-bot-fab');
aiBotFab.addEventListener('click', () => {
alert('Fitur AI Bot akan membawa Anda ke halaman chat dengan AI kami. (Ini adalah simulasi)');
// In a real app, you would redirect to a chat page:
// window.location.href = 'chat-with-ai.html';
});
// Admin Login Modal
const adminLoginLink = document.getElementById('admin-login-link');
const adminModal = document.getElementById('admin-modal');
const adminCloseButton = adminModal.querySelector('.close-button');
const adminLoginForm = document.getElementById('admin-login-form');
adminLoginLink.addEventListener('click', (e) => {
e.preventDefault();
adminModal.style.display = 'flex';
setTimeout(() => adminModal.classList.add('active'), 10);
});
adminCloseButton.addEventListener('click', () => {
adminModal.classList.remove('active');
setTimeout(() => adminModal.style.display = 'none', 300);
});
adminLoginForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = adminLoginForm.querySelector('input[type="text"]').value;
const password = adminLoginForm.querySelector('input[type="password"]').value;
if (username === "Annas" && password === "pw 1") {
alert('Login Admin Berhasil! (Simulasi)\nAnda sekarang memiliki akses ke panel admin.');
// In a real app, you would redirect to the admin dashboard:
// window.location.href = '/admin/dashboard.html';
adminModal.classList.remove('active');
setTimeout(() => adminModal.style.display = 'none', 300);
adminLoginForm.reset();
} else {
alert('Username atau Password salah!');
}
});
window.addEventListener('click', (event) => {
if (event.target === adminModal) {
adminModal.classList.remove('active');
setTimeout(() => adminModal.style.display = 'none', 300);
}
});
// Basic Contact Form submission (no backend)
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
alert('Pesan Anda telah terkirim! Kami akan segera menghubungi Anda.');
this.reset();
});
}
// Intersection Observer for scroll animations
const sections = document.querySelectorAll('section');
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
sections.forEach(section => {
section.classList.add('hidden-section'); // Add a class to initially hide
observer.observe(section);
});
// Initial load animations for specific elements
document.querySelector('.hero-content h2').classList.add('fade-in');
document.querySelector('.hero-content p').classList.add('fade-in');
document.querySelector('.hero-content .btn').classList.add('fade-in');
});