add: agregar campo de código de barras en formularios de creación y edición de productos

This commit is contained in:
Juan Felipe Zapata Moreno 2026-01-05 20:31:01 -06:00
parent 58a0e5b89e
commit 0fd2d06db4
3 changed files with 74 additions and 2 deletions

View File

@ -21,6 +21,7 @@ const categories = ref([]);
const form = useForm({ const form = useForm({
name: '', name: '',
sku: '', sku: '',
barcode: '',
category_id: '', category_id: '',
stock: 0, stock: 0,
cost: 0, cost: 0,
@ -121,8 +122,22 @@ watch(() => props.show, (newValue) => {
<FormError :message="form.errors?.sku" /> <FormError :message="form.errors?.sku" />
</div> </div>
<!-- Categoría --> <!-- Código de Barras -->
<div> <div>
<label class="block text-xs font-semibold text-gray-700 dark:text-gray-300 uppercase mb-1.5">
CÓDIGO DE BARRAS
</label>
<FormInput
v-model="form.barcode"
type="text"
placeholder="1234567890123"
maxlength="100"
/>
<FormError :message="form.errors?.barcode" />
</div>
<!-- Categoría -->
<div class="col-span-2">
<label class="block text-xs font-semibold text-gray-700 dark:text-gray-300 uppercase mb-1.5"> <label class="block text-xs font-semibold text-gray-700 dark:text-gray-300 uppercase mb-1.5">
CATEGORÍA CATEGORÍA
</label> </label>

View File

@ -22,6 +22,7 @@ const categories = ref([]);
const form = useForm({ const form = useForm({
name: '', name: '',
sku: '', sku: '',
barcode: '',
category_id: '', category_id: '',
stock: 0, stock: 0,
cost: 0, cost: 0,
@ -70,6 +71,7 @@ watch(() => props.product, (newProduct) => {
if (newProduct) { if (newProduct) {
form.name = newProduct.name || ''; form.name = newProduct.name || '';
form.sku = newProduct.sku || ''; form.sku = newProduct.sku || '';
form.barcode = newProduct.barcode || '';
form.category_id = newProduct.category_id || ''; form.category_id = newProduct.category_id || '';
form.stock = newProduct.stock || 0; form.stock = newProduct.stock || 0;
form.cost = parseFloat(newProduct.price?.cost || 0); form.cost = parseFloat(newProduct.price?.cost || 0);
@ -134,8 +136,22 @@ watch(() => props.show, (newValue) => {
<FormError :message="form.errors?.sku" /> <FormError :message="form.errors?.sku" />
</div> </div>
<!-- Categoría --> <!-- Código de Barras -->
<div> <div>
<label class="block text-xs font-semibold text-gray-700 dark:text-gray-300 uppercase mb-1.5">
CÓDIGO DE BARRAS
</label>
<FormInput
v-model="form.barcode"
type="text"
placeholder="1234567890123"
maxlength="100"
/>
<FormError :message="form.errors?.barcode" />
</div>
<!-- Categoría -->
<div class="col-span-2">
<label class="block text-xs font-semibold text-gray-700 dark:text-gray-300 uppercase mb-1.5"> <label class="block text-xs font-semibold text-gray-700 dark:text-gray-300 uppercase mb-1.5">
CATEGORÍA CATEGORÍA
</label> </label>

View File

@ -47,6 +47,7 @@ const filteredProducts = computed(() => {
return ( return (
product.name?.toLowerCase().includes(query) || product.name?.toLowerCase().includes(query) ||
product.sku?.toLowerCase().includes(query) || product.sku?.toLowerCase().includes(query) ||
product.barcode?.toLowerCase().includes(query) ||
product.description?.toLowerCase().includes(query) product.description?.toLowerCase().includes(query)
); );
}); });
@ -90,6 +91,46 @@ const toggleScanMode = () => {
} }
}; };
const handleCodeDetected = async (barcode) => {
if (!barcode || barcode.trim() === '') {
window.Notify.error('Código de barras inválido');
return;
}
try {
window.Notify.info('Buscando producto...');
// Buscar producto por código de barras usando el API
const response = await fetch(apiURL(`inventario?q=${encodeURIComponent(barcode)}`), {
headers: {
'Authorization': `Bearer ${sessionStorage.token}`,
'Accept': 'application/json'
}
});
const result = await response.json();
// Verificar si se encontró el producto
if (result.data && result.data.products && result.data.products.data && result.data.products.data.length > 0) {
const product = result.data.products.data[0];
// Verificar si el producto tiene stock
if (product.stock <= 0) {
window.Notify.error(`${product.name} no tiene stock disponible`);
return;
}
// Agregar producto al carrito
addToCart(product);
} else {
window.Notify.error('Producto no encontrado');
}
} catch (error) {
console.error('Error buscando producto:', error);
window.Notify.error('Error al buscar el producto');
}
};
const handleConfirmSale = async (paymentData) => { const handleConfirmSale = async (paymentData) => {
processingPayment.value = true; processingPayment.value = true;