Spaces:
Running

f3squadshop-com / index.html
F3squad18's picture
Viết code tạo một web, Tôi là Admin, tôi là Admin, Admin có thể chỉnh sửa shop, tôi có một tài khoảng Admin tên là F3squad mật khẩu là tuongbienTuongbien14082012 mã đặc quyền là 14082012, thêm các món đồ mà tôi muốn bán, xoá các món đồ mà thôi muốn, chỉnh sửa các món dồ mà tôi muốn, shop có link là F3squadshop.com.vn, shop có tên là F3squadshop; Khi đăng nhập xong thì vào được trang chủ shop thì màng hình của admin có phần quản trị viên trong đó có các phần bao gồm, thêm món đồ ( khi bấm vào phần thêm món đồ thì hiện ra một cái bản trong cái bản đó có phần mã sản phẩm, có phần tên sản phẩm, có phần giá mua - giá bán - số lượng), trong đó có phần lưu sản phẩm( khi bấm lưu sản phẩm thì sản phẩm được lưu và hiện ra phần trang chủ sản phẩm ); khi khách hàng đặc mua sản phẩm thì sẽ thông báo đến phần đang chờ sử lý ( Adim có thể quyết định duyệt hay không duyệt đơn của khách hàng ) ; đơn vị tiền tệ của shop là Việt Nam đồng; khi admin duyệt đơn thì có thể viết ghi chú vào đơn và gửi cho khách hàng ghi chú đó, khi Admin gửi ghi chú cho khách hàng thì ghi chú sẽ hiện ra trong phần đơn hàng của khách hàng; khi tôi lưu món đồ mà tôi muốn bán thì cho dù tôi có thoát ra rồi vào lại shop thì các món đồ ấy cũng không mất, trong phần thêm sản phẩm thì phần thêm hình ảnh của sản phẩn thì Admin thì sẽ dán hình ảnh mà Admin đã sao chép trước đó, khi mới bào shop thì sẽ có ba khung; khung bên trái là khung đăng nhập của Admin khung đăng nhập của Admin thì có 3 khung nhỏ khung 1 là tên tài khoảng khung 2 là khung mật khẩu khung 3 là khung mã đặc quyền ( chỉ có đăng nhập Admin mới có mã đặc quyền) ; khung chính giữa là khung đăng nhập của khách hàng, khung đăng nhập của khách hàng có 2 khung, khung 1 khung điền tên, khung 2 là khung điền mật khẩu; khung bên phải là khung đăng kí của khách hàng; có 3 khung, khung 1 là khung nhập tên, khung 2 là khung nhập mật khẩu, khung 3 là khung xác nhận mật khẩu. Khi đăng nhập của khách hàng thì sẽ thấy phần sản phẩm mà Admin đã thêm vào shop, khi bấm vào sản phẩm thì sẽ thấy phầm mua sản phẩm,, khi mua sản phẩm thì sẽ gửi tới Admin nếu Admin duyệt thì đơn sẽ được thanh toán, nếu Admin không chấp nhận thì đơn sẽ từ chối, - Initial Deployment
fd4df77 verified
Raw History Blame Contribute Delete
57.2 kB
<!DOCTYPE html> <html lang="vi"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>F3squadshop - Admin Panel</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> .fade-in { animation: fadeIn 0.3s ease-in-out; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .slide-in { animation: slideIn 0.3s ease-out; } @keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } .custom-scrollbar::-webkit-scrollbar { width: 6px; } .custom-scrollbar::-webkit-scrollbar-track { background: #f1f1f1; } .custom-scrollbar::-webkit-scrollbar-thumb { background: #888; border-radius: 3px; } .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #555; } </style> </head> <body class="bg-gray-100 font-sans"> <!-- Main Container --> <div id="app" class="min-h-screen"> <!-- Login Page --> <div id="login-page" class="flex flex-col md:flex-row min-h-screen"> <!-- Admin Login (Left) --> <div class="w-full md:w-1/3 bg-blue-600 text-white p-8 flex flex-col justify-center"> <div class="max-w-md mx-auto w-full"> <h2 class="text-2xl font-bold mb-6 text-center">Đăng nhập Admin</h2> <div class="space-y-4"> <div> <label class="block mb-2">Tên tài khoản</label> <input type="text" id="admin-username" class="w-full p-3 rounded text-gray-800" placeholder="Nhập tên admin"> </div> <div> <label class="block mb-2">Mật khẩu</label> <input type="password" id="admin-password" class="w-full p-3 rounded text-gray-800" placeholder="Nhập mật khẩu"> </div> <div> <label class="block mb-2">Mã đặc quyền</label> <input type="password" id="admin-privilege" class="w-full p-3 rounded text-gray-800" placeholder="Nhập mã đặc quyền"> </div> <button onclick="adminLogin()" class="w-full bg-blue-800 hover:bg-blue-900 text-white py-3 px-4 rounded font-bold transition duration-200"> Đăng nhập </button> </div> </div> </div> <!-- Customer Login (Middle) --> <div class="w-full md:w-1/3 bg-white p-8 flex flex-col justify-center border-l border-r border-gray-200"> <div class="max-w-md mx-auto w-full"> <h2 class="text-2xl font-bold mb-6 text-center text-gray-800">Đăng nhập Khách hàng</h2> <div class="space-y-4"> <div> <label class="block mb-2 text-gray-700">Tên đăng nhập</label> <input type="text" id="customer-username" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập tên khách hàng"> </div> <div> <label class="block mb-2 text-gray-700">Mật khẩu</label> <input type="password" id="customer-password" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập mật khẩu"> </div> <button onclick="customerLogin()" class="w-full bg-green-600 hover:bg-green-700 text-white py-3 px-4 rounded font-bold transition duration-200"> Đăng nhập </button> </div> </div> </div> <!-- Customer Register (Right) --> <div class="w-full md:w-1/3 bg-gray-100 p-8 flex flex-col justify-center"> <div class="max-w-md mx-auto w-full"> <h2 class="text-2xl font-bold mb-6 text-center text-gray-800">Đăng ký Khách hàng</h2> <div class="space-y-4"> <div> <label class="block mb-2 text-gray-700">Tên đăng nhập</label> <input type="text" id="register-username" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập tên khách hàng"> </div> <div> <label class="block mb-2 text-gray-700">Mật khẩu</label> <input type="password" id="register-password" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập mật khẩu"> </div> <div> <label class="block mb-2 text-gray-700">Xác nhận mật khẩu</label> <input type="password" id="register-confirm" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập lại mật khẩu"> </div> <button onclick="customerRegister()" class="w-full bg-purple-600 hover:bg-purple-700 text-white py-3 px-4 rounded font-bold transition duration-200"> Đăng ký </button> </div> </div> </div> </div> <!-- Admin Dashboard (Hidden by default) --> <div id="admin-dashboard" class="hidden min-h-screen"> <!-- Admin Header --> <header class="bg-blue-600 text-white shadow-lg"> <div class="container mx-auto px-4 py-4 flex justify-between items-center"> <div class="flex items-center space-x-2"> <i class="fas fa-user-shield text-2xl"></i> <h1 class="text-xl font-bold">F3squadshop - Quản trị viên</h1> </div> <div class="flex items-center space-x-4"> <span id="admin-name" class="font-medium">Xin chào, Admin</span> <button onclick="logout()" class="bg-red-500 hover:bg-red-600 px-4 py-2 rounded flex items-center space-x-2 transition duration-200"> <i class="fas fa-sign-out-alt"></i> <span>Đăng xuất</span> </button> </div> </div> </header> <!-- Admin Main Content --> <div class="container mx-auto px-4 py-6 flex flex-col md:flex-row"> <!-- Sidebar --> <aside class="w-full md:w-64 bg-white rounded-lg shadow-md p-4 mb-6 md:mb-0 md:mr-6"> <nav> <ul class="space-y-2"> <li> <button onclick="showSection('dashboard-section')" class="w-full text-left px-4 py-2 rounded bg-blue-100 text-blue-800 font-medium flex items-center space-x-2"> <i class="fas fa-tachometer-alt"></i> <span>Bảng điều khiển</span> </button> </li> <li> <button onclick="showSection('products-section')" class="w-full text-left px-4 py-2 rounded hover:bg-gray-100 flex items-center space-x-2"> <i class="fas fa-box-open"></i> <span>Sản phẩm</span> </button> </li> <li> <button onclick="showSection('add-product-section')" class="w-full text-left px-4 py-2 rounded hover:bg-gray-100 flex items-center space-x-2"> <i class="fas fa-plus-circle"></i> <span>Thêm sản phẩm</span> </button> </li> <li> <button onclick="showSection('orders-section')" class="w-full text-left px-4 py-2 rounded hover:bg-gray-100 flex items-center space-x-2"> <i class="fas fa-clipboard-list"></i> <span>Đơn hàng</span> </button> </li> </ul> </nav> </aside> <!-- Main Content --> <main class="flex-1"> <!-- Dashboard Section --> <section id="dashboard-section" class="bg-white rounded-lg shadow-md p-6 fade-in"> <h2 class="text-xl font-bold mb-6 text-gray-800">Bảng điều khiển</h2> <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6"> <div class="bg-blue-100 p-4 rounded-lg"> <h3 class="font-medium text-blue-800 mb-2">Tổng sản phẩm</h3> <p id="total-products" class="text-3xl font-bold text-blue-600">0</p> </div> <div class="bg-green-100 p-4 rounded-lg"> <h3 class="font-medium text-green-800 mb-2">Đơn hàng mới</h3> <p id="pending-orders" class="text-3xl font-bold text-green-600">0</p> </div> <div class="bg-purple-100 p-4 rounded-lg"> <h3 class="font-medium text-purple-800 mb-2">Tổng doanh thu</h3> <p id="total-revenue" class="text-3xl font-bold text-purple-600">0 ₫</p> </div> </div> <div class="bg-white border border-gray-200 rounded-lg p-4"> <h3 class="font-medium text-gray-800 mb-4">Thống kê gần đây</h3> <div class="h-64 flex items-center justify-center text-gray-500"> Biểu đồ thống kê sẽ hiển thị ở đây </div> </div> </section> <!-- Products Section --> <section id="products-section" class="hidden bg-white rounded-lg shadow-md p-6"> <div class="flex justify-between items-center mb-6"> <h2 class="text-xl font-bold text-gray-800">Quản lý sản phẩm</h2> <button onclick="showSection('add-product-section')" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded flex items-center space-x-2"> <i class="fas fa-plus"></i> <span>Thêm sản phẩm</span> </button> </div> <div class="overflow-x-auto"> <table class="min-w-full bg-white border border-gray-200"> <thead> <tr class="bg-gray-100"> <th class="py-3 px-4 text-left">Mã SP</th> <th class="py-3 px-4 text-left">Tên sản phẩm</th> <th class="py-3 px-4 text-left">Giá mua</th> <th class="py-3 px-4 text-left">Giá bán</th> <th class="py-3 px-4 text-left">Số lượng</th> <th class="py-3 px-4 text-left">Hành động</th> </tr> </thead> <tbody id="products-list" class="divide-y divide-gray-200"> <!-- Products will be loaded here --> </tbody> </table> </div> </section> <!-- Add Product Section --> <section id="add-product-section" class="hidden bg-white rounded-lg shadow-md p-6"> <h2 class="text-xl font-bold mb-6 text-gray-800">Thêm sản phẩm mới</h2> <form id="add-product-form" class="space-y-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> <div> <label class="block mb-2 text-gray-700">Mã sản phẩm</label> <input type="text" id="product-code" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập mã sản phẩm" required> </div> <div> <label class="block mb-2 text-gray-700">Tên sản phẩm</label> <input type="text" id="product-name" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập tên sản phẩm" required> </div> </div> <div class="grid grid-cols-1 md:grid-cols-3 gap-6"> <div> <label class="block mb-2 text-gray-700">Giá mua (₫)</label> <input type="number" id="product-cost" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập giá mua" required> </div> <div> <label class="block mb-2 text-gray-700">Giá bán (₫)</label> <input type="number" id="product-price" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập giá bán" required> </div> <div> <label class="block mb-2 text-gray-700">Số lượng</label> <input type="number" id="product-quantity" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập số lượng" required> </div> </div> <div> <label class="block mb-2 text-gray-700">Hình ảnh sản phẩm</label> <div class="flex items-center space-x-4"> <input type="text" id="product-image" class="flex-1 p-3 rounded border border-gray-300" placeholder="Dán URL hình ảnh đã sao chép"> <button type="button" onclick="pasteImage()" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-3 rounded"> <i class="fas fa-paste"></i> Dán hình ảnh </button> </div> <div id="image-preview" class="mt-4 hidden"> <p class="text-sm text-gray-500 mb-2">Xem trước hình ảnh:</p> <img id="preview-image" src="" alt="Preview" class="max-w-xs h-auto rounded border border-gray-300"> </div> </div> <div class="pt-4"> <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded font-bold"> <i class="fas fa-save mr-2"></i> Lưu sản phẩm </button> </div> </form> </section> <!-- Orders Section --> <section id="orders-section" class="hidden bg-white rounded-lg shadow-md p-6"> <h2 class="text-xl font-bold mb-6 text-gray-800">Quản lý đơn hàng</h2> <div class="mb-6"> <div class="flex space-x-4 border-b border-gray-200"> <button onclick="showOrderTab('pending')" class="px-4 py-2 font-medium border-b-2 border-blue-500 text-blue-600">Đang chờ</button> <button onclick="showOrderTab('approved')" class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Đã duyệt</button> <button onclick="showOrderTab('rejected')" class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Đã từ chối</button> </div> </div> <div id="pending-orders-list" class="space-y-4"> <!-- Pending orders will be loaded here --> </div> <div id="approved-orders-list" class="hidden space-y-4"> <!-- Approved orders will be loaded here --> </div> <div id="rejected-orders-list" class="hidden space-y-4"> <!-- Rejected orders will be loaded here --> </div> </section> </main> </div> </div> <!-- Customer Dashboard (Hidden by default) --> <div id="customer-dashboard" class="hidden min-h-screen"> <!-- Customer Header --> <header class="bg-green-600 text-white shadow-lg"> <div class="container mx-auto px-4 py-4 flex justify-between items-center"> <div class="flex items-center space-x-2"> <i class="fas fa-user text-2xl"></i> <h1 class="text-xl font-bold">F3squadshop - Khách hàng</h1> </div> <div class="flex items-center space-x-4"> <span id="customer-name" class="font-medium">Xin chào, Khách hàng</span> <button onclick="customerLogout()" class="bg-red-500 hover:bg-red-600 px-4 py-2 rounded flex items-center space-x-2 transition duration-200"> <i class="fas fa-sign-out-alt"></i> <span>Đăng xuất</span> </button> </div> </div> </header> <!-- Customer Main Content --> <div class="container mx-auto px-4 py-6"> <!-- Products Grid --> <div class="mb-8"> <h2 class="text-2xl font-bold mb-6 text-gray-800">Sản phẩm của chúng tôi</h2> <div id="customer-products" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6"> <!-- Products will be loaded here --> </div> </div> <!-- Customer Orders --> <div class="bg-white rounded-lg shadow-md p-6"> <h2 class="text-xl font-bold mb-6 text-gray-800">Đơn hàng của bạn</h2> <div id="customer-orders-list" class="space-y-4"> <!-- Orders will be loaded here --> </div> </div> </div> </div> <!-- Product Modal (Hidden by default) --> <div id="product-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto custom-scrollbar slide-in"> <div class="p-6"> <div class="flex justify-between items-center mb-4"> <h3 id="modal-product-name" class="text-xl font-bold text-gray-800"></h3> <button onclick="closeModal()" class="text-gray-500 hover:text-gray-700"> <i class="fas fa-times"></i> </button> </div> <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> <div> <img id="modal-product-image" src="" alt="Product Image" class="w-full h-auto rounded-lg border border-gray-200"> </div> <div> <div class="space-y-4"> <div> <p class="text-gray-600">Mã sản phẩm: <span id="modal-product-code" class="font-medium text-gray-800"></span></p> </div> <div> <p class="text-gray-600">Giá bán: <span id="modal-product-price" class="font-medium text-green-600"></span></p> </div> <div> <p class="text-gray-600">Số lượng còn: <span id="modal-product-quantity" class="font-medium text-gray-800"></span></p> </div> <div class="pt-4"> <div class="flex items-center space-x-4 mb-4"> <button onclick="decreaseQuantity()" class="bg-gray-200 hover:bg-gray-300 w-10 h-10 rounded-full flex items-center justify-center"> <i class="fas fa-minus"></i> </button> <input type="number" id="order-quantity" value="1" min="1" class="w-20 text-center border border-gray-300 rounded py-2"> <button onclick="increaseQuantity()" class="bg-gray-200 hover:bg-gray-300 w-10 h-10 rounded-full flex items-center justify-center"> <i class="fas fa-plus"></i> </button> </div> <button onclick="placeOrder()" class="w-full bg-green-600 hover:bg-green-700 text-white py-3 px-4 rounded font-bold"> <i class="fas fa-shopping-cart mr-2"></i> Đặt hàng </button> </div> </div> </div> </div> </div> </div> </div> <!-- Order Modal (Hidden by default) --> <div id="order-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto custom-scrollbar slide-in"> <div class="p-6"> <div class="flex justify-between items-center mb-4"> <h3 id="modal-order-title" class="text-xl font-bold text-gray-800">Xử lý đơn hàng</h3> <button onclick="closeOrderModal()" class="text-gray-500 hover:text-gray-700"> <i class="fas fa-times"></i> </button> </div> <div class="space-y-4"> <div> <p class="text-gray-600">Mã đơn hàng: <span id="modal-order-id" class="font-medium text-gray-800"></span></p> </div> <div> <p class="text-gray-600">Khách hàng: <span id="modal-order-customer" class="font-medium text-gray-800"></span></p> </div> <div> <p class="text-gray-600">Sản phẩm: <span id="modal-order-product" class="font-medium text-gray-800"></span></p> </div> <div> <p class="text-gray-600">Số lượng: <span id="modal-order-qty" class="font-medium text-gray-800"></span></p> </div> <div> <p class="text-gray-600">Tổng tiền: <span id="modal-order-total" class="font-medium text-green-600"></span></p> </div> <div> <label class="block mb-2 text-gray-700">Ghi chú cho khách hàng</label> <textarea id="order-note" class="w-full p-3 rounded border border-gray-300" rows="3" placeholder="Nhập ghi chú (nếu có)"></textarea> </div> <div class="pt-4 flex space-x-4"> <button onclick="approveOrder()" class="flex-1 bg-green-600 hover:bg-green-700 text-white py-3 px-4 rounded font-bold"> <i class="fas fa-check mr-2"></i> Duyệt đơn </button> <button onclick="rejectOrder()" class="flex-1 bg-red-600 hover:bg-red-700 text-white py-3 px-4 rounded font-bold"> <i class="fas fa-times mr-2"></i> Từ chối </button> </div> </div> </div> </div> </div> <!-- Notification (Hidden by default) --> <div id="notification" class="fixed bottom-4 right-4 bg-green-500 text-white px-6 py-3 rounded-lg shadow-lg hidden slide-in"> <div class="flex items-center space-x-2"> <i id="notification-icon" class="fas fa-check"></i> <span id="notification-message">Thao tác thành công!</span> </div> </div> </div> <script> // Global variables let currentUser = null; let products = JSON.parse(localStorage.getItem('products')) || []; let customers = JSON.parse(localStorage.getItem('customers')) || []; let orders = JSON.parse(localStorage.getItem('orders')) || []; let currentOrderId = null; // Admin credentials const adminCredentials = { username: 'F3squad', password: 'tuongbienTuongbien14082012', privilegeCode: '14082012' }; // Initialize the app document.addEventListener('DOMContentLoaded', function() { updateProductCount(); renderProductsForAdmin(); renderProductsForCustomer(); renderCustomerOrders(); }); // Admin login function function adminLogin() { const username = document.getElementById('admin-username').value; const password = document.getElementById('admin-password').value; const privilege = document.getElementById('admin-privilege').value; if (username === adminCredentials.username && password === adminCredentials.password && privilege === adminCredentials.privilegeCode) { currentUser = { type: 'admin', username: username }; document.getElementById('login-page').classList.add('hidden'); document.getElementById('admin-dashboard').classList.remove('hidden'); document.getElementById('admin-name').textContent = `Xin chào, ${username}`; showNotification('Đăng nhập thành công!', 'success'); showSection('dashboard-section'); } else { showNotification('Thông tin đăng nhập không chính xác!', 'error'); } } // Customer login function function customerLogin() { const username = document.getElementById('customer-username').value; const password = document.getElementById('customer-password').value; const customer = customers.find(c => c.username === username && c.password === password); if (customer) { currentUser = { type: 'customer', username: username, id: customer.id }; document.getElementById('login-page').classList.add('hidden'); document.getElementById('customer-dashboard').classList.remove('hidden'); document.getElementById('customer-name').textContent = `Xin chào, ${username}`; showNotification('Đăng nhập thành công!', 'success'); renderProductsForCustomer(); renderCustomerOrders(); } else { showNotification('Tên đăng nhập hoặc mật khẩu không đúng!', 'error'); } } // Customer registration function function customerRegister() { const username = document.getElementById('register-username').value; const password = document.getElementById('register-password').value; const confirm = document.getElementById('register-confirm').value; if (password !== confirm) { showNotification('Mật khẩu xác nhận không khớp!', 'error'); return; } if (customers.some(c => c.username === username)) { showNotification('Tên đăng nhập đã tồn tại!', 'error'); return; } const newCustomer = { id: Date.now().toString(), username: username, password: password }; customers.push(newCustomer); localStorage.setItem('customers', JSON.stringify(customers)); showNotification('Đăng ký thành công! Bạn có thể đăng nhập ngay bây giờ.', 'success'); // Clear the form document.getElementById('register-username').value = ''; document.getElementById('register-password').value = ''; document.getElementById('register-confirm').value = ''; } // Logout function function logout() { currentUser = null; document.getElementById('admin-dashboard').classList.add('hidden'); document.getElementById('login-page').classList.remove('hidden'); // Clear login fields document.getElementById('admin-username').value = ''; document.getElementById('admin-password').value = ''; document.getElementById('admin-privilege').value = ''; } // Customer logout function function customerLogout() { currentUser = null; document.getElementById('customer-dashboard').classList.add('hidden'); document.getElementById('login-page').classList.remove('hidden'); // Clear login fields document.getElementById('customer-username').value = ''; document.getElementById('customer-password').value = ''; } // Show section function function showSection(sectionId) { // Hide all sections document.querySelectorAll('main section').forEach(section => { section.classList.add('hidden'); }); // Show the selected section document.getElementById(sectionId).classList.remove('hidden'); // Update data if needed if (sectionId === 'dashboard-section') { updateDashboard(); } else if (sectionId === 'products-section') { renderProductsForAdmin(); } else if (sectionId === 'orders-section') { renderOrders('pending'); } } // Update dashboard stats function updateDashboard() { document.getElementById('total-products').textContent = products.length; const pendingOrders = orders.filter(o => o.status === 'pending').length; document.getElementById('pending-orders').textContent = pendingOrders; const totalRevenue = orders .filter(o => o.status === 'approved') .reduce((sum, order) => sum + (order.price * order.quantity), 0); document.getElementById('total-revenue').textContent = formatCurrency(totalRevenue); } // Add product form submission document.getElementById('add-product-form').addEventListener('submit', function(e) { e.preventDefault(); const product = { id: Date.now().toString(), code: document.getElementById('product-code').value, name: document.getElementById('product-name').value, cost: parseInt(document.getElementById('product-cost').value), price: parseInt(document.getElementById('product-price').value), quantity: parseInt(document.getElementById('product-quantity').value), image: document.getElementById('product-image').value || 'https://via.placeholder.com/300' }; products.push(product); localStorage.setItem('products', JSON.stringify(products)); showNotification('Thêm sản phẩm thành công!', 'success'); // Reset form this.reset(); document.getElementById('image-preview').classList.add('hidden'); // Update counts and lists updateProductCount(); renderProductsForAdmin(); renderProductsForCustomer(); // Go back to products list showSection('products-section'); }); // Paste image function function pasteImage() { navigator.clipboard.readText().then(text => { document.getElementById('product-image').value = text; document.getElementById('preview-image').src = text; document.getElementById('image-preview').classList.remove('hidden'); }).catch(err => { showNotification('Không thể đọc dữ liệu từ clipboard!', 'error'); }); } // Render products for admin function renderProductsForAdmin() { const container = document.getElementById('products-list'); container.innerHTML = ''; if (products.length === 0) { container.innerHTML = ` <tr> <td colspan="6" class="py-4 text-center text-gray-500">Không có sản phẩm nào</td> </tr> `; return; } products.forEach(product => { const row = document.createElement('tr'); row.className = 'hover:bg-gray-50'; row.innerHTML = ` <td class="py-3 px-4">${product.code}</td> <td class="py-3 px-4">${product.name}</td> <td class="py-3 px-4">${formatCurrency(product.cost)}</td> <td class="py-3 px-4">${formatCurrency(product.price)}</td> <td class="py-3 px-4">${product.quantity}</td> <td class="py-3 px-4"> <button onclick="editProduct('${product.id}')" class="text-blue-500 hover:text-blue-700 mr-3"> <i class="fas fa-edit"></i> </button> <button onclick="deleteProduct('${product.id}')" class="text-red-500 hover:text-red-700"> <i class="fas fa-trash"></i> </button> </td> `; container.appendChild(row); }); } // Render products for customer function renderProductsForCustomer() { const container = document.getElementById('customer-products'); container.innerHTML = ''; if (products.length === 0) { container.innerHTML = ` <div class="col-span-4 text-center py-8 text-gray-500"> <i class="fas fa-box-open text-4xl mb-2"></i> <p>Hiện không có sản phẩm nào</p> </div> `; return; } products.forEach(product => { const card = document.createElement('div'); card.className = 'bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition duration-200'; card.innerHTML = ` <div class="h-48 bg-gray-100 flex items-center justify-center"> <img src="${product.image || 'https://via.placeholder.com/300'}" alt="${product.name}" class="h-full w-full object-cover"> </div> <div class="p-4"> <h3 class="font-bold text-lg mb-1 text-gray-800">${product.name}</h3> <p class="text-gray-600 text-sm mb-2">Mã: ${product.code}</p> <p class="text-green-600 font-bold mb-4">${formatCurrency(product.price)}</p> <button onclick="viewProduct('${product.id}')" class="w-full bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded"> <i class="fas fa-eye mr-2"></i> Xem chi tiết </button> </div> `; container.appendChild(card); }); } // View product details (customer) function viewProduct(id) { const product = products.find(p => p.id === id); if (!product) return; document.getElementById('modal-product-name').textContent = product.name; document.getElementById('modal-product-code').textContent = product.code; document.getElementById('modal-product-price').textContent = formatCurrency(product.price); document.getElementById('modal-product-quantity').textContent = product.quantity; document.getElementById('modal-product-image').src = product.image || 'https://via.placeholder.com/300'; document.getElementById('order-quantity').value = 1; document.getElementById('order-quantity').max = product.quantity; document.getElementById('product-modal').classList.remove('hidden'); } // Close product modal function closeModal() { document.getElementById('product-modal').classList.add('hidden'); } // Increase quantity function increaseQuantity() { const input = document.getElementById('order-quantity'); const max = parseInt(input.max); let value = parseInt(input.value) || 0; if (value < max) { input.value = value + 1; } } // Decrease quantity function decreaseQuantity() { const input = document.getElementById('order-quantity'); let value = parseInt(input.value) || 0; if (value > 1) { input.value = value - 1; } } // Place order function placeOrder() { if (!currentUser || currentUser.type !== 'customer') { showNotification('Vui lòng đăng nhập để đặt hàng!', 'error'); return; } const productName = document.getElementById('modal-product-name').textContent; const productCode = document.getElementById('modal-product-code').textContent; const productPrice = parseInt(document.getElementById('modal-product-price').textContent.replace(/[^\d]/g, '')); const quantity = parseInt(document.getElementById('order-quantity').value); const product = products.find(p => p.code === productCode); if (!product) return; if (quantity > product.quantity) { showNotification('Số lượng đặt vượt quá số lượng tồn kho!', 'error'); return; } const order = { id: Date.now().toString(), customerId: currentUser.id, customerName: currentUser.username, productId: product.id, productName: product.name, productCode: product.code, price: product.price, quantity: quantity, total: product.price * quantity, status: 'pending', date: new Date().toISOString(), note: '' }; orders.push(order); localStorage.setItem('orders', JSON.stringify(orders)); showNotification('Đặt hàng thành công! Đơn hàng đang chờ xử lý.', 'success'); closeModal(); renderCustomerOrders(); if (document.getElementById('admin-dashboard').classList.contains('hidden') === false) { renderOrders('pending'); updateDashboard(); } } // Render customer orders function renderCustomerOrders() { if (!currentUser || currentUser.type !== 'customer') return; const container = document.getElementById('customer-orders-list'); container.innerHTML = ''; const customerOrders = orders.filter(o => o.customerId === currentUser.id); if (customerOrders.length === 0) { container.innerHTML = ` <div class="text-center py-8 text-gray-500"> <i class="fas fa-clipboard-list text-4xl mb-2"></i> <p>Bạn chưa có đơn hàng nào</p> </div> `; return; } customerOrders.forEach(order => { const orderElement = document.createElement('div'); orderElement.className = 'bg-white border border-gray-200 rounded-lg p-4'; let statusClass = ''; let statusIcon = ''; if (order.status === 'pending') { statusClass = 'bg-yellow-100 text-yellow-800'; statusIcon = 'fa-clock'; } else if (order.status === 'approved') { statusClass = 'bg-green-100 text-green-800'; statusIcon = 'fa-check'; } else { statusClass = 'bg-red-100 text-red-800'; statusIcon = 'fa-times'; } orderElement.innerHTML = ` <div class="flex justify-between items-start mb-2"> <div> <h3 class="font-bold text-gray-800">${order.productName}</h3> <p class="text-sm text-gray-600">Mã đơn: ${order.id}</p> </div> <span class="px-3 py-1 rounded-full text-xs font-medium ${statusClass}"> <i class="fas ${statusIcon} mr-1"></i> ${order.status === 'pending' ? 'Đang chờ' : order.status === 'approved' ? 'Đã duyệt' : 'Đã từ chối'} </span> </div> <div class="grid grid-cols-2 gap-4 mb-3"> <div> <p class="text-sm text-gray-600">Số lượng</p> <p class="font-medium">${order.quantity}</p> </div> <div> <p class="text-sm text-gray-600">Tổng tiền</p> <p class="font-medium text-green-600">${formatCurrency(order.total)}</p> </div> </div> ${order.note ? ` <div class="bg-blue-50 border-l-4 border-blue-500 p-3 text-sm text-gray-700"> <i class="fas fa-info-circle mr-1 text-blue-500"></i> ${order.note} </div> ` : ''} `; container.appendChild(orderElement); }); } // Render orders for admin function renderOrders(status) { const filteredOrders = orders.filter(o => o.status === status); const containerId = `${status}-orders-list`; const container = document.getElementById(containerId); container.innerHTML = ''; if (filteredOrders.length === 0) { container.innerHTML = ` <div class="text-center py-8 text-gray-500"> <i class="fas fa-clipboard-list text-4xl mb-2"></i> <p>Không có đơn hàng nào</p> </div> `; return; } filteredOrders.forEach(order => { const orderElement = document.createElement('div'); orderElement.className = 'bg-white border border-gray-200 rounded-lg p-4'; orderElement.innerHTML = ` <div class="flex justify-between items-start mb-2"> <div> <h3 class="font-bold text-gray-800">${order.productName}</h3> <p class="text-sm text-gray-600">Mã đơn: ${order.id}</p> </div> <span class="px-3 py-1 rounded-full text-xs font-medium ${status === 'pending' ? 'bg-yellow-100 text-yellow-800' : status === 'approved' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}"> <i class="fas ${status === 'pending' ? 'fa-clock' : status === 'approved' ? 'fa-check' : 'fa-times'} mr-1"></i> ${status === 'pending' ? 'Đang chờ' : status === 'approved' ? 'Đã duyệt' : 'Đã từ chối'} </span> </div> <div class="mb-3"> <p class="text-sm text-gray-600">Khách hàng: <span class="font-medium">${order.customerName}</span></p> </div> <div class="grid grid-cols-2 gap-4 mb-3"> <div> <p class="text-sm text-gray-600">Số lượng</p> <p class="font-medium">${order.quantity}</p> </div> <div> <p class="text-sm text-gray-600">Tổng tiền</p> <p class="font-medium text-green-600">${formatCurrency(order.total)}</p> </div> </div> <div class="flex justify-end"> <button onclick="openOrderModal('${order.id}')" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded text-sm"> <i class="fas fa-edit mr-1"></i> Xử lý </button> </div> `; container.appendChild(orderElement); }); } // Show order tab function showOrderTab(tab) { document.getElementById('pending-orders-list').classList.add('hidden'); document.getElementById('approved-orders-list').classList.add('hidden'); document.getElementById('rejected-orders-list').classList.add('hidden'); document.getElementById(`${tab}-orders-list`).classList.remove('hidden'); renderOrders(tab); } // Open order modal function openOrderModal(orderId) { const order = orders.find(o => o.id === orderId); if (!order) return; currentOrderId = orderId; document.getElementById('modal-order-id').textContent = order.id; document.getElementById('modal-order-customer').textContent = order.customerName; document.getElementById('modal-order-product').textContent = order.productName; document.getElementById('modal-order-qty').textContent = order.quantity; document.getElementById('modal-order-total').textContent = formatCurrency(order.total); document.getElementById('order-note').value = order.note || ''; document.getElementById('order-modal').classList.remove('hidden'); } // Close order modal function closeOrderModal() { document.getElementById('order-modal').classList.add('hidden'); currentOrderId = null; } // Approve order function approveOrder() { if (!currentOrderId) return; const orderIndex = orders.findIndex(o => o.id === currentOrderId); if (orderIndex === -1) return; const productIndex = products.findIndex(p => p.id === orders[orderIndex].productId); if (productIndex === -1) return; // Check if enough quantity if (products[productIndex].quantity < orders[orderIndex].quantity) { showNotification('Số lượng tồn kho không đủ để duyệt đơn này!', 'error'); return; } // Update product quantity products[productIndex].quantity -= orders[orderIndex].quantity; localStorage.setItem('products', JSON.stringify(products)); // Update order status orders[orderIndex].status = 'approved'; orders[orderIndex].note = document.getElementById('order-note').value; localStorage.setItem('orders', JSON.stringify(orders)); showNotification('Đã duyệt đơn hàng thành công!', 'success'); closeOrderModal(); // Refresh views renderOrders('pending'); renderOrders('approved'); updateDashboard(); // If customer is viewing their orders, refresh that too if (document.getElementById('customer-dashboard').classList.contains('hidden') === false) { renderCustomerOrders(); } } // Reject order function rejectOrder() { if (!currentOrderId) return; const orderIndex = orders.findIndex(o => o.id === currentOrderId); if (orderIndex === -1) return; // Update order status orders[orderIndex].status = 'rejected'; orders[orderIndex].note = document.getElementById('order-note').value; localStorage.setItem('orders', JSON.stringify(orders)); showNotification('Đã từ chối đơn hàng!', 'success'); closeOrderModal(); // Refresh views renderOrders('pending'); renderOrders('rejected'); updateDashboard(); // If customer is viewing their orders, refresh that too if (document.getElementById('customer-dashboard').classList.contains('hidden') === false) { renderCustomerOrders(); } } // Edit product function editProduct(id) { const product = products.find(p => p.id === id); if (!product) return; document.getElementById('product-code').value = product.code; document.getElementById('product-name').value = product.name; document.getElementById('product-cost').value = product.cost; document.getElementById('product-price').value = product.price; document.getElementById('product-quantity').value = product.quantity; document.getElementById('product-image').value = product.image; if (product.image) { document.getElementById('preview-image').src = product.image; document.getElementById('image-preview').classList.remove('hidden'); } // Remove the product from the list products = products.filter(p => p.id !== id); localStorage.setItem('products', JSON.stringify(products)); showSection('add-product-section'); showNotification('Sản phẩm đã được tải lên form chỉnh sửa. Lưu lại sau khi chỉnh sửa.', 'info'); } // Delete product function deleteProduct(id) { if (!confirm('Bạn có chắc chắn muốn xóa sản phẩm này?')) return; products = products.filter(p => p.id !== id); localStorage.setItem('products', JSON.stringify(products)); showNotification('Đã xóa sản phẩm!', 'success'); renderProductsForAdmin(); renderProductsForCustomer(); updateProductCount(); } // Update product count function updateProductCount() { document.getElementById('total-products').textContent = products.length; } // Format currency function formatCurrency(amount) { return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(amount); } // Show notification function showNotification(message, type) { const notification = document.getElementById('notification'); const icon = document.getElementById('notification-icon'); const msg = document.getElementById('notification-message'); // Set icon and color based on type if (type === 'success') { notification.className = 'fixed bottom-4 right-4 bg-green-500 text-white px-6 py-3 rounded-lg shadow-lg flex items-center space-x-2 slide-in'; icon.className = 'fas fa-check'; } else if (type === 'error') { notification.className = 'fixed bottom-4 right-4 bg-red-500 text-white px-6 py-3 rounded-lg shadow-lg flex items-center space-x-2 slide-in'; icon.className = 'fas fa-exclamation-circle'; } else if (type === 'info') { notification.className = 'fixed bottom-4 right-4 bg-blue-500 text-white px-6 py-3 rounded-lg shadow-lg flex items-center space-x-2 slide-in'; icon.className = 'fas fa-info-circle'; } msg.textContent = message; notification.classList.remove('hidden'); // Hide after 3 seconds setTimeout(() => { notification.classList.add('hidden'); }, 3000); } </script> <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=F3squad18/f3squadshop-com" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> </html>
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>F3squadshop - Admin Panel</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.fade-in {
animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.slide-in {
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #f1f1f1;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #888;
border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #555;
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<!-- Main Container -->
<div id="app" class="min-h-screen">
<!-- Login Page -->
<div id="login-page" class="flex flex-col md:flex-row min-h-screen">
<!-- Admin Login (Left) -->
<div class="w-full md:w-1/3 bg-blue-600 text-white p-8 flex flex-col justify-center">
<div class="max-w-md mx-auto w-full">
<h2 class="text-2xl font-bold mb-6 text-center">Đăng nhập Admin</h2>
<div class="space-y-4">
<div>
<label class="block mb-2">Tên tài khoản</label>
<input type="text" id="admin-username" class="w-full p-3 rounded text-gray-800" placeholder="Nhập tên admin">
</div>
<div>
<label class="block mb-2">Mật khẩu</label>
<input type="password" id="admin-password" class="w-full p-3 rounded text-gray-800" placeholder="Nhập mật khẩu">
</div>
<div>
<label class="block mb-2">Mã đặc quyền</label>
<input type="password" id="admin-privilege" class="w-full p-3 rounded text-gray-800" placeholder="Nhập mã đặc quyền">
</div>
<button onclick="adminLogin()" class="w-full bg-blue-800 hover:bg-blue-900 text-white py-3 px-4 rounded font-bold transition duration-200">
Đăng nhập
</button>
</div>
</div>
</div>
<!-- Customer Login (Middle) -->
<div class="w-full md:w-1/3 bg-white p-8 flex flex-col justify-center border-l border-r border-gray-200">
<div class="max-w-md mx-auto w-full">
<h2 class="text-2xl font-bold mb-6 text-center text-gray-800">Đăng nhập Khách hàng</h2>
<div class="space-y-4">
<div>
<label class="block mb-2 text-gray-700">Tên đăng nhập</label>
<input type="text" id="customer-username" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập tên khách hàng">
</div>
<div>
<label class="block mb-2 text-gray-700">Mật khẩu</label>
<input type="password" id="customer-password" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập mật khẩu">
</div>
<button onclick="customerLogin()" class="w-full bg-green-600 hover:bg-green-700 text-white py-3 px-4 rounded font-bold transition duration-200">
Đăng nhập
</button>
</div>
</div>
</div>
<!-- Customer Register (Right) -->
<div class="w-full md:w-1/3 bg-gray-100 p-8 flex flex-col justify-center">
<div class="max-w-md mx-auto w-full">
<h2 class="text-2xl font-bold mb-6 text-center text-gray-800">Đăng ký Khách hàng</h2>
<div class="space-y-4">
<div>
<label class="block mb-2 text-gray-700">Tên đăng nhập</label>
<input type="text" id="register-username" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập tên khách hàng">
</div>
<div>
<label class="block mb-2 text-gray-700">Mật khẩu</label>
<input type="password" id="register-password" class="w-full p-3 rounded border border-gray-300" placeholder="Nhập mật khẩu">
</div>