add template unggulan
This commit is contained in:
parent
ebc4513762
commit
050c0b8ffd
@ -8,11 +8,23 @@ use App\Models\Template;
|
|||||||
class TemplateApiController extends Controller
|
class TemplateApiController extends Controller
|
||||||
{
|
{
|
||||||
// User hanya bisa lihat semua template
|
// User hanya bisa lihat semua template
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
// UBAH DI SINI: 'fitur' -> 'fiturs'
|
$templates = Template::with(['kategori','fiturs'])
|
||||||
return response()->json(Template::with(['kategori','fiturs'])->get());
|
->get()
|
||||||
}
|
->map(function($t){
|
||||||
|
return [
|
||||||
|
'id' => $t->id,
|
||||||
|
'nama' => $t->nama_template,
|
||||||
|
'harga' => (float) $t->harga,
|
||||||
|
'foto' => asset('storage/' . $t->foto),
|
||||||
|
'kategori' => $t->kategori,
|
||||||
|
'fiturs' => $t->fiturs,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return response()->json($templates);
|
||||||
|
}
|
||||||
|
|
||||||
// User bisa lihat detail 1 template
|
// User bisa lihat detail 1 template
|
||||||
public function show(Template $template)
|
public function show(Template $template)
|
||||||
|
|||||||
@ -1,175 +1,108 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
|
||||||
|
// id template yang mau ditampilkan
|
||||||
|
const selectedIds = [1, 2, 3, 5, 6, 8]
|
||||||
|
|
||||||
|
// state dropdown
|
||||||
|
const openDropdownId = ref(null)
|
||||||
|
const toggleDropdown = (templateId) => {
|
||||||
|
openDropdownId.value = openDropdownId.value === templateId ? null : templateId
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch API dari Laravel
|
||||||
|
const { data: templatesData, error } = await useFetch('http://localhost:8000/api/templates')
|
||||||
|
|
||||||
|
// filter hanya id tertentu
|
||||||
|
const templates = computed(() =>
|
||||||
|
(templatesData.value || []).filter(t => selectedIds.includes(t.id))
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<section id="template" class="feature-section">
|
<section id="template" class="py-16 px-5 text-center">
|
||||||
<div class="featured-header">
|
<!-- Header -->
|
||||||
<h2>Templat Unggulan</h2>
|
<div class="mb-10">
|
||||||
<p>"Tersedia berbagai desain undangan pernikahan, khitan, ulang tahun, dan lainnya."</p>
|
<h2 class="text-[2.9rem] font-bold mb-6">Templat Unggulan</h2>
|
||||||
|
<p class="text-gray-600 text-lg mb-10">
|
||||||
|
"Tersedia berbagai desain undangan pernikahan, khitan, ulang tahun, dan lainnya."
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Grid Template -->
|
<!-- Grid Template -->
|
||||||
<div class="template-grid">
|
<div v-if="templates.length" class="grid gap-8 max-w-[1100px] mx-auto grid-cols-1 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
<div class="template-card" v-for="i in 6" :key="i">
|
<div
|
||||||
<div class="template-image">
|
v-for="t in templates"
|
||||||
<img src="/templat.jpg" alt="Template" />
|
:key="t.id"
|
||||||
</div>
|
class="bg-white border rounded-lg overflow-hidden shadow-md hover:shadow-xl transition-shadow duration-300"
|
||||||
|
>
|
||||||
|
<!-- Image -->
|
||||||
|
<img
|
||||||
|
:src="`http://localhost:8000${t.foto}`"
|
||||||
|
:alt="t.nama_template"
|
||||||
|
class="w-full h-48 object-cover"
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="template-body">
|
<!-- Body -->
|
||||||
<h3 class="template-title">Golf Party</h3>
|
<div class="p-5 text-center">
|
||||||
<p class="template-price">Rp.89.000</p>
|
<h4 class="text-xl font-bold text-gray-800 mb-2">{{ t.nama }}</h4>
|
||||||
|
<p class="text-green-600 font-semibold text-xl mb-4">
|
||||||
|
Rp {{ Number(t.harga).toLocaleString('id-ID') }}
|
||||||
|
</p>
|
||||||
|
|
||||||
<select class="template-select">
|
<!-- Dropdown fitur -->
|
||||||
<option>Fitur Terbaik</option>
|
<div v-if="t.fiturs && t.fiturs.length > 0" class="relative mb-4">
|
||||||
<option>Fitur Lengkap</option>
|
<button
|
||||||
</select>
|
@click="toggleDropdown(t.id)"
|
||||||
|
class="w-full bg-white border border-gray-300 rounded-md shadow-sm px-4 py-2 inline-flex justify-between items-center"
|
||||||
|
>
|
||||||
|
<span class="mx-auto text-gray-700 font-semibold">FITUR YANG TERSEDIA</span>
|
||||||
|
<svg class="h-5 w-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
<div class="button-group">
|
<div v-if="openDropdownId === t.id">
|
||||||
<button class="btn btn-preview">Preview</button>
|
<ul class="mt-4 space-y-2 text-gray-600 text-left">
|
||||||
<button class="btn btn-order">Order</button>
|
<li v-for="f in t.fiturs" :key="f.id" class="flex items-center">
|
||||||
|
<svg class="h-4 w-4 text-green-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
||||||
|
</svg>
|
||||||
|
{{ f.deskripsi }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Buttons -->
|
||||||
|
<div class="flex items-center gap-3 mt-6">
|
||||||
|
<button
|
||||||
|
class="w-full bg-white border border-gray-300 text-gray-800 font-semibold py-2 px-4 rounded-lg hover:bg-gray-100 transition-colors"
|
||||||
|
>
|
||||||
|
Preview
|
||||||
|
</button>
|
||||||
|
<NuxtLink
|
||||||
|
:to="`/form/${t.kategori.nama.toLowerCase().replace(/ /g, '-')}` + `?template_id=${t.id}`"
|
||||||
|
class="w-full bg-blue-600 text-white font-semibold py-2 px-4 rounded-lg hover:bg-blue-700 transition-colors text-center"
|
||||||
|
>
|
||||||
|
Order
|
||||||
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="see-more">
|
<!-- Jika error -->
|
||||||
<NuxtLink to="/template">Lihat Selengkapnya...</NuxtLink>
|
<div v-else class="text-gray-500">Tidak ada template yang bisa ditampilkan</div>
|
||||||
|
|
||||||
|
<!-- See more -->
|
||||||
|
<div class="mt-8 text-right max-w-[1100px] mx-auto">
|
||||||
|
<NuxtLink
|
||||||
|
to="/template"
|
||||||
|
class="text-blue-600 font-medium hover:underline"
|
||||||
|
>
|
||||||
|
Lihat Selengkapnya...
|
||||||
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.featured-section {
|
|
||||||
padding: 60px 20px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.featured-header h2 {
|
|
||||||
font-size: 2.9rem;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-bottom: 30px;
|
|
||||||
text-align: center;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.featured-header p {
|
|
||||||
color: #555;
|
|
||||||
margin-bottom: 40px;
|
|
||||||
font-size: 17px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
|
||||||
gap: 24px;
|
|
||||||
max-width: 1100px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-card {
|
|
||||||
background: #f2f2f2;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 16px;
|
|
||||||
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 400px;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-image {
|
|
||||||
background: #fff;
|
|
||||||
border-radius: 10px;
|
|
||||||
width: 100%;
|
|
||||||
height: 180px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-image img {
|
|
||||||
max-height: 100%;
|
|
||||||
object-fit: contain;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-body {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-between;
|
|
||||||
width: 100%;
|
|
||||||
margin-top: 12px;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-title {
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: 600;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-price {
|
|
||||||
color: #008000;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.template-select {
|
|
||||||
width: 100%;
|
|
||||||
padding: 8px;
|
|
||||||
border-radius: 6px;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-group {
|
|
||||||
display: flex;
|
|
||||||
gap: 10px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
flex: 1;
|
|
||||||
padding: 10px 0;
|
|
||||||
border-radius: 6px;
|
|
||||||
font-weight: 500;
|
|
||||||
cursor: pointer;
|
|
||||||
border: none;
|
|
||||||
transition: 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-preview {
|
|
||||||
background: #e5e5e5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-preview:hover {
|
|
||||||
background: #d6d6d6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-order {
|
|
||||||
background: #2563eb;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-order:hover {
|
|
||||||
background: #1d4ed8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.see-more {
|
|
||||||
margin-top: 30px;
|
|
||||||
text-align: right;
|
|
||||||
max-width: 1100px;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.see-more a {
|
|
||||||
color: #2563eb;
|
|
||||||
font-weight: 500;
|
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.see-more a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user