diff --git a/resources/js/components/CreateItemModal.vue b/resources/js/components/CreateItemModal.vue index 1ab7592..f2b2983 100644 --- a/resources/js/components/CreateItemModal.vue +++ b/resources/js/components/CreateItemModal.vue @@ -2,42 +2,26 @@

Item {{ product?.nama }}

- +
-

Produk "{{ product?.nama }}" berhasil dibuat!

- -
- - -
+ +
- - @@ -48,33 +32,34 @@
- + + + +
- +

Item Berhasil Dibuat!

-

- Item dari produk "{{ product?.nama }}" telah ditambahkan ke {{ selectedNampanName }}. +

+ Item dari produk "{{ product?.nama }}" telah ditambahkan ke {{ + selectedNampanName }}. +

+

+ ID Item: {{ createdItem.id }}

- - -
@@ -87,6 +72,7 @@ import { ref, computed, watch } from 'vue'; import axios from 'axios'; import Modal from './Modal.vue'; +import InputSelect from './InputSelect.vue'; // Props 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 nampanList = ref([]); +const positionListOptions = ref([ + { value: '', label: 'Brankas', selected: true }, +]) const success = ref(false); const loading = ref(false); +const createdItem = ref(null); +// Computed const selectedNampanName = computed(() => { 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'; }); @@ -118,6 +115,14 @@ const loadNampanList = async () => { try { const response = await axios.get('/api/nampan'); 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) { console.error('Error loading nampan list:', error); } @@ -125,26 +130,24 @@ const loadNampanList = async () => { const createItem = async () => { if (!props.product) return; - + loading.value = true; - + try { const payload = { id_produk: props.product.id }; - + if (selectedNampan.value) { payload.id_nampan = selectedNampan.value; } - + const response = await axios.post('/api/item', payload); - + success.value = true; - emit('item-created', { - item: response.data, - product: props.product, - nampan: selectedNampanName.value - }); + createdItem.value = response.data.data + console.log('Item created:', createdItem); + } catch (error) { console.error('Error creating item:', error); alert('Gagal membuat item: ' + (error.response?.data?.message || error.message)); @@ -154,15 +157,12 @@ const createItem = async () => { }; const addNewItem = () => { - // Reset state untuk item baru success.value = false; selectedNampan.value = ''; - - // Emit event untuk membuat item baru - emit('item-created', { - newItem: true, - product: props.product - }); +}; + +const printItem = () => { + alert('Wak waw'); }; const handleClose = () => { @@ -170,7 +170,7 @@ const handleClose = () => { selectedNampan.value = ''; success.value = false; loading.value = false; - + emit('close'); }; @@ -180,7 +180,7 @@ watch(() => props.isOpen, (newValue) => { selectedNampan.value = ''; success.value = false; loading.value = false; - + loadNampanList(); } }); diff --git a/resources/js/pages/InputProduk.vue b/resources/js/pages/InputProduk.vue index c9164b8..5f4a1ae 100644 --- a/resources/js/pages/InputProduk.vue +++ b/resources/js/pages/InputProduk.vue @@ -5,9 +5,6 @@ :isOpen="openItemModal" :product="createdProduct" @close="closeItemModal" - @finish="goToProductList" - @print="printItem" - @item-created="handleItemCreated" />
@@ -161,7 +158,6 @@ const fileInput = ref(null); // TODO: Logika autentikasi user const userId = ref(1); -// Modal item variables - Simplified karena logic sudah dipindah ke component const openItemModal = ref(false); const createdProduct = ref(null); @@ -196,7 +192,6 @@ const loadExistingPhotos = async () => { } }; -// Simplified modal handlers const openCreateItemModal = (product) => { createdProduct.value = product; openItemModal.value = true; @@ -209,23 +204,6 @@ const closeItemModal = () => { 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 = () => { if (!uploadLoading.value && uploadedImages.value.length < 6) { fileInput.value?.click(); diff --git a/resources/js/pages/Produk.vue b/resources/js/pages/Produk.vue index 7104636..d9fa8e9 100644 --- a/resources/js/pages/Produk.vue +++ b/resources/js/pages/Produk.vue @@ -1,5 +1,12 @@