53 lines
3.4 KiB
JavaScript
53 lines
3.4 KiB
JavaScript
const NOTEBOOKS = [
|
||
{ id: 1, name: "Dell XPS 13", tag: "Уч", price: 449000, specs: ["Intel i7-1360P", "16GB", "512GB SSD", "13.4\u2033 3.8K OLED"], cat: "office" },
|
||
{ id: 2, name: "HP Pavilion 15", tag: "Уч", price: 289000, specs: ["AMD Ryzen 5 7530U", "16GB", "512GB SSD", "15.6\u2033 FHD IPS"], cat: "office" },
|
||
{ id: 3, name: "Lenovo IdeaPad 3", tag: "Дом", price: 199000, specs: ["Intel i5-1235U", "8GB", "256GB SSD", "15.6\u2033 FHD"], cat: "home" },
|
||
{ id: 4, name: "Asus VivoBook 15", tag: "Дом", price: 239000, specs: ["Intel i5-1335U", "16GB", "512GB SSD", "15.6\u2033 FHD IPS"], cat: "home" },
|
||
{ id: 5, name: "MacBook Air M2", tag: "Про", price: 649000, specs: ["Apple M2 8/10 cores", "16GB", "512GB SSD", "13.6\u2033 Liquid Retina"], cat: "pro" },
|
||
{ id: 6, name: "MacBook Pro 14 M3", tag: "Иг", price: 899000, specs: ["Apple M3 Pro", "18GB", "1TB SSD", "14.2\u2033 120Hz"], cat: "pro" },
|
||
{ id: 7, name: "Acer Nitro 5", tag: "Иг", price: 549000, specs: ["Intel i7-13700H", "16GB", "1TB SSD", "RTX 4060 8GB", "15.6\u2033 165Hz"], cat: "game" },
|
||
{ id: 8, name: "Lenovo Legion 5", tag: "Иг", price: 649000, specs: ["AMD R7 7735H", "16GB", "1TB SSD", "RTX 4060 8GB", "15.6\u2033 165Hz"], cat: "game" },
|
||
{ id: 9, name: "MSI Prestige 14", tag: "Про", price: 599000, specs: ["Intel i7-1360P", "32GB", "1TB SSD", "14\u2033 2.8K OLED"], cat: "pro" },
|
||
];
|
||
const CATS = [
|
||
{ key: "all", label: "Все" },
|
||
{ key: "home", label: "Для дома" },
|
||
{ key: "office", label: "Для учёбы/офиса" },
|
||
{ key: "pro", label: "Для работы" },
|
||
{ key: "game", label: "Игровые" },
|
||
];
|
||
const FILTER_LABELS = { home: "Для дома", office: "Для учёбы/офиса", pro: "Для работы", game: "Игровой" };
|
||
function fmtPrice(n) { return n.toLocaleString("ru-RU") + " ₸"; }
|
||
function waLink(text) { return "https://wa.me/77001234567?text=" + encodeURIComponent(text); }
|
||
|
||
function renderFilters() {
|
||
const box = document.getElementById("nb-filters");
|
||
box.innerHTML = CATS.map((c, i) => '<button class="kt-ai-btn" data-size="sm" data-cat="' + c.key + '"' + (i === 0 ? ' data-active="true"' : "") + ">" + c.label + "</button>").join("");
|
||
}
|
||
function renderProducts(cat) {
|
||
const list = cat === "all" ? NOTEBOOKS : NOTEBOOKS.filter(p => p.cat === cat);
|
||
const grid = document.getElementById("nb-grid");
|
||
grid.innerHTML = list.map(p => `
|
||
<article class="kt-ai-card nb-card">
|
||
<span class="kt-ai-chip nb-card-badge">${p.tag}</span>
|
||
<h3 class="nb-card-name">${p.name}</h3>
|
||
<div class="nb-card-specs">${p.specs.map(s => '<span class="kt-ai-chip nb-card-spec">' + s + "</span>").join("")}</div>
|
||
<div class="nb-card-foot">
|
||
<p class="nb-card-price">${fmtPrice(p.price)}</p>
|
||
<a class="kt-ai-btn" data-variant="primary" href="${waLink("Здравствуйте! Хочу заказать: " + p.name + " за " + fmtPrice(p.price))}" target="_blank" rel="noopener">Заказать</a>
|
||
</div>
|
||
</article>`).join("");
|
||
}
|
||
function init() {
|
||
renderFilters();
|
||
renderProducts("all");
|
||
document.getElementById("nb-filters").addEventListener("click", (e) => {
|
||
const btn = e.target.closest("button[data-cat]");
|
||
if (!btn) return;
|
||
document.querySelectorAll("#nb-filters button[data-cat]").forEach(b => b.removeAttribute("data-active"));
|
||
btn.setAttribute("data-active", "true");
|
||
renderProducts(btn.getAttribute("data-cat"));
|
||
});
|
||
}
|
||
document.addEventListener("DOMContentLoaded", init);
|