update stok item di halaman produk tanpa reload page
This commit is contained in:
parent
6246800b0c
commit
8ed0ea26cf
@ -87,7 +87,7 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Emits
|
// Emits
|
||||||
const emit = defineEmits(['close']);
|
const emit = defineEmits(['close','itemAdded']);
|
||||||
|
|
||||||
// State
|
// State
|
||||||
const selectedNampan = ref('');
|
const selectedNampan = ref('');
|
||||||
@ -147,15 +147,17 @@ const createItem = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post('/api/item', payload, {
|
const response = await axios.post('/api/item', payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
});;
|
});
|
||||||
|
|
||||||
success.value = true;
|
success.value = true;
|
||||||
createdItem.value = response.data.data
|
createdItem.value = response.data.data;
|
||||||
console.log('Item created:', createdItem);
|
console.log('Item created:', createdItem);
|
||||||
|
|
||||||
|
emit('itemAdded'); // 🔔 penting
|
||||||
|
|
||||||
loadNampanList();
|
loadNampanList();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating item:', error);
|
console.error('Error creating item:', error);
|
||||||
@ -165,6 +167,7 @@ const createItem = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const addNewItem = () => {
|
const addNewItem = () => {
|
||||||
success.value = false;
|
success.value = false;
|
||||||
selectedNampan.value = '';
|
selectedNampan.value = '';
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<mainLayout>
|
<mainLayout>
|
||||||
<!-- Modal Buat Item -->
|
<!-- Modal Buat Item -->
|
||||||
<CreateItemModal :isOpen="creatingItem" :product="detail" @close="closeItemModal" />
|
<CreateItemModal
|
||||||
|
:isOpen="creatingItem"
|
||||||
|
:product="detail"
|
||||||
|
@close="closeItemModal"
|
||||||
|
@itemAdded="handleItemAdded"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
<!-- Modal Konfirmasi Hapus Produk -->
|
<!-- Modal Konfirmasi Hapus Produk -->
|
||||||
<ConfirmDeleteModal :isOpen="deleting" @cancel="deleting = false" @confirm="deleteProduk" title="Hapus Produk"
|
<ConfirmDeleteModal :isOpen="deleting" @cancel="deleting = false" @confirm="deleteProduk" title="Hapus Produk"
|
||||||
@ -268,6 +274,15 @@ function formatNumber(num) {
|
|||||||
return new Intl.NumberFormat().format(num || 0);
|
return new Intl.NumberFormat().format(num || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleItemAdded() {
|
||||||
|
if (detail.value) {
|
||||||
|
detail.value.items_count++;
|
||||||
|
}
|
||||||
|
creatingItem.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Hapus produk
|
// Hapus produk
|
||||||
async function deleteProduk() {
|
async function deleteProduk() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user