[update] nambahin satuan berat,kadar

This commit is contained in:
dhilanradya 2025-09-12 16:04:02 +07:00
parent 4223cad92f
commit 286b270bd6

View File

@ -1,69 +1,51 @@
<template>
<div
v-if="isOpen"
class="text-D pt-serif-regular-italic fixed inset-0 bg-black/75 flex items-center justify-center z-[9999]"
>
<div
class="bg-white w-[1224px] h-[528px] rounded-md shadow-lg relative overflow-hidden"
>
<div v-if="isOpen"
class="text-D pt-serif-regular-italic fixed inset-0 bg-black/75 flex items-center justify-center z-[9999]">
<div class="bg-white w-[1224px] h-[528px] rounded-md shadow-lg relative overflow-hidden">
<div class="bg-D h-8 w-full"></div>
<div class="p-6 text-sm flex flex-col h-full relative">
<!-- Header -->
<div class="relative flex items-center justify-between pb-2 mb-2">
<!-- Sosmed -->
<div class="flex flex-col gap-4">
<p class="flex items-center gap-2">
<i class="fab fa-instagram text-red-500 text-xl"></i> tokomas_Jakartacitayam
<i class="fab fa-instagram text-D text-xl"></i> tokomas_Jakartacitayam
</p>
<p class="flex items-center gap-2">
<i class="fab fa-tiktok text-black text-xl"></i> tokomas_Jakartacitayam
<i class="fab fa-tiktok text-D text-xl"></i> tokomas_Jakartacitayam
</p>
<p class="flex items-center gap-2">
<i class="fab fa-whatsapp text-green-500 text-xl"></i> 08158851178
<i class="fab fa-whatsapp text-D text-xl"></i> 08158851178
</p>
</div>
<!-- Logo & tanggal (absolute di tengah) -->
<div class="absolute inset-x-0 top-0 flex flex-col items-center">
<img :src="logo" alt="Logo" class="h-15" />
<!-- ==== MODIFIKASI: Tanggal sekarang dinamis ==== -->
<p class="mt-1 text-center">{{ getCurrentDate() }}</p>
<!-- ==== END MODIFIKASI ==== -->
</div>
<!-- Data Pembeli -->
<div
class="grid grid-cols-[130px_1fr] gap-y-2 items-center relative z-10"
>
<div class="grid grid-cols-[130px_1fr] gap-y-2 items-center relative z-10">
<div class="text-right font-semibold pr-3">Nama Pembeli</div>
<!-- ==== MODIFIKASI: Input field sekarang v-model ==== -->
<inputField
v-model="namaPembeli"
class="h-7 px-2 text-sm rounded bg-blue-200 w-full"
/>
<!-- ==== END MODIFIKASI ==== -->
<inputField v-model="namaPembeli" class="h-7 px-2 text-sm rounded bg-blue-200 w-full" />
<div class="text-right font-semibold pr-3">Nomor Telepon</div>
<!-- ==== MODIFIKASI: Input field sekarang v-model ==== -->
<inputField
v-model="nomorTelepon"
class="h-7 px-2 text-sm rounded bg-blue-200 w-full"
/>
<!-- ==== END MODIFIKASI ==== -->
<inputField v-model="nomorTelepon" class="h-7 px-2 text-sm rounded bg-blue-200 w-full" />
<div class="text-right font-semibold pr-3">Alamat</div>
<!-- ==== MODIFIKASI: Input field sekarang v-model ==== -->
<inputField
v-model="alamat"
class="h-7 px-2 text-sm rounded bg-blue-200 w-full"
/>
<!-- ==== END MODIFIKASI ==== -->
<inputField v-model="alamat" class="h-7 px-2 text-sm rounded bg-blue-200 w-full" />
</div>
</div>
<!-- Nomor Transaksi -->
<!-- ==== MODIFIKASI: Kode transaksi dinamis ==== -->
<p class="mt-1 text-sm">{{ generateTransactionCode() }}</p>
<!-- ==== END MODIFIKASI ==== -->
<table class="w-full border-D mt-0 text-sm table-fixed">
<thead>
@ -82,22 +64,20 @@
<tr v-for="(item, index) in pesananMinimal" :key="index" class="text-center">
<td class="flex items-center gap-2 p-2 border-r border-D">
<template v-if="item.produk?.foto?.[0]?.url">
<img
:src="item.produk.foto[0].url"
class="w-12 h-12 object-cover"
/>
<img :src="item.produk.foto[0].url" class="w-12 h-12 object-cover" />
</template>
<template v-else>
<div class="w-12 h-12"></div>
</template>
{{ item.produk?.nama || '' }}
</td>
<td class="border-r border-D">{{ item.posisi || '' }}</td>
<td class="border-r border-D">{{ item.produk?.berat || '' }}</td>
<td class="border-r border-D">{{ item.produk?.kadar || '' }}</td>
<td class="border-r border-D">
<span v-if="item.produk?.berat">{{ item.produk.berat }}g</span>
</td>
<td class="border-r border-D">
<span v-if="item.produk?.kadar">{{ item.produk.kadar }}k</span>
</td>
<td class="border-r border-D">
<span v-if="item.harga_deal">Rp{{ item.harga_deal.toLocaleString() }}</span>
</td>
@ -111,15 +91,17 @@
</tbody>
<!-- BAGIAN BAWAH DIPINDAHKAN KE TFOOT -->
<tfoot>
<!-- Baris Ongkos + Total -->
<tr class="align-top border-t">
<td colspan="2" rowspan="2" class="p-2 text-left align-top">
<p class="font-semibold">PERHATIAN</p>
<ol class="list-decimal ml-4 text-xs space-y-1">
<li>Berat barang telah ditimbang dan disaksikan oleh pembeli.</li>
<li>Barang yang dikembalikan menurut harga pasaran dan <br> dipotong ongkos bikin, barang rusak lain harga.</li>
<li>Barang yang dikembalikan menurut harga pasaran dan <br> dipotong ongkos bikin,
barang rusak lain
harga.</li>
<li>Barang yang sudah dibeli berarti sudah diperiksa dan disetujui.</li>
<li>Surat ini harap dibawa pada saat menjual kembali.</li>
</ol>
@ -128,11 +110,8 @@
<td colspan="2" rowspan="2" class="p-2 text-center align-top">
<div class="flex flex-col items-center justify-center h-full">
<p><strong>Sales</strong></p>
<inputSelect
v-model="selectedSales"
:options="salesOptions"
class="mt-16 text-sm rounded bg-B cursor-pointer !w-[160px] text-center [option]:text-left"
/>
<inputSelect v-model="selectedSales" :options="salesOptions"
class="mt-16 text-sm rounded bg-B cursor-pointer !w-[160px] text-center [option]:text-left" />
</div>
</td>
@ -148,21 +127,19 @@
<div class="space-y-2">
<div class="flex items-center">
<p>Rp</p>
<inputField
v-model.number="ongkosBikin"
type="number"
class="h-7 px-2 text-sm rounded bg-blue-200 text-left w-full"
/>
<inputField v-model.number="ongkosBikin" type="number"
class="h-7 px-2 text-sm rounded bg-blue-200 text-left w-full" />
</div>
<div class="flex items-center">
<p>Rp</p>
<p class="px-3 py-1 text-left text-sm w-full">{{ grandTotal.toLocaleString() }}</p>
<p class="px-3 py-1 text-left text-sm w-full">{{ grandTotal.toLocaleString() }}
</p>
</div>
</div>
</td>
</tr>
<!-- Baris Tombol -->
<tr>
<td></td>
<td></td>
@ -179,10 +156,8 @@
</div>
<!-- Pesan bawah -->
<p
class="absolute bottom-0 left-0 text-xs bg-D text-white px-2 py-1 rounded-tr-md"
>
<p class="absolute bottom-0 left-0 text-xs bg-D text-white px-2 py-1 rounded-tr-md">
Terima kasih sudah berbelanja dengan kami
</p>
</div>
@ -194,11 +169,9 @@ import { ref, computed, onMounted } from 'vue'
import logo from '@/../images/logo.png'
import inputField from '@/components/inputField.vue'
import inputSelect from '@/components/inputSelect.vue'
// ==== TAMBAHAN: Import axios ====
import axios from 'axios'
// ==== END TAMBAHAN ====
// ==== MODIFIKASI: Props sekarang menerima pesanan dan total ====
import axios from 'axios'
const props = defineProps({
isOpen: {
type: Boolean,
@ -213,28 +186,21 @@ const props = defineProps({
default: 0
}
})
// ==== END MODIFIKASI ====
// ==== TAMBAHAN: Define emits ====
const emit = defineEmits(['close', 'confirm'])
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Reactive variables untuk form ====
const namaPembeli = ref('')
const nomorTelepon = ref('')
const alamat = ref('')
const ongkosBikin = ref(0)
const selectedSales = ref(null)
const salesOptions = ref([])
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Computed untuk grand total ====
const grandTotal = computed(() => {
return props.total + (ongkosBikin.value || 0)
})
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Fungsi untuk generate tanggal ====
const getCurrentDate = () => {
const days = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu']
const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
@ -247,17 +213,13 @@ const getCurrentDate = () => {
return `${dayName}/${day}-${month}-${year}`
}
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Fungsi untuk generate kode transaksi ====
const generateTransactionCode = () => {
const now = new Date()
const timestamp = now.getTime().toString().slice(-6)
return `TRS-${timestamp}`
}
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Fetch sales data ====
const fetchSales = async () => {
try {
const response = await axios.get('/api/sales', {
@ -271,7 +233,7 @@ const fetchSales = async () => {
label: sales.nama
}))
// Set default sales jika ada
if (salesOptions.value.length > 0) {
selectedSales.value = salesOptions.value[0].value
}
@ -279,11 +241,9 @@ const fetchSales = async () => {
console.error('Error fetching sales:', error)
}
}
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Handle simpan dengan validasi ====
const handleSimpan = () => {
// Validasi input wajib
if (!namaPembeli.value.trim()) {
alert('Nama pembeli harus diisi!')
return
@ -304,7 +264,7 @@ const handleSimpan = () => {
return
}
// Emit data ke parent
simpanTransaksi({
id_sales: selectedSales.value,
nama_pembeli: namaPembeli.value,
@ -316,7 +276,7 @@ const handleSimpan = () => {
})
}
// ==== TAMBAHAN: Fungsi untuk menyimpan transaksi ====
const simpanTransaksi = async (dataTransaksi) => {
console.log('Data transaksi yang akan disimpan:', dataTransaksi);
@ -327,7 +287,7 @@ const simpanTransaksi = async (dataTransaksi) => {
},
});
// Reset form setelah berhasil
props.pesanan.value = [];
props.isOpen = false;
@ -339,10 +299,7 @@ const simpanTransaksi = async (dataTransaksi) => {
alert('Error menyimpan transaksi: ' + (error.response?.data?.message || error.message));
}
};
// ==== END TAMBAHAN ====
// ==== END TAMBAHAN ====
// ==== TAMBAHAN: Fetch sales saat component mounted ====
onMounted(() => {
if (props.isOpen) {
fetchSales()
@ -350,20 +307,20 @@ onMounted(() => {
})
const pesananMinimal = computed(() => {
const arr = [...props.pesanan] // copy data asli
const arr = [...props.pesanan]
while (arr.length < 2) {
arr.push({ produk: {}, harga_deal: 0, posisi: '' }) // baris kosong
arr.push({ produk: {}, harga_deal: 0, posisi: '' })
}
return arr
})
// ==== END TAMBAHAN ====
</script>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=PT+Serif:ital,wght@0,400;0,700;1,400;1,700&display=swap');
.pt-serif-regular-italic {
font-family: "PT Serif", serif;
font-weight: 400;
}
</style>