feat: consulta pública de pedidos por código

This commit is contained in:
2026-08-09 23:48:55 -05:00
parent 7a7939e309
commit 1af4d2052d
24 changed files with 2639 additions and 33 deletions

View File

@@ -0,0 +1,79 @@
<template>
<v-container class="pa-4 pa-md-6" fluid>
<v-sheet class="rounded-lg pa-4 pa-md-6 mb-4">
<h1 class="text-h5 font-weight-bold">Consultar mi pedido</h1>
<p class="text-body-2 text-medium-emphasis mb-4">
Ingresa el código de tu pedido o abre el link que recibiste para revisar su estado.
</p>
<v-form @submit.prevent="onConsult">
<v-row align="center">
<v-col cols="12" md="6" sm="8">
<v-text-field
v-model="inputCode"
clearable
density="comfortable"
hide-details
label="Código del pedido"
variant="outlined"
/>
</v-col>
<v-col class="d-flex align-center" cols="12" md="6" sm="4">
<v-btn color="primary" prepend-icon="mdi-magnify-scan" type="submit">
Consultar
</v-btn>
</v-col>
</v-row>
</v-form>
</v-sheet>
<PublicOrderSummary :error="error" :loading="loading" :purchase="purchase" />
</v-container>
</template>
<script setup>
import { inject, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import PublicOrderSummary from '@/components/PublicOrderSummary.vue'
const route = useRoute()
const router = useRouter()
const api = inject('api')
const inputCode = ref(route.params.code || '')
const purchase = ref(null)
const loading = ref(false)
const error = ref('')
async function fetchOrder (code) {
loading.value = true
error.value = ''
purchase.value = null
try {
purchase.value = await api.getPublicOrderSummary(code)
} catch (e) {
error.value =
e?.response?.status === 404
? 'No se encontró un pedido con ese código.'
: 'Ocurrió un error al consultar el pedido. Inténtalo de nuevo.'
} finally {
loading.value = false
}
}
function onConsult () {
const code = inputCode.value.trim()
if (!code) return
router.push(`/pedido/${code}`)
}
watch(
() => route.params.code,
code => {
if (code) {
inputCode.value = code
fetchOrder(code)
}
},
{ immediate: true }
)
</script>