[update] membuat item dari halaman produk
This commit is contained in:
parent
8046360f6e
commit
4e06c25082
@ -5,39 +5,23 @@
|
|||||||
|
|
||||||
<div v-if="!success">
|
<div v-if="!success">
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<p class="text-gray-600 mb-4">Produk "<strong>{{ product?.nama }}</strong>" berhasil dibuat!</p>
|
<label class="block text-gray-700 mb-2">Pilih Nampan</label>
|
||||||
|
<InputSelect v-model="selectedNampan" :options="positionListOptions" :disabled="loading" />
|
||||||
<div class="mb-4">
|
|
||||||
<label class="block text-gray-700 mb-2">Pilih Nampan</label>
|
|
||||||
<select
|
|
||||||
v-model="selectedNampan"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
|
||||||
:disabled="loading"
|
|
||||||
>
|
|
||||||
<option value="">Brankas</option>
|
|
||||||
<option v-for="nampan in nampanList" :key="nampan.id" :value="nampan.id">
|
|
||||||
{{ nampan.nama }} ({{ nampan.items_count }} items)
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end gap-3">
|
<div class="flex justify-end gap-3">
|
||||||
<button
|
<button @click="handleClose" :disabled="loading"
|
||||||
@click="handleClose"
|
class="px-4 py-2 text-white bg-gray-400 hover:bg-gray-500 rounded-lg transition-colors disabled:opacity-50">
|
||||||
:disabled="loading"
|
|
||||||
class="px-4 py-2 text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors disabled:opacity-50"
|
|
||||||
>
|
|
||||||
Batal
|
Batal
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button @click="createItem" :disabled="loading"
|
||||||
@click="createItem"
|
class="px-4 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors disabled:bg-A disabled:cursor-not-allowed flex items-center gap-2">
|
||||||
:disabled="loading"
|
|
||||||
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors disabled:bg-blue-400 disabled:cursor-not-allowed flex items-center gap-2"
|
|
||||||
>
|
|
||||||
<svg v-if="loading" class="animate-spin w-4 h-4" fill="none" viewBox="0 0 24 24">
|
<svg v-if="loading" class="animate-spin w-4 h-4" fill="none" viewBox="0 0 24 24">
|
||||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4">
|
||||||
<path class="opacity-75" fill="currentColor" d="m4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
</circle>
|
||||||
|
<path class="opacity-75" fill="currentColor"
|
||||||
|
d="m4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
|
||||||
|
</path>
|
||||||
</svg>
|
</svg>
|
||||||
{{ loading ? 'Membuat...' : 'Buat Item' }}
|
{{ loading ? 'Membuat...' : 'Buat Item' }}
|
||||||
</button>
|
</button>
|
||||||
@ -48,33 +32,34 @@
|
|||||||
<div v-else>
|
<div v-else>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
<div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||||
<!-- QR CODe HERE -->
|
<svg class="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7">
|
||||||
|
</path>
|
||||||
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h4 class="text-lg font-semibold text-gray-900 mb-2">Item Berhasil Dibuat!</h4>
|
<h4 class="text-lg font-semibold text-gray-900 mb-2">Item Berhasil Dibuat!</h4>
|
||||||
<p class="text-gray-600 mb-6">
|
<p class="text-gray-600 mb-2">
|
||||||
Item dari produk "<strong>{{ product?.nama }}</strong>" telah ditambahkan ke {{ selectedNampanName }}.
|
Item dari produk "<strong>{{ product?.nama }}</strong>" telah ditambahkan ke {{
|
||||||
|
selectedNampanName }}.
|
||||||
|
</p>
|
||||||
|
<p class="text-sm text-gray-500 mb-6">
|
||||||
|
ID Item: <strong>{{ createdItem.id }}</strong>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="flex flex-row justify-between gap-3">
|
<div class="flex flex-row justify-between gap-3">
|
||||||
<button
|
<button @click="handleClose"
|
||||||
@click="$emit('finish')"
|
class="flex-1 px-6 py-2 bg-gray-400 hover:bg-gray-500 text-white rounded-lg transition-colors">
|
||||||
class="flex-1 px-6 py-2 bg-gray-400 hover:bg-gray-500 text-white rounded-lg transition-colors"
|
|
||||||
>
|
|
||||||
Selesai
|
Selesai
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button @click="printItem"
|
||||||
@click="$emit('print')"
|
|
||||||
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors opacity-50 cursor-not-allowed"
|
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors opacity-50 cursor-not-allowed"
|
||||||
disabled
|
disabled>
|
||||||
>
|
|
||||||
Print
|
Print
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button @click="addNewItem"
|
||||||
@click="addNewItem"
|
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors">
|
||||||
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors"
|
Buat Lagi
|
||||||
>
|
|
||||||
Tambah Item Baru
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -87,6 +72,7 @@
|
|||||||
import { ref, computed, watch } from 'vue';
|
import { ref, computed, watch } from 'vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import Modal from './Modal.vue';
|
import Modal from './Modal.vue';
|
||||||
|
import InputSelect from './InputSelect.vue';
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -100,16 +86,27 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['close', 'finish', 'print', 'item-created']);
|
// Emits
|
||||||
|
const emit = defineEmits(['close']);
|
||||||
|
|
||||||
|
// State
|
||||||
const selectedNampan = ref('');
|
const selectedNampan = ref('');
|
||||||
const nampanList = ref([]);
|
const nampanList = ref([]);
|
||||||
|
const positionListOptions = ref([
|
||||||
|
{ value: '', label: 'Brankas', selected: true },
|
||||||
|
])
|
||||||
const success = ref(false);
|
const success = ref(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const createdItem = ref(null);
|
||||||
|
|
||||||
|
// Computed
|
||||||
const selectedNampanName = computed(() => {
|
const selectedNampanName = computed(() => {
|
||||||
if (!selectedNampan.value) return 'Brankas';
|
if (!selectedNampan.value) return 'Brankas';
|
||||||
const nampan = nampanList.value.find(n => n.id === selectedNampan.value);
|
|
||||||
|
console.log("Selected nampan ID:", selectedNampan.value);
|
||||||
|
const nampan = nampanList.value.find(n => n.id === Number(selectedNampan.value));
|
||||||
|
console.log("All nampan:", nampanList.value);
|
||||||
|
console.log("Selected nampan:", nampan);
|
||||||
return nampan ? nampan.nama : 'Brankas';
|
return nampan ? nampan.nama : 'Brankas';
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -118,6 +115,14 @@ const loadNampanList = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.get('/api/nampan');
|
const response = await axios.get('/api/nampan');
|
||||||
nampanList.value = response.data;
|
nampanList.value = response.data;
|
||||||
|
positionListOptions.value = [
|
||||||
|
{ value: '', label: 'Brankas', selected: !selectedNampan.value },
|
||||||
|
...nampanList.value.map(n => ({
|
||||||
|
value: n.id,
|
||||||
|
label: `${n.nama} (${n.items_count} items)`,
|
||||||
|
selected: n.id === selectedNampan.value
|
||||||
|
}))
|
||||||
|
];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading nampan list:', error);
|
console.error('Error loading nampan list:', error);
|
||||||
}
|
}
|
||||||
@ -140,11 +145,9 @@ const createItem = async () => {
|
|||||||
const response = await axios.post('/api/item', payload);
|
const response = await axios.post('/api/item', payload);
|
||||||
|
|
||||||
success.value = true;
|
success.value = true;
|
||||||
emit('item-created', {
|
createdItem.value = response.data.data
|
||||||
item: response.data,
|
console.log('Item created:', createdItem);
|
||||||
product: props.product,
|
|
||||||
nampan: selectedNampanName.value
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating item:', error);
|
console.error('Error creating item:', error);
|
||||||
alert('Gagal membuat item: ' + (error.response?.data?.message || error.message));
|
alert('Gagal membuat item: ' + (error.response?.data?.message || error.message));
|
||||||
@ -154,15 +157,12 @@ const createItem = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const addNewItem = () => {
|
const addNewItem = () => {
|
||||||
// Reset state untuk item baru
|
|
||||||
success.value = false;
|
success.value = false;
|
||||||
selectedNampan.value = '';
|
selectedNampan.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
// Emit event untuk membuat item baru
|
const printItem = () => {
|
||||||
emit('item-created', {
|
alert('Wak waw');
|
||||||
newItem: true,
|
|
||||||
product: props.product
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
|
@ -5,9 +5,6 @@
|
|||||||
:isOpen="openItemModal"
|
:isOpen="openItemModal"
|
||||||
:product="createdProduct"
|
:product="createdProduct"
|
||||||
@close="closeItemModal"
|
@close="closeItemModal"
|
||||||
@finish="goToProductList"
|
|
||||||
@print="printItem"
|
|
||||||
@item-created="handleItemCreated"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
@ -161,7 +158,6 @@ const fileInput = ref(null);
|
|||||||
// TODO: Logika autentikasi user
|
// TODO: Logika autentikasi user
|
||||||
const userId = ref(1);
|
const userId = ref(1);
|
||||||
|
|
||||||
// Modal item variables - Simplified karena logic sudah dipindah ke component
|
|
||||||
const openItemModal = ref(false);
|
const openItemModal = ref(false);
|
||||||
const createdProduct = ref(null);
|
const createdProduct = ref(null);
|
||||||
|
|
||||||
@ -196,7 +192,6 @@ const loadExistingPhotos = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simplified modal handlers
|
|
||||||
const openCreateItemModal = (product) => {
|
const openCreateItemModal = (product) => {
|
||||||
createdProduct.value = product;
|
createdProduct.value = product;
|
||||||
openItemModal.value = true;
|
openItemModal.value = true;
|
||||||
@ -209,23 +204,6 @@ const closeItemModal = () => {
|
|||||||
router.replace('/produk');
|
router.replace('/produk');
|
||||||
};
|
};
|
||||||
|
|
||||||
const goToProductList = () => {
|
|
||||||
closeItemModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
const printItem = () => {
|
|
||||||
alert('Wak waw');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle item creation events from modal
|
|
||||||
const handleItemCreated = (data) => {
|
|
||||||
if (data.newItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Item created:', data);
|
|
||||||
};
|
|
||||||
|
|
||||||
const triggerFileInput = () => {
|
const triggerFileInput = () => {
|
||||||
if (!uploadLoading.value && uploadedImages.value.length < 6) {
|
if (!uploadLoading.value && uploadedImages.value.length < 6) {
|
||||||
fileInput.value?.click();
|
fileInput.value?.click();
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<mainLayout>
|
<mainLayout>
|
||||||
|
<!-- Modal Buat Item - Sekarang menggunakan komponen terpisah -->
|
||||||
|
<CreateItemModal
|
||||||
|
:isOpen="creatingItem"
|
||||||
|
:product="detail"
|
||||||
|
@close="closeItemModal"
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<!-- Judul -->
|
<!-- Judul -->
|
||||||
<p class="font-serif italic text-[25px] text-D">PRODUK</p>
|
<p class="font-serif italic text-[25px] text-D">PRODUK</p>
|
||||||
@ -41,7 +48,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Overlay Detail Produk -->
|
<!-- Overlay Detail Produk -->
|
||||||
<!-- Overlay Detail Produk -->
|
|
||||||
<div
|
<div
|
||||||
v-if="showOverlay"
|
v-if="showOverlay"
|
||||||
class="fixed inset-0 bg-black/30 flex justify-center items-center z-50"
|
class="fixed inset-0 bg-black/30 flex justify-center items-center z-50"
|
||||||
@ -63,7 +69,7 @@
|
|||||||
|
|
||||||
<!-- Stok (pcs) pojok kiri atas -->
|
<!-- Stok (pcs) pojok kiri atas -->
|
||||||
<div class="absolute top-1 left-1 bg-black/60 text-white text-xs px-2 py-1 rounded">
|
<div class="absolute top-1 left-1 bg-black/60 text-white text-xs px-2 py-1 rounded">
|
||||||
{{ detail.item_count }} pcs
|
{{ detail.items_count }} pcs
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Nama Produk di bawah -->
|
<!-- Nama Produk di bawah -->
|
||||||
@ -109,7 +115,7 @@
|
|||||||
<button class="bg-yellow-400 text-black px-4 py-2 rounded font-bold">
|
<button class="bg-yellow-400 text-black px-4 py-2 rounded font-bold">
|
||||||
Ubah
|
Ubah
|
||||||
</button>
|
</button>
|
||||||
<button class="bg-green-400 text-black px-4 py-2 rounded font-bold">
|
<button @click="openItemModal" class="bg-green-400 text-black px-4 py-2 rounded font-bold">
|
||||||
Tambah
|
Tambah
|
||||||
</button>
|
</button>
|
||||||
<button class="bg-red-500 text-white px-4 py-2 rounded font-bold">
|
<button class="bg-red-500 text-white px-4 py-2 rounded font-bold">
|
||||||
@ -128,10 +134,21 @@ import axios from "axios";
|
|||||||
import mainLayout from "../layouts/mainLayout.vue";
|
import mainLayout from "../layouts/mainLayout.vue";
|
||||||
import ProductCard from "../components/ProductCard.vue";
|
import ProductCard from "../components/ProductCard.vue";
|
||||||
import searchbar from "../components/searchbar.vue";
|
import searchbar from "../components/searchbar.vue";
|
||||||
|
import CreateItemModal from "../components/CreateItemModal.vue";
|
||||||
|
|
||||||
const products = ref([]);
|
const products = ref([]);
|
||||||
const searchQuery = ref("");
|
const searchQuery = ref("");
|
||||||
const selectedCategory = ref("semua");
|
const selectedCategory = ref("semua");
|
||||||
|
const creatingItem = ref(false);
|
||||||
|
|
||||||
|
const openItemModal = () => {
|
||||||
|
console.log("open item modal", detail.value);
|
||||||
|
|
||||||
|
creatingItem.value = true;
|
||||||
|
};
|
||||||
|
const closeItemModal = () => {
|
||||||
|
creatingItem.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
// overlay state
|
// overlay state
|
||||||
const showOverlay = ref(false);
|
const showOverlay = ref(false);
|
||||||
@ -171,20 +188,14 @@ const filteredProducts = computed(() => {
|
|||||||
|
|
||||||
// buka overlay
|
// buka overlay
|
||||||
async function openOverlay(id) {
|
async function openOverlay(id) {
|
||||||
try {
|
detail.value = products.value.find(p => p.id === id) ;
|
||||||
const res = await axios.get(`/api/produk/${id}`);
|
currentFotoIndex.value = 0;
|
||||||
detail.value = res.data;
|
showOverlay.value = true;
|
||||||
currentFotoIndex.value = 0; // reset ke foto pertama
|
|
||||||
showOverlay.value = true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Gagal fetch detail produk:", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tutup overlay
|
// tutup overlay
|
||||||
function closeOverlay() {
|
function closeOverlay() {
|
||||||
showOverlay.value = false;
|
showOverlay.value = false;
|
||||||
detail.value = {};
|
|
||||||
currentFotoIndex.value = 0;
|
currentFotoIndex.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user