Admin em vẫn ko call được phần thể loại ạ Admin kiểm tra source giúp em với ạ
<!DOCTYPE html>
<html lang=“vi”>
<head>
<meta charset=“UTF-8”>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<title>Kho Phim Easylove</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
margin: 20px 0;
}
.search-container, .list-container {
margin: 20px;
}
.container {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 20px;
padding: 20px;
max-width: 1200px;
width: 100%;
}
.movie {
background-color: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: transform 0.3s, box-shadow 0.3s;
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
}
.movie img {
width: 100%;
height: auto;
max-height: 300px;
object-fit: cover;
transition: transform 0.3s;
}
.movie h2 {
font-size: 18px;
margin: 10px;
}
.movie p {
font-size: 14px;
color: #555;
margin: 0 10px 10px;
}
.movie:hover {
transform: translateY(-10px);
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2);
}
.movie:hover img {
transform: scale(1.05);
}
.pagination {
text-align: center;
margin: 20px 0;
}
.pagination button {
margin: 0 5px;
padding: 10px 20px;
border: none;
background-color: transparent;
color: inherit;
cursor: pointer;
border-radius: 4px;
}
.list-container select, .list-container button {
margin: 0 10px;
}
@media (max-width: 1200px) {
.container {
grid-template-columns: repeat(4, 1fr);
}
}
@media (max-width: 900px) {
.container {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 600px) {
.container {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<h1>Kho Phim Easylove</h1>
<div class=“search-container”>
<input type=“text” id=“search-input” placeholder=“Tìm kiếm phim…” onkeypress=“handleKeyPress(event)”>
<button onclick=“searchMovies()”>Tìm Kiếm</button>
</div>
<div class=“list-container”>
<select id=“list-select” onchange=“resetPageAndLoadList()”>
<option value="">Chọn danh sách phim</option>
<option value=“phim-bo”>Phim Bộ</option>
<option value=“phim-le”>Phim Lẻ</option>
<option value=“hoat-hinh”>Hoạt Hình</option>
<option value=“tv-shows”>TV Shows</option>
<option value=“phim-vietsub”>Phim Vietsub</option>
<option value=“phim-thuyet-minh”>Phim Thuyết Minh</option>
<option value=“phim-long-tieng”>Phim Lồng Ghép</option>
<option value=“phim-bo-dang-chieu”>Phim Bộ Đang Chiếu</option>
<option value=“phim-bo-hoan-thanh”>Phim Bộ Hoàn Thành</option>
<option value=“phim-sap-chieu”>Phim Sắp Chiếu</option>
<option value=“subteam”>Subteam</option>
</select>
<select id=“genre-select” onchange=“resetPageAndLoadList()”>
<option value="">Chọn thể loại</option>
</select>
<select id=“country-select” onchange=“resetPageAndLoadList()”>
<option value="">Chọn quốc gia</option>
</select>
</div>
<div class=“container” id=“movie-container”></div>
<div class=“pagination”>
<button onclick=“prevPage()”>Trang Trước</button>
<span id=“page-number”>1</span>
<button onclick=“nextPage()”>Trang Sau</button>
</div>
<script>
let currentPage = 1;
let listType = '';
let genreFilter = '';
let countryFilter = '';
let isLoading = false;
async function fetchMovies(page, type, genre, country) {
try {
let url = `https://ophim1.com/v1/api/danh-sach/${type}?page=${page}`;
if (genre) url += `&genre=${genre}`;
if (country) url += `&country=${country}`;
console.log('Fetching URL:', url);
const response = await fetch(url);
const data = await response.json();
return data.data.items || [];
} catch (error) {
console.error('Error fetching movies:', error);
return [];
}
}
async function fetchGenres() {
try {
const response = await fetch('https://ophim1.com/v1/api/the-loai');
const data = await response.json();
return Array.isArray(data.data.items) ? data.data.items : [];
} catch (error) {
console.error('Error fetching genres:', error);
return [];
}
}
async function fetchCountries() {
try {
const response = await fetch('https://ophim1.com/v1/api/quoc-gia');
const data = await response.json();
return Array.isArray(data.data.items) ? data.data.items : [];
} catch (error) {
console.error('Error fetching countries:', error);
return [];
}
}
async function loadGenres() {
const genres = await fetchGenres();
const genreSelect = document.getElementById('genre-select');
genreSelect.innerHTML = '<option value="">Chọn thể loại</option>';
genres.forEach(genre => {
const option = document.createElement('option');
option.value = genre.slug;
option.textContent = genre.name;
genreSelect.appendChild(option);
});
}
async function loadCountries() {
const countries = await fetchCountries();
const countrySelect = document.getElementById('country-select');
countrySelect.innerHTML = '<option value="">Chọn quốc gia</option>';
countries.forEach(country => {
const option = document.createElement('option');
option.value = country.slug;
option.textContent = country.name;
countrySelect.appendChild(option);
});
}
function renderMovies(movies) {
const container = document.getElementById('movie-container');
container.innerHTML = '';
if (movies.length > 0) {
movies.forEach(movie => {
const movieElement = document.createElement('div');
movieElement.classList.add('movie');
movieElement.onclick = () => {
window.location.href = `detail.html?slug=${movie.slug}`;
};
movieElement.innerHTML = `
<img src="https://img.ophim.live/uploads/movies/${movie.thumb_url}" alt="${movie.name}">
<h2>${movie.name}</h2>
<p>Năm: ${movie.year}</p>
`;
container.appendChild(movieElement);
});
} else {
container.innerHTML = '<p>Không tìm thấy phim.</p>';
}
}
async function loadMovies() {
if (isLoading) return;
isLoading = true;
const movies = await fetchMovies(currentPage, listType, genreFilter, countryFilter);
renderMovies(movies);
document.getElementById('page-number').textContent = currentPage;
window.scrollTo(0, 0);
isLoading = false;
}
async function loadList() {
listType = document.getElementById('list-select').value;
genreFilter = document.getElementById('genre-select').value;
countryFilter = document.getElementById('country-select').value;
currentPage = 1;
await loadMovies();
}
function resetPageAndLoadList() {
currentPage = 1;
loadList();
}
function prevPage() {
if (currentPage > 1) {
currentPage--;
loadMovies();
}
}
function nextPage() {
currentPage++;
loadMovies();
}
function handleKeyPress(event) {
if (event.key === 'Enter') {
searchMovies();
}
}
async function searchMovies() {
const keyword = document.getElementById('search-input').value;
try {
const response = await fetch(`https://ophim1.com/v1/api/tim-kiem?keyword=${keyword}`);
const data = await response.json();
renderMovies(data.data.items || []);
} catch (error) {
console.error('Error searching movies:', error);
document.getElementById('movie-container').innerHTML = '<p>Đã xảy ra lỗi trong khi tìm kiếm phim.</p>';
}
}
document.addEventListener('DOMContentLoaded', async () => {
await loadGenres();
await loadCountries();
await loadMovies();
});
</script>
</body>
</html>