Merge branch 'production' of https://git.abbauf.com/Magang-2025/Kasir into production
This commit is contained in:
commit
f4e0392331
@ -107,19 +107,37 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tombol -->
|
<!-- Tombol -->
|
||||||
<div class="flex justify-end gap-2">
|
<!-- Tombol -->
|
||||||
<button @click="closePopup" class="px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-50 transition">
|
<div class="flex justify-end gap-2">
|
||||||
Batal
|
<button @click="closePopup" class="px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-50 transition">
|
||||||
</button>
|
Batal
|
||||||
<button @click="saveMove" :disabled="!selectedTrayId || isMoving"
|
</button>
|
||||||
class="px-4 py-2 rounded text-D transition flex items-center"
|
|
||||||
:class="(selectedTrayId && !isMoving) ? 'bg-C hover:bg-C/80' : 'bg-gray-400 cursor-not-allowed'">
|
<button @click="showDeleteConfirm = true"
|
||||||
<div v-if="isMoving" class="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
class="px-4 py-2 rounded bg-red-500 text-white hover:bg-red-600 transition flex items-center">
|
||||||
{{ isMoving ? 'Memindahkan...' : 'Pindahkan' }}
|
<i class="fas fa-trash mr-2"></i>Hapus
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
|
<button @click="saveMove" :disabled="!selectedTrayId || isMoving"
|
||||||
|
class="px-4 py-2 rounded text-D transition flex items-center"
|
||||||
|
:class="(selectedTrayId && !isMoving) ? 'bg-C hover:bg-C/80' : 'bg-gray-400 cursor-not-allowed'">
|
||||||
|
<div v-if="isMoving" class="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||||
|
{{ isMoving ? 'Memindahkan...' : 'Pindahkan' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Modal Konfirmasi Hapus -->
|
||||||
|
<ConfirmDeleteModal
|
||||||
|
:isOpen="showDeleteConfirm"
|
||||||
|
title="Konfirmasi Hapus Item"
|
||||||
|
message="Apakah kamu yakin ingin menghapus item ini?"
|
||||||
|
confirmText="Ya, Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
@confirm="confirmDelete"
|
||||||
|
@cancel="cancelDelete"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Confirm Modal untuk aksi berbahaya (jika diperlukan di masa depan) -->
|
<!-- Confirm Modal untuk aksi berbahaya (jika diperlukan di masa depan) -->
|
||||||
<div v-if="isConfirmModalVisible" class="fixed inset-0 bg-black/75 flex items-center justify-center p-4 z-50 backdrop-blur-sm">
|
<div v-if="isConfirmModalVisible" class="fixed inset-0 bg-black/75 flex items-center justify-center p-4 z-50 backdrop-blur-sm">
|
||||||
@ -151,6 +169,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from "vue";
|
import { ref, computed, onMounted } from "vue";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import ConfirmDeleteModal from './ConfirmDeleteModal.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
search: {
|
search: {
|
||||||
@ -173,6 +192,8 @@ const selectedTrayId = ref("");
|
|||||||
const errorMove = ref("");
|
const errorMove = ref("");
|
||||||
const isMoving = ref(false);
|
const isMoving = ref(false);
|
||||||
|
|
||||||
|
const showDeleteConfirm = ref(false);
|
||||||
|
|
||||||
// State modal konfirmasi
|
// State modal konfirmasi
|
||||||
const isConfirmModalVisible = ref(false);
|
const isConfirmModalVisible = ref(false);
|
||||||
const confirmModalTitle = ref("");
|
const confirmModalTitle = ref("");
|
||||||
@ -221,6 +242,44 @@ const closePopup = () => {
|
|||||||
isMoving.value = false;
|
isMoving.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const confirmDelete = async () => {
|
||||||
|
if (!selectedItem.value) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Panggil API hapus item
|
||||||
|
await axios.delete(`/api/item/${selectedItem.value.id}`, {
|
||||||
|
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tampilkan alert sukses
|
||||||
|
alert.value = { success: `Item ${selectedItem.value.kode_item} berhasil dihapus.` };
|
||||||
|
|
||||||
|
// Refresh data
|
||||||
|
await refreshData();
|
||||||
|
|
||||||
|
// Tutup modal & popup
|
||||||
|
showDeleteConfirm.value = false;
|
||||||
|
closePopup();
|
||||||
|
|
||||||
|
// Auto hide alert
|
||||||
|
clearTimeout(timer.value);
|
||||||
|
timer.value = setTimeout(() => { alert.value = null; }, 3000);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Gagal menghapus item:", err.response?.data || err);
|
||||||
|
alert.value = { error: err.response?.data?.message || "Gagal menghapus item. Silakan coba lagi." };
|
||||||
|
|
||||||
|
// Auto hide alert error
|
||||||
|
clearTimeout(timer.value);
|
||||||
|
timer.value = setTimeout(() => { alert.value = null; }, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const cancelDelete = () => {
|
||||||
|
showDeleteConfirm.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
const saveMove = async () => {
|
const saveMove = async () => {
|
||||||
if (!selectedTrayId.value || !selectedItem.value || isMoving.value) return;
|
if (!selectedTrayId.value || !selectedItem.value || isMoving.value) return;
|
||||||
|
|
||||||
|
|||||||
@ -49,33 +49,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Isi Card (Max tinggi 3 item + scroll kalau lebih) -->
|
<!-- Isi Card (Max tinggi 3 item + scroll kalau lebih) -->
|
||||||
<div
|
<div v-if="tray.items && tray.items.length" class="space-y-2 flex-1 overflow-y-auto max-h-[168px] pr-1">
|
||||||
v-if="tray.items && tray.items.length"
|
<div v-for="item in tray.items" :key="item.id"
|
||||||
class="space-y-2 flex-1 overflow-y-auto max-h-[168px] pr-1"
|
class="flex justify-between items-center border border-C rounded-lg p-2 cursor-pointer hover:bg-gray-50"
|
||||||
>
|
@click="openMovePopup(item)">
|
||||||
<div
|
<div class="flex items-center gap-3">
|
||||||
v-for="item in tray.items"
|
<img v-if="item.produk.foto && item.produk.foto.length > 0" :src="item.produk.foto[0].url"
|
||||||
:key="item.id"
|
alt="foto produk" class="size-12 object-cover rounded" />
|
||||||
class="flex justify-between items-center border border-C rounded-lg p-2 cursor-pointer hover:bg-gray-50"
|
<div class="text-D">
|
||||||
@click="openMovePopup(item)"
|
<p class="text-sm">{{ item.produk.nama }}</p>
|
||||||
>
|
<p class="text-sm font-medium">{{ item.kode_item }}</p>
|
||||||
<div class="flex items-center gap-3">
|
</div>
|
||||||
<img
|
</div>
|
||||||
v-if="item.produk?.foto && item.produk?.foto.length > 0"
|
<div class="flex items-center gap-2">
|
||||||
:src="item.produk?.foto[0].url"
|
<span class="font-medium">{{ item.produk.berat }}g</span>
|
||||||
alt="foto produk"
|
</div>
|
||||||
class="size-12 object-cover rounded"
|
</div>
|
||||||
/>
|
</div>
|
||||||
<div class="text-D">
|
|
||||||
<p class="text-sm">{{ item.produk?.nama }}</p>
|
|
||||||
<p class="text-sm font-medium">{{ item.kode_item }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<span class="font-medium">{{ item.produk?.berat }}g</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Kalau kosong -->
|
<!-- Kalau kosong -->
|
||||||
<div v-else class="text-gray-400 text-center py-4 flex-1">
|
<div v-else class="text-gray-400 text-center py-4 flex-1">
|
||||||
@ -107,7 +97,7 @@
|
|||||||
{{ selectedItem.kode_item }}
|
{{ selectedItem.kode_item }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center text-gray-700 font-medium mb-3">
|
<div class="text-center text-gray-700 font-medium mb-3">
|
||||||
{{ selectedItem.produk?.nama }}
|
{{ selectedItem.produk.nama }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-center mb-4">
|
<div class="flex justify-center mb-4">
|
||||||
@ -128,9 +118,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end gap-2">
|
<div class="flex justify-end gap-2">
|
||||||
|
|
||||||
<button @click="closePopup" class="px-4 py-2 rounded bg-gray-400 hover:bg-gray-500 text-white transition">
|
<button @click="closePopup" class="px-4 py-2 rounded bg-gray-400 hover:bg-gray-500 text-white transition">
|
||||||
{{ isAdmin ? 'Batal' : 'Tutup' }}
|
{{ isAdmin ? 'Batal' : 'Tutup' }}
|
||||||
</button>
|
</button>
|
||||||
|
<button @click="showDeleteConfirm = true"
|
||||||
|
class="px-4 py-2 rounded bg-red-500 text-white hover:bg-red-600 transition flex items-center">
|
||||||
|
<i class="fas fa-trash mr-2"></i>Hapus
|
||||||
|
</button>
|
||||||
<button v-if="isAdmin" @click="saveMove" :disabled="!selectedTrayId" class="px-4 py-2 rounded transition"
|
<button v-if="isAdmin" @click="saveMove" :disabled="!selectedTrayId" class="px-4 py-2 rounded transition"
|
||||||
:class="selectedTrayId ? 'bg-C hover:bg-C/80 text-D' : 'bg-gray-400 cursor-not-allowed'">
|
:class="selectedTrayId ? 'bg-C hover:bg-C/80 text-D' : 'bg-gray-400 cursor-not-allowed'">
|
||||||
Simpan
|
Simpan
|
||||||
@ -138,12 +133,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal Konfirmasi Hapus -->
|
||||||
|
<ConfirmDeleteModal
|
||||||
|
:isOpen="showDeleteConfirm"
|
||||||
|
title="Konfirmasi Hapus Item"
|
||||||
|
message="Apakah kamu yakin ingin menghapus item ini?"
|
||||||
|
confirmText="Ya, Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
@confirm="confirmDelete"
|
||||||
|
@cancel="cancelDelete"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, computed } from "vue";
|
import { ref, onMounted, computed } from "vue";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import InputSelect from "./InputSelect.vue";
|
import InputSelect from "./InputSelect.vue";
|
||||||
|
import ConfirmDeleteModal from './ConfirmDeleteModal.vue';
|
||||||
|
|
||||||
const isAdmin = localStorage.getItem("role") === "owner";
|
const isAdmin = localStorage.getItem("role") === "owner";
|
||||||
|
|
||||||
@ -212,6 +219,47 @@ const printQR = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showDeleteConfirm = ref(false);
|
||||||
|
|
||||||
|
const confirmDelete = async () => {
|
||||||
|
if (!selectedItem.value) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Panggil API hapus item
|
||||||
|
await axios.delete(`/api/item/${selectedItem.value.id}`, {
|
||||||
|
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tampilkan alert sukses
|
||||||
|
alert.value = { success: `Item ${selectedItem.value.kode_item} berhasil dihapus.` };
|
||||||
|
|
||||||
|
// Refresh data
|
||||||
|
await refreshData();
|
||||||
|
|
||||||
|
// Tutup modal & popup
|
||||||
|
showDeleteConfirm.value = false;
|
||||||
|
closePopup();
|
||||||
|
|
||||||
|
// Auto hide alert
|
||||||
|
clearTimeout(timer.value);
|
||||||
|
timer.value = setTimeout(() => { alert.value = null; }, 3000);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Gagal menghapus item:", err.response?.data || err);
|
||||||
|
alert.value = { error: err.response?.data?.message || "Gagal menghapus item. Silakan coba lagi." };
|
||||||
|
|
||||||
|
// Auto hide alert error
|
||||||
|
clearTimeout(timer.value);
|
||||||
|
timer.value = setTimeout(() => { alert.value = null; }, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const cancelDelete = () => {
|
||||||
|
showDeleteConfirm.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
// --- Fungsi Pop-up ---
|
// --- Fungsi Pop-up ---
|
||||||
const openMovePopup = (item) => {
|
const openMovePopup = (item) => {
|
||||||
selectedItem.value = item;
|
selectedItem.value = item;
|
||||||
@ -248,7 +296,7 @@ const saveMove = async () => {
|
|||||||
// Hitung total berat
|
// Hitung total berat
|
||||||
const totalWeight = (tray) => {
|
const totalWeight = (tray) => {
|
||||||
if (!tray.items) return 0;
|
if (!tray.items) return 0;
|
||||||
const total = tray.items.reduce((sum, item) => sum + (item.produk?.berat || 0), 0);
|
const total = tray.items.reduce((sum, item) => sum + (item.produk.berat || 0), 0);
|
||||||
return total.toFixed(2);
|
return total.toFixed(2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user