add: agregar campo de código de barras en formularios de creación y edición de productos
This commit is contained in:
parent
58a0e5b89e
commit
0fd2d06db4
@ -21,6 +21,7 @@ const categories = ref([]);
|
||||
const form = useForm({
|
||||
name: '',
|
||||
sku: '',
|
||||
barcode: '',
|
||||
category_id: '',
|
||||
stock: 0,
|
||||
cost: 0,
|
||||
@ -121,8 +122,22 @@ watch(() => props.show, (newValue) => {
|
||||
<FormError :message="form.errors?.sku" />
|
||||
</div>
|
||||
|
||||
<!-- Categoría -->
|
||||
<!-- Código de Barras -->
|
||||
<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">
|
||||
CATEGORÍA
|
||||
</label>
|
||||
|
||||
@ -22,6 +22,7 @@ const categories = ref([]);
|
||||
const form = useForm({
|
||||
name: '',
|
||||
sku: '',
|
||||
barcode: '',
|
||||
category_id: '',
|
||||
stock: 0,
|
||||
cost: 0,
|
||||
@ -70,6 +71,7 @@ watch(() => props.product, (newProduct) => {
|
||||
if (newProduct) {
|
||||
form.name = newProduct.name || '';
|
||||
form.sku = newProduct.sku || '';
|
||||
form.barcode = newProduct.barcode || '';
|
||||
form.category_id = newProduct.category_id || '';
|
||||
form.stock = newProduct.stock || 0;
|
||||
form.cost = parseFloat(newProduct.price?.cost || 0);
|
||||
@ -134,8 +136,22 @@ watch(() => props.show, (newValue) => {
|
||||
<FormError :message="form.errors?.sku" />
|
||||
</div>
|
||||
|
||||
<!-- Categoría -->
|
||||
<!-- Código de Barras -->
|
||||
<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">
|
||||
CATEGORÍA
|
||||
</label>
|
||||
|
||||
@ -47,6 +47,7 @@ const filteredProducts = computed(() => {
|
||||
return (
|
||||
product.name?.toLowerCase().includes(query) ||
|
||||
product.sku?.toLowerCase().includes(query) ||
|
||||
product.barcode?.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) => {
|
||||
processingPayment.value = true;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user