105 lines
4.6 KiB
PHP
105 lines
4.6 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', 'Buat Pesanan')
|
|
|
|
@section('content')
|
|
<div class="container mx-auto py-8">
|
|
<div class="max-w-2xl mx-auto bg-white shadow-md rounded-xl p-8 border border-blue-100">
|
|
<h2 class="text-2xl font-semibold text-black mb-6">Buat Pesanan</h2>
|
|
|
|
<form action="{{ route('pelanggans.store') }}" method="POST" class="space-y-5">
|
|
@csrf
|
|
|
|
<!-- Nama Pemesan -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Nama Pemesan</label>
|
|
<input type="text" name="nama_pemesan"
|
|
value="{{ old('nama_pemesan') }}"
|
|
class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-400 focus:outline-none"
|
|
required>
|
|
</div>
|
|
|
|
<!-- Email -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Email</label>
|
|
<input type="email" name="email"
|
|
value="{{ old('email') }}"
|
|
class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-400 focus:outline-none"
|
|
required>
|
|
</div>
|
|
|
|
<!-- No. Telepon -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">No. Telepon</label>
|
|
<input type="text" name="no_tlpn"
|
|
value="{{ old('no_tlpn') }}"
|
|
class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-400 focus:outline-none"
|
|
required>
|
|
</div>
|
|
|
|
<!-- Template -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Template</label>
|
|
<select name="template_id" id="template_id"
|
|
class="w-full border border-gray-300 rounded-lg px-4 py-2 bg-gray-50 focus:ring-2 focus:ring-blue-400 focus:outline-none"
|
|
required>
|
|
<option value="">-- Pilih Template --</option>
|
|
@foreach($templates as $template)
|
|
<option value="{{ $template->id }}" data-form='@json($template->form)'>
|
|
{{ $template->nama_template }} (Rp {{ number_format($template->harga,0,',','.') }})
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Tempat field dinamis -->
|
|
<div id="dynamic-form"></div>
|
|
|
|
<!-- Tombol -->
|
|
<div class="flex justify-end pt-4">
|
|
<button type="submit"
|
|
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-6 py-2 rounded-lg shadow transition duration-200">
|
|
Kirim Pesanan
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('template_id').addEventListener('change', function () {
|
|
let selected = this.options[this.selectedIndex];
|
|
let formJson = selected.getAttribute('data-form');
|
|
let container = document.getElementById('dynamic-form');
|
|
container.innerHTML = '';
|
|
|
|
if (formJson) {
|
|
let fields = JSON.parse(formJson);
|
|
for (let key in fields) {
|
|
let field = fields[key];
|
|
let label = field.label ?? key;
|
|
let input = '';
|
|
|
|
if (field.type === 'text') {
|
|
input = `<input type="text" name="form[${key}]" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-400 focus:outline-none" ${field.required ? 'required' : ''}>`;
|
|
} else if (field.type === 'textarea') {
|
|
input = `<textarea name="form[${key}]" class="w-full border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-400 focus:outline-none" ${field.required ? 'required' : ''}></textarea>`;
|
|
} else if (field.type === 'select') {
|
|
input = `<select name="form[${key}]" class="w-full border border-gray-300 rounded-lg px-4 py-2 bg-gray-50 focus:ring-2 focus:ring-blue-400 focus:outline-none">`;
|
|
field.options.forEach(opt => {
|
|
input += `<option value="${opt}">${opt}</option>`;
|
|
});
|
|
input += `</select>`;
|
|
}
|
|
container.innerHTML += `
|
|
<div class="mb-3">
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">${label}</label>
|
|
${input}
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
@endsection
|