DMC chuyên nghiệp tại Nha Trang — tour, vé xe, eSIM chất lượng cao.
📍 34 Bùi Phùng, Nam Nha Trang, Khánh Hòa
📞 +84 789 900 099 (Zalo·WA·Viber)
✉️ ad@go365.vn
© 2025 Go365.vn — Go Everywhere
🔒 SSL✅ DKKD⭐ 4.87🌐 VI·EN·中
const API = window.location.hostname === 'localhost' ? 'http://localhost:5001/api/v1' : '/api/v1';
async function loadEsimProducts() {
try {
// Load eSIM products
const res = await fetch(`${API}/Products?page=1&pageSize=20`);
const data = await res.json();
if (!data.success || !data.data) {
console.error('No products found');
showEmptyState();
return;
}
const products = data.data;
// Helper to format price with dots
function formatPrice(price) {
return price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
}
// Get the grid container (g4c class)
const gridContainer = document.querySelector('.g4c');
if (!gridContainer) {
console.error('Grid container not found');
return;
}
// Clear existing static cards
gridContainer.innerHTML = '';
// If no products, show empty state
if (products.length === 0) {
showEmptyState();
return;
}
// Create cards for each product
products.forEach(product => {
const card = document.createElement('div');
card.className = 'card';
card.style.cssText = 'padding:16px;display:flex;align-items:center;gap:12px;cursor:pointer';
card.onmouseover = function() { this.style.borderColor = 'var(--t3)'; };
card.onmouseout = function() { this.style.borderColor = 'var(--g2)'; };
// Create link
const link = document.createElement('a');
link.href = `03-tour-detail.html?id=${product.id}`;
link.style.cssText = 'display:flex;align-items:center;gap:12px;width:100%;text-decoration:none;color:inherit';
// Get first image or use emoji fallback
const imageEmoji = product.images && product.images.length > 0 ? '🌍' : '🌏';
link.innerHTML = `
${imageEmoji}
${product.nameVI || product.nameEN || 'Product'}
${product.descriptionVI ? product.descriptionVI.substring(0, 40) + '...' : ''}
Từ
${formatPrice(product.basePrice)}đ
`;
card.appendChild(link);
gridContainer.appendChild(card);
});
} catch (error) {
console.error('Error loading eSIM products:', error);
showEmptyState();
}
}
function showEmptyState() {
const gridContainer = document.querySelector('.g4c');
if (gridContainer) {
gridContainer.innerHTML = `
📭
Không có sản phẩm nào
Vui lòng thử lại sau
`;
}
}
// Load on page load
document.addEventListener('DOMContentLoaded', loadEsimProducts);