add customer and providers
This commit is contained in:
454
app/pages/policies/[application_id].vue
Normal file
454
app/pages/policies/[application_id].vue
Normal file
@@ -0,0 +1,454 @@
|
||||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
const applicationId = route.params.application_id as string
|
||||
|
||||
const { data, error, pending, refresh } = usePolicy(`/car-policies/${applicationId}`)
|
||||
const policy = computed(() => data.value?.data)
|
||||
|
||||
// ── Accept plan ──────────────────────────────────────────────────────────────
|
||||
const isAcceptOpen = ref(false)
|
||||
const accepting = ref(false)
|
||||
const selectedQuote = ref<any>(null)
|
||||
const selectedPlan = ref<any>(null)
|
||||
const solicitationFields = ref<Record<string, string>>({})
|
||||
const toast = useToast()
|
||||
const { $policy } = useNuxtApp()
|
||||
|
||||
function openAccept(quote: any, plan: any) {
|
||||
selectedQuote.value = quote
|
||||
selectedPlan.value = plan
|
||||
solicitationFields.value = {}
|
||||
isAcceptOpen.value = true
|
||||
}
|
||||
|
||||
async function submitAccept() {
|
||||
accepting.value = true
|
||||
try {
|
||||
await $policy(`/car-policies/${applicationId}/accept`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
quote_id: selectedQuote.value.quote_id,
|
||||
plan_id: selectedPlan.value.plan_id,
|
||||
solicitation_fields: solicitationFields.value
|
||||
}
|
||||
})
|
||||
toast.add({ title: 'Plan accepted — solicitation in progress', color: 'green' })
|
||||
isAcceptOpen.value = false
|
||||
await refresh()
|
||||
} catch (e: any) {
|
||||
toast.add({ title: 'Failed to accept plan', description: e?.data?.error ?? e.message, color: 'red' })
|
||||
} finally {
|
||||
accepting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Solicitation PDF ─────────────────────────────────────────────────────────
|
||||
const solicitationUrl = ref<string | null>(null)
|
||||
const loadingPdf = ref(false)
|
||||
const pdfError = ref<string | null>(null)
|
||||
|
||||
async function loadSolicitationUrl() {
|
||||
if (!policy.value?.solicitation_id) return
|
||||
loadingPdf.value = true
|
||||
pdfError.value = null
|
||||
try {
|
||||
const res = await $policy(`/car-policies/${applicationId}/solicitation-url`) as any
|
||||
solicitationUrl.value = res.download_url
|
||||
} catch (e: any) {
|
||||
pdfError.value = e?.data?.error ?? 'Failed to load document'
|
||||
} finally {
|
||||
loadingPdf.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => policy.value?.solicitation_id, (id) => {
|
||||
if (id) loadSolicitationUrl()
|
||||
}, { immediate: true })
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
const quotes = computed(() => {
|
||||
if (!policy.value?.quotes) return []
|
||||
return Object.entries(policy.value.quotes).map(([provider_id, q]: [string, any]) => ({
|
||||
provider_id, ...q
|
||||
}))
|
||||
})
|
||||
|
||||
const allPlans = computed(() =>
|
||||
quotes.value.flatMap((q: any) =>
|
||||
(q.plans ?? []).map((p: any) => ({
|
||||
...p,
|
||||
provider_id: q.provider_id,
|
||||
valid_until: q.valid_until,
|
||||
quote_id: q.quote_id
|
||||
}))
|
||||
)
|
||||
)
|
||||
|
||||
const canAccept = computed(() => policy.value?.status === 'quotes_received')
|
||||
|
||||
const statusColor = (s: string) => ({
|
||||
quote_requested: 'yellow',
|
||||
quotes_received: 'blue',
|
||||
solicitation_sent: 'purple',
|
||||
active: 'green'
|
||||
}[s] ?? 'gray')
|
||||
|
||||
const statusLabel = (s: string) => ({
|
||||
quote_requested: 'Quote Requested',
|
||||
quotes_received: 'Quotes Received',
|
||||
solicitation_sent: 'Solicitation Sent',
|
||||
active: 'Active'
|
||||
}[s] ?? s)
|
||||
|
||||
const clientTypeLabel = (ct: string) => ct === 'juridico' ? 'Jurídico' : 'Natural'
|
||||
const clientTypeColor = (ct: string) => ct === 'juridico' ? 'purple' : 'blue'
|
||||
|
||||
const formatDate = (d: string) =>
|
||||
d ? new Date(d).toLocaleDateString('es-PA', { day: '2-digit', month: 'short', year: 'numeric' }) : '—'
|
||||
|
||||
const formatDateTime = (d: string) =>
|
||||
d ? new Date(d).toLocaleString('es-PA') : '—'
|
||||
|
||||
// ── Applicant display — handles both natural and juridico ────────────────────
|
||||
const applicantRows = computed(() => {
|
||||
const info = policy.value?.applicant_info ?? {}
|
||||
const ct = policy.value?.client_type
|
||||
|
||||
if (ct === 'juridico') {
|
||||
return [
|
||||
{ label: 'Company', value: info.company_name ?? info['company_name'] },
|
||||
{ label: 'RUC', value: info.ruc ?? info['ruc'] },
|
||||
{ label: 'Legal Rep', value: info.legal_rep_name ?? info['legal_rep_name'] },
|
||||
{ label: 'Rep Document', value: info.legal_rep_document ?? info['legal_rep_document'] }
|
||||
]
|
||||
}
|
||||
|
||||
return [
|
||||
{ label: 'Name', value: info.name ?? info['name'] },
|
||||
{ label: 'DOB', value: formatDate(info.date_of_birth ?? info['date_of_birth']) },
|
||||
{ label: 'Document', value: info.document_id ?? info['document_id'] }
|
||||
]
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-8 space-y-8 bg-gray-50 min-h-screen">
|
||||
<NuxtLink to="/policies">
|
||||
<UButton icon="i-heroicons-arrow-left" color="gray" variant="ghost">Back to Policies</UButton>
|
||||
</NuxtLink>
|
||||
|
||||
<UAlert v-if="error" color="red" variant="soft" title="Failed to load policy" :description="error.message" />
|
||||
|
||||
<div v-else-if="pending" class="space-y-4">
|
||||
<UCard v-for="n in 4" :key="n"><div class="h-32 animate-pulse bg-gray-200 rounded" /></UCard>
|
||||
</div>
|
||||
|
||||
<template v-else-if="policy">
|
||||
<!-- Header -->
|
||||
<div class="flex justify-between items-start">
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<UBadge :color="statusColor(policy.status)" variant="soft">
|
||||
{{ statusLabel(policy.status) }}
|
||||
</UBadge>
|
||||
<UBadge :color="clientTypeColor(policy.client_type)" variant="outline">
|
||||
{{ clientTypeLabel(policy.client_type) }}
|
||||
</UBadge>
|
||||
<UBadge color="gray" variant="outline">CAR</UBadge>
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-slate-900">{{ policy.applicant_display_name }}</h1>
|
||||
<p class="text-gray-500 text-sm font-mono">{{ policy.application_id }}</p>
|
||||
</div>
|
||||
<UButton icon="i-heroicons-arrow-path" color="gray" variant="soft" :loading="pending" @click="refresh()" />
|
||||
</div>
|
||||
|
||||
<!-- Info grid -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
|
||||
<!-- Applicant — dynamic rows based on client_type -->
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-user" class="w-4 h-4" />
|
||||
{{ policy.client_type === 'juridico' ? 'Legal Entity' : 'Applicant' }}
|
||||
<UBadge :color="clientTypeColor(policy.client_type)" variant="soft" size="xs">
|
||||
{{ clientTypeLabel(policy.client_type) }}
|
||||
</UBadge>
|
||||
</p>
|
||||
</template>
|
||||
<div class="space-y-2 text-sm">
|
||||
<div v-for="row in applicantRows" :key="row.label" class="flex justify-between">
|
||||
<span class="text-gray-500">{{ row.label }}</span>
|
||||
<span class="font-medium font-mono text-xs">{{ row.value ?? '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Vehicle -->
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-truck" class="w-4 h-4" /> Vehicle
|
||||
</p>
|
||||
</template>
|
||||
<div class="space-y-2 text-sm">
|
||||
<div class="flex justify-between"><span class="text-gray-500">Plate</span><span class="font-mono font-medium">{{ policy.plate }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Vehicle</span><span>{{ policy.year }} {{ policy.make }} {{ policy.model }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Value</span><span>${{ Number(policy.car_value).toLocaleString() }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Type</span><span class="capitalize">{{ policy.car_type }} / {{ policy.use_type }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Chassis</span><span class="font-mono text-xs">{{ policy.chassis_number }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Engine</span><span class="font-mono text-xs">{{ policy.engine_number }}</span></div>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Issued policy -->
|
||||
<UCard v-if="policy.policy_number">
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-check-badge" class="w-4 h-4 text-green-500" /> Policy
|
||||
</p>
|
||||
</template>
|
||||
<div class="space-y-2 text-sm">
|
||||
<div class="flex justify-between"><span class="text-gray-500">Policy #</span><span class="font-mono font-medium text-green-600">{{ policy.policy_number }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Premium</span><span class="font-semibold">${{ policy.premium }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Effective</span><span>{{ formatDate(policy.effective_date) }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Expires</span><span>{{ formatDate(policy.expiry_date) }}</span></div>
|
||||
<div class="flex justify-between"><span class="text-gray-500">Issued</span><span>{{ formatDateTime(policy.issued_at) }}</span></div>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Providers -->
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-building-office" class="w-4 h-4" /> Providers
|
||||
<UBadge color="gray" variant="soft" size="xs">{{ policy.selected_providers?.length ?? 0 }}</UBadge>
|
||||
</p>
|
||||
</template>
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="pid in policy.selected_providers" :key="pid"
|
||||
class="flex justify-between items-center text-sm p-2 bg-gray-50 rounded-lg"
|
||||
>
|
||||
<span class="font-mono text-xs text-gray-600">{{ pid }}</span>
|
||||
<UBadge :color="policy.quotes?.[pid] ? 'green' : 'yellow'" variant="soft" size="xs">
|
||||
{{ policy.quotes?.[pid] ? 'Quote received' : 'Pending' }}
|
||||
</UBadge>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
</div>
|
||||
|
||||
<!-- Quote comparison + accept -->
|
||||
<UCard v-if="quotes.length > 0">
|
||||
<template #header>
|
||||
<div class="flex justify-between items-center">
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-table-cells" class="w-4 h-4" /> Quote Comparison
|
||||
<UBadge color="gray" variant="soft" size="xs">{{ allPlans.length }} plans</UBadge>
|
||||
</p>
|
||||
<UBadge v-if="policy.accepted_plan_id" color="green" variant="soft">Plan Accepted</UBadge>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b">
|
||||
<th class="text-left py-3 px-4 text-gray-500 font-medium w-36">Feature</th>
|
||||
<th
|
||||
v-for="plan in allPlans" :key="plan.plan_id"
|
||||
class="py-3 px-4 text-center min-w-44"
|
||||
:class="plan.plan_id === policy.accepted_plan_id ? 'bg-green-50' : ''"
|
||||
>
|
||||
<div class="space-y-1">
|
||||
<UBadge v-if="plan.plan_id === policy.accepted_plan_id" color="green" variant="soft" size="xs">
|
||||
Selected
|
||||
</UBadge>
|
||||
<p class="font-semibold text-slate-800">{{ plan.name }}</p>
|
||||
<p class="text-xs font-mono text-gray-400">{{ plan.provider_id?.slice(0, 8) }}...</p>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="border-b bg-gray-50">
|
||||
<td class="py-3 px-4 font-medium text-gray-600">Premium</td>
|
||||
<td v-for="plan in allPlans" :key="plan.plan_id" class="py-3 px-4 text-center"
|
||||
:class="plan.plan_id === policy.accepted_plan_id ? 'bg-green-50' : ''">
|
||||
<span class="font-bold text-lg text-slate-900">${{ Number(plan.premium).toLocaleString() }}</span>
|
||||
<span class="text-xs text-gray-400 block">/year</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-b">
|
||||
<td class="py-3 px-4 font-medium text-gray-600">Deductible</td>
|
||||
<td v-for="plan in allPlans" :key="plan.plan_id" class="py-3 px-4 text-center"
|
||||
:class="plan.plan_id === policy.accepted_plan_id ? 'bg-green-50' : ''">
|
||||
<span v-if="plan.deductible">${{ Number(plan.deductible).toLocaleString() }}</span>
|
||||
<span v-else class="text-gray-400">—</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-b bg-gray-50">
|
||||
<td class="py-3 px-4 font-medium text-gray-600">Coverage Limit</td>
|
||||
<td v-for="plan in allPlans" :key="plan.plan_id" class="py-3 px-4 text-center"
|
||||
:class="plan.plan_id === policy.accepted_plan_id ? 'bg-green-50' : ''">
|
||||
<span v-if="plan.coverage_limit">${{ Number(plan.coverage_limit).toLocaleString() }}</span>
|
||||
<span v-else class="text-gray-400">—</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-b">
|
||||
<td class="py-3 px-4 font-medium text-gray-600">Valid Until</td>
|
||||
<td v-for="plan in allPlans" :key="plan.plan_id" class="py-3 px-4 text-center"
|
||||
:class="plan.plan_id === policy.accepted_plan_id ? 'bg-green-50' : ''">
|
||||
{{ formatDate(plan.valid_until) }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-b bg-gray-50">
|
||||
<td class="py-3 px-4 font-medium text-gray-600 align-top pt-4">Coverage</td>
|
||||
<td v-for="plan in allPlans" :key="plan.plan_id"
|
||||
class="py-3 px-4 text-center align-top pt-4"
|
||||
:class="plan.plan_id === policy.accepted_plan_id ? 'bg-green-50' : ''">
|
||||
<p class="text-xs text-gray-600 leading-relaxed">{{ plan.coverage_details }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Accept row -->
|
||||
<tr v-if="canAccept">
|
||||
<td class="py-4 px-4" />
|
||||
<td v-for="plan in allPlans" :key="plan.plan_id" class="py-4 px-4 text-center">
|
||||
<UButton
|
||||
color="primary" size="sm" icon="i-heroicons-check"
|
||||
@click="openAccept({ quote_id: plan.quote_id, provider_id: plan.provider_id, valid_until: plan.valid_until }, plan)"
|
||||
>
|
||||
Accept
|
||||
</UButton>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Solicitation PDF -->
|
||||
<UCard v-if="policy.solicitation_id">
|
||||
<template #header>
|
||||
<div class="flex justify-between items-center">
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-document-text" class="w-4 h-4" /> Solicitation Document
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<UBadge color="purple" variant="soft" size="xs">{{ policy.solicitation_id?.slice(0, 8) }}...</UBadge>
|
||||
<UButton
|
||||
icon="i-heroicons-arrow-path" color="gray" variant="ghost" size="xs"
|
||||
:loading="loadingPdf" @click="loadSolicitationUrl()"
|
||||
>
|
||||
Refresh URL
|
||||
</UButton>
|
||||
<UButton
|
||||
v-if="solicitationUrl"
|
||||
icon="i-heroicons-arrow-top-right-on-square"
|
||||
color="gray" variant="soft" size="xs"
|
||||
:to="solicitationUrl" target="_blank"
|
||||
>
|
||||
Open
|
||||
</UButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="loadingPdf" class="h-64 flex items-center justify-center text-gray-400">
|
||||
<UIcon name="i-heroicons-document-arrow-down" class="w-8 h-8 animate-pulse" />
|
||||
</div>
|
||||
<UAlert v-else-if="pdfError" color="red" variant="soft" :description="pdfError" />
|
||||
<iframe
|
||||
v-else-if="solicitationUrl"
|
||||
:src="solicitationUrl"
|
||||
class="w-full rounded-lg border"
|
||||
style="height: 600px;"
|
||||
/>
|
||||
<div v-else class="h-32 flex items-center justify-center text-gray-400 text-sm">
|
||||
Solicitation not yet generated
|
||||
</div>
|
||||
</UCard>
|
||||
</template>
|
||||
|
||||
<!-- Accept Slideover -->
|
||||
<USlideover v-model:open="isAcceptOpen" side="right">
|
||||
<template #content>
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="flex justify-between items-center p-6 border-b">
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-slate-900">Accept Plan</h2>
|
||||
<p v-if="selectedPlan" class="text-sm text-gray-500">
|
||||
{{ selectedPlan.name }} — ${{ Number(selectedPlan.premium).toLocaleString() }}/yr
|
||||
</p>
|
||||
</div>
|
||||
<UButton icon="i-heroicons-x-mark" color="gray" variant="ghost" @click="isAcceptOpen = false" />
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-6 space-y-6">
|
||||
<!-- Plan summary -->
|
||||
<div v-if="selectedPlan" class="bg-primary-50 border border-primary-200 rounded-lg p-4 text-sm space-y-2">
|
||||
<div class="flex justify-between">
|
||||
<span class="text-primary-600">Plan</span>
|
||||
<span class="font-semibold">{{ selectedPlan.name }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-primary-600">Premium</span>
|
||||
<span class="font-bold text-primary-900">${{ Number(selectedPlan.premium).toLocaleString() }}/yr</span>
|
||||
</div>
|
||||
<div v-if="selectedPlan.deductible" class="flex justify-between">
|
||||
<span class="text-primary-600">Deductible</span>
|
||||
<span>${{ Number(selectedPlan.deductible).toLocaleString() }}</span>
|
||||
</div>
|
||||
<div v-if="selectedPlan.coverage_limit" class="flex justify-between">
|
||||
<span class="text-primary-600">Coverage Limit</span>
|
||||
<span>${{ Number(selectedPlan.coverage_limit).toLocaleString() }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-primary-600">Provider</span>
|
||||
<span class="font-mono text-xs">{{ selectedQuote?.provider_id?.slice(0, 12) }}...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Optional solicitation fields -->
|
||||
<div class="space-y-3">
|
||||
<div class="flex justify-between items-center">
|
||||
<p class="font-medium text-sm text-slate-700">Additional Fields</p>
|
||||
<UButton
|
||||
icon="i-heroicons-plus" color="gray" variant="soft" size="xs"
|
||||
@click="solicitationFields[`field_${Object.keys(solicitationFields).length + 1}`] = ''"
|
||||
>
|
||||
Add Field
|
||||
</UButton>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400">
|
||||
Optional provider-specific fields for the solicitation form.
|
||||
</p>
|
||||
<div v-for="(val, key) in solicitationFields" :key="key" class="flex gap-2 items-end">
|
||||
<UFormField :label="String(key)" class="flex-1">
|
||||
<UInput v-model="solicitationFields[key]" class="w-full" />
|
||||
</UFormField>
|
||||
<UButton icon="i-heroicons-trash" color="red" variant="ghost" size="sm"
|
||||
@click="delete solicitationFields[key]" />
|
||||
</div>
|
||||
<p v-if="Object.keys(solicitationFields).length === 0" class="text-xs text-gray-400 italic">
|
||||
No additional fields — the PDF will be filled from policy data automatically.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-6 border-t flex justify-end gap-3">
|
||||
<UButton color="gray" variant="soft" @click="isAcceptOpen = false">Cancel</UButton>
|
||||
<UButton
|
||||
color="primary" icon="i-heroicons-check"
|
||||
:loading="accepting"
|
||||
@click="submitAccept"
|
||||
>
|
||||
Confirm & Generate Solicitation
|
||||
</UButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</USlideover>
|
||||
</div>
|
||||
</template>
|
||||
202
app/pages/policies/index.vue
Normal file
202
app/pages/policies/index.vue
Normal file
@@ -0,0 +1,202 @@
|
||||
<script setup lang="ts">
|
||||
import { refDebounced } from '@vueuse/core'
|
||||
import type { SelectItem } from '@nuxt/ui'
|
||||
|
||||
const page = ref(1)
|
||||
const search = ref('')
|
||||
const statusFilter = ref<string | null>(null)
|
||||
const debouncedSearch = refDebounced(search, 300)
|
||||
|
||||
const statusItems = ref<SelectItem[]>([
|
||||
{ label: 'All Statuses', value: null },
|
||||
{ label: 'Quote Requested', value: 'quote_requested' },
|
||||
{ label: 'Quotes Received', value: 'quotes_received' },
|
||||
{ label: 'Solicitation Sent', value: 'solicitation_sent' },
|
||||
{ label: 'Active', value: 'active' }
|
||||
])
|
||||
|
||||
watch(debouncedSearch, () => { page.value = 1 })
|
||||
watch(statusFilter, () => { page.value = 1 })
|
||||
|
||||
const { data, error, pending, refresh } = usePolicy('/car-policies', {
|
||||
query: computed(() => ({
|
||||
page_size: 20,
|
||||
page: page.value,
|
||||
...(statusFilter.value && {
|
||||
'filters[0][field]': 'status',
|
||||
'filters[0][op]': '==',
|
||||
'filters[0][value]': statusFilter.value
|
||||
}),
|
||||
...(debouncedSearch.value && {
|
||||
[`filters[${statusFilter.value ? 1 : 0}][field]`]: 'search',
|
||||
[`filters[${statusFilter.value ? 1 : 0}][op]`]: '==',
|
||||
[`filters[${statusFilter.value ? 1 : 0}][value]`]: debouncedSearch.value
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
const policies = computed(() => data.value?.data ?? [])
|
||||
const meta = computed(() => data.value?.meta)
|
||||
|
||||
const statusColor = (status: string) => {
|
||||
switch (status) {
|
||||
case 'quote_requested': return 'yellow'
|
||||
case 'quotes_received': return 'blue'
|
||||
case 'solicitation_sent': return 'purple'
|
||||
case 'active': return 'green'
|
||||
default: return 'gray'
|
||||
}
|
||||
}
|
||||
|
||||
const statusLabel = (status: string) => {
|
||||
switch (status) {
|
||||
case 'quote_requested': return 'Quote Requested'
|
||||
case 'quotes_received': return 'Quotes Received'
|
||||
case 'solicitation_sent': return 'Solicitation Sent'
|
||||
case 'active': return 'Active'
|
||||
default: return status
|
||||
}
|
||||
}
|
||||
|
||||
const statusIcon = (status: string) => {
|
||||
switch (status) {
|
||||
case 'quote_requested': return 'i-heroicons-clock'
|
||||
case 'quotes_received': return 'i-heroicons-inbox'
|
||||
case 'solicitation_sent': return 'i-heroicons-paper-airplane'
|
||||
case 'active': return 'i-heroicons-check-badge'
|
||||
default: return 'i-heroicons-document'
|
||||
}
|
||||
}
|
||||
|
||||
const clientTypeLabel = (ct: string) =>
|
||||
ct === 'juridico' ? 'Jurídico' : 'Natural'
|
||||
|
||||
const clientTypeColor = (ct: string) =>
|
||||
ct === 'juridico' ? 'purple' : 'blue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-8 space-y-8 bg-gray-50 min-h-screen">
|
||||
<!-- Header -->
|
||||
<div class="flex justify-between items-center">
|
||||
<div>
|
||||
<h1 class="text-3xl text-slate-900 font-bold">Policies</h1>
|
||||
<p class="text-gray-500 text-sm">Car Insurance Policy Management</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<UBadge color="gray" variant="soft" size="lg">
|
||||
{{ meta?.total_count ?? 0 }} policies
|
||||
</UBadge>
|
||||
<NuxtLink to="/policies/new">
|
||||
<UButton icon="i-heroicons-plus" color="primary">New Policy</UButton>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="flex gap-4 items-center flex-wrap">
|
||||
<UInput
|
||||
v-model="search"
|
||||
icon="i-heroicons-magnifying-glass"
|
||||
placeholder="Search by name, plate, policy #..."
|
||||
class="w-80"
|
||||
/>
|
||||
<USelect v-model="statusFilter" :items="statusItems" class="w-52" />
|
||||
<UButton
|
||||
icon="i-heroicons-arrow-path"
|
||||
color="gray" variant="soft"
|
||||
:loading="pending"
|
||||
@click="refresh()"
|
||||
>
|
||||
Refresh
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
<UAlert v-if="error" color="red" variant="soft" title="Failed to load policies" :description="error.message" />
|
||||
|
||||
<div v-else-if="pending" class="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
<UCard v-for="n in 6" :key="n">
|
||||
<div class="h-48 animate-pulse bg-gray-200 rounded" />
|
||||
</UCard>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
<NuxtLink
|
||||
v-for="policy in policies"
|
||||
:key="policy.application_id"
|
||||
:to="`/policies/${policy.application_id}`"
|
||||
>
|
||||
<UCard class="hover:shadow-md transition-shadow cursor-pointer h-full">
|
||||
<div class="space-y-4">
|
||||
<!-- Status + type badges -->
|
||||
<div class="flex justify-between items-start">
|
||||
<UBadge :color="statusColor(policy.status)" variant="soft" class="flex items-center gap-1">
|
||||
<UIcon :name="statusIcon(policy.status)" class="w-3 h-3" />
|
||||
{{ statusLabel(policy.status) }}
|
||||
</UBadge>
|
||||
<div class="flex gap-1">
|
||||
<UBadge :color="clientTypeColor(policy.client_type)" variant="outline" size="xs">
|
||||
{{ clientTypeLabel(policy.client_type) }}
|
||||
</UBadge>
|
||||
<UBadge color="gray" variant="outline" size="xs">CAR</UBadge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Applicant -->
|
||||
<div>
|
||||
<p class="font-semibold text-slate-900 text-lg leading-tight">
|
||||
{{ policy.applicant_display_name }}
|
||||
</p>
|
||||
<p class="text-gray-400 text-sm">{{ policy.applicant_document }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Vehicle -->
|
||||
<div class="bg-gray-50 rounded-lg p-3 space-y-1.5 text-sm">
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-500">Plate</span>
|
||||
<span class="font-medium font-mono">{{ policy.plate }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-500">Vehicle</span>
|
||||
<span class="font-medium">{{ policy.year }} {{ policy.make }} {{ policy.model }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-500">Value</span>
|
||||
<span class="font-medium">${{ Number(policy.car_value).toLocaleString() }}</span>
|
||||
</div>
|
||||
<div v-if="policy.policy_number" class="flex justify-between">
|
||||
<span class="text-gray-500">Policy #</span>
|
||||
<span class="font-medium font-mono text-green-600">{{ policy.policy_number }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="flex justify-between items-center text-xs text-gray-400 pt-1 border-t">
|
||||
<div class="flex items-center gap-1">
|
||||
<UIcon name="i-heroicons-chat-bubble-left-right" class="w-3.5 h-3.5" />
|
||||
<span>
|
||||
{{ Object.keys(policy.quotes ?? {}).length }} /
|
||||
{{ (policy.selected_providers ?? []).length }} quotes
|
||||
</span>
|
||||
</div>
|
||||
<span>{{ new Date(policy.submitted_at).toLocaleDateString('es-PA') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
</NuxtLink>
|
||||
|
||||
<div v-if="policies.length === 0" class="col-span-3 text-center py-16 text-gray-400">
|
||||
<UIcon name="i-heroicons-document-text" class="w-12 h-12 mx-auto mb-4" />
|
||||
<p class="text-lg font-medium">No policies found</p>
|
||||
<p class="text-sm">Create a new policy or adjust your filters</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div v-if="meta && meta.total_pages > 1" class="flex justify-center">
|
||||
<UPagination v-model="page" :total="meta.total_count" :page-count="meta.page_size" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
498
app/pages/policies/new.vue
Normal file
498
app/pages/policies/new.vue
Normal file
@@ -0,0 +1,498 @@
|
||||
<script setup lang="ts">
|
||||
import type { SelectItem } from '@nuxt/ui'
|
||||
import { refDebounced } from '@vueuse/core'
|
||||
|
||||
const router = useRouter()
|
||||
const policyType = ref<'car' | 'life' | 'fire'>('car')
|
||||
const submitting = ref(false)
|
||||
const toast = useToast()
|
||||
const { $policy } = useNuxtApp()
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Customer selection
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const customerSearch = ref('')
|
||||
const debouncedCustomerSearch = refDebounced(customerSearch, 300)
|
||||
const customerPage = ref(1)
|
||||
const selectedCustomer = ref<any>(null)
|
||||
|
||||
const { data: customersData, pending: customersPending } = useCustomer('/customers', {
|
||||
query: computed(() => ({
|
||||
'page_size': 12,
|
||||
'page': customerPage.value,
|
||||
...(debouncedCustomerSearch.value && {
|
||||
'filters[0][field]': 'search',
|
||||
'filters[0][op]': '==',
|
||||
'filters[0][value]': debouncedCustomerSearch.value
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
watch(debouncedCustomerSearch, () => { customerPage.value = 1 })
|
||||
|
||||
const customerItems = computed(() => customersData.value?.data ?? [])
|
||||
const customerMeta = computed(() => customersData.value?.meta)
|
||||
|
||||
function selectCustomer(customer: any) {
|
||||
selectedCustomer.value = customer
|
||||
}
|
||||
|
||||
const customerDisplayName = (c: any) =>
|
||||
c.customer_type === 'corporate'
|
||||
? (c.commercial_name || c.legal_name)
|
||||
: `${c.first_name} ${c.last_name}`
|
||||
|
||||
const customerSubtitle = (c: any) =>
|
||||
c.customer_type === 'corporate' ? c.ruc : c.email
|
||||
|
||||
// Build applicant_info from selected customer — shape varies by type
|
||||
const applicantInfo = computed(() => {
|
||||
const c = selectedCustomer.value
|
||||
if (!c) return null
|
||||
if (c.customer_type === 'corporate') {
|
||||
return {
|
||||
company_name: c.legal_name,
|
||||
ruc: c.ruc,
|
||||
legal_rep_name: c.legal_rep_name,
|
||||
legal_rep_document: c.legal_rep_document_id
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: `${c.first_name} ${c.last_name}`.trim(),
|
||||
date_of_birth: c.birth_date,
|
||||
document_id: c.document_id
|
||||
}
|
||||
})
|
||||
|
||||
const isApplicantValid = computed(() => {
|
||||
const c = selectedCustomer.value
|
||||
if (!c) return false
|
||||
if (c.customer_type === 'corporate') {
|
||||
return !!(c.legal_name && c.ruc)
|
||||
}
|
||||
return !!(c.birth_date && c.document_id)
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Policy type
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const policyTypeItems = ref<SelectItem[]>([
|
||||
{ label: 'Car Insurance', value: 'car' },
|
||||
{ label: 'Life Insurance', value: 'life', disabled: true },
|
||||
{ label: 'Fire Insurance', value: 'fire', disabled: true }
|
||||
])
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Car form
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const carForm = ref({
|
||||
car_details: {
|
||||
plate: '',
|
||||
make: '',
|
||||
model: '',
|
||||
year: new Date().getFullYear(),
|
||||
car_value: '',
|
||||
use_type: 'private',
|
||||
car_type: 'sedan',
|
||||
chassis_number: '',
|
||||
engine_number: ''
|
||||
},
|
||||
selected_providers: [] as { id: string, email: string }[]
|
||||
})
|
||||
|
||||
const useTypeItems = ref<SelectItem[]>([
|
||||
{ label: 'Private', value: 'private' },
|
||||
{ label: 'Commercial', value: 'commercial' },
|
||||
{ label: 'Bus', value: 'bus' },
|
||||
{ label: 'Taxi', value: 'taxi' },
|
||||
{ label: 'School', value: 'school' }
|
||||
])
|
||||
|
||||
const carTypeItems = ref<SelectItem[]>([
|
||||
{ label: 'Sedan', value: 'sedan' },
|
||||
{ label: 'SUV', value: 'suv' },
|
||||
{ label: 'Hatchback', value: 'hatchback' },
|
||||
{ label: 'Coupe', value: 'coupe' },
|
||||
{ label: 'Convertible', value: 'convertible' },
|
||||
{ label: 'Pickup', value: 'pickup' },
|
||||
{ label: 'Van', value: 'van' },
|
||||
{ label: 'Minivan', value: 'minivan' },
|
||||
{ label: 'Truck', value: 'truck' }
|
||||
])
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Provider selection
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const providerSearch = ref('')
|
||||
const debouncedProviderSearch = refDebounced(providerSearch, 300)
|
||||
|
||||
const { data: providersData, pending: providersPending } = useProviders('/providers', {
|
||||
query: computed(() => ({
|
||||
...(debouncedProviderSearch.value && {
|
||||
'filters[0][field]': 'search',
|
||||
'filters[0][op]': '==',
|
||||
'filters[0][value]': debouncedProviderSearch.value
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
const providerItems = computed(() => providersData.value?.data ?? [])
|
||||
|
||||
function toggleProvider(provider: any) {
|
||||
const idx = carForm.value.selected_providers.findIndex(p => p.id === provider.provider_id)
|
||||
if (idx >= 0) {
|
||||
carForm.value.selected_providers.splice(idx, 1)
|
||||
} else {
|
||||
carForm.value.selected_providers.push({ id: provider.provider_id, email: provider.email })
|
||||
}
|
||||
}
|
||||
|
||||
function isProviderSelected(provider: any) {
|
||||
return carForm.value.selected_providers.some(p => p.id === provider.provider_id)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Submit
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function submitCarPolicy() {
|
||||
submitting.value = true
|
||||
try {
|
||||
const data = await $policy('/car-policies', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
applicant_info: applicantInfo.value,
|
||||
car_details: carForm.value.car_details,
|
||||
selected_providers: carForm.value.selected_providers
|
||||
}
|
||||
}) as any
|
||||
|
||||
toast.add({ title: 'Policy submitted successfully', color: 'green' })
|
||||
router.push(`/policies/${data.application_id}`)
|
||||
} catch (e: any) {
|
||||
toast.add({
|
||||
title: 'Failed to submit policy',
|
||||
description: e?.data?.errors ? JSON.stringify(e.data.errors) : e.message,
|
||||
color: 'red'
|
||||
})
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const isCarFormValid = computed(() => {
|
||||
const { car_details, selected_providers } = carForm.value
|
||||
return (
|
||||
isApplicantValid.value &&
|
||||
car_details.plate &&
|
||||
car_details.make &&
|
||||
car_details.model &&
|
||||
car_details.year &&
|
||||
car_details.car_value &&
|
||||
car_details.chassis_number &&
|
||||
car_details.engine_number &&
|
||||
selected_providers.length > 0
|
||||
)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-8 space-y-8 bg-gray-50 min-h-screen">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center gap-4">
|
||||
<NuxtLink to="/policies">
|
||||
<UButton icon="i-heroicons-arrow-left" color="gray" variant="ghost">
|
||||
Back to Policies
|
||||
</UButton>
|
||||
</NuxtLink>
|
||||
<div>
|
||||
<h1 class="text-3xl text-slate-900 font-bold">New Policy</h1>
|
||||
<p class="text-gray-500 text-sm">Submit a new insurance policy quote request</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Customer Selection -->
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-users" class="w-4 h-4" />
|
||||
Select Customer
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<div class="space-y-4">
|
||||
<UInput
|
||||
v-model="customerSearch"
|
||||
icon="i-heroicons-magnifying-glass"
|
||||
placeholder="Search by name, email, RUC..."
|
||||
class="w-full max-w-sm"
|
||||
/>
|
||||
|
||||
<div v-if="customersPending" class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||
<div v-for="n in 3" :key="n" class="h-16 animate-pulse bg-gray-100 rounded-lg" />
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-3">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 max-h-72 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="c in customerItems"
|
||||
:key="c.id"
|
||||
class="flex items-center gap-3 p-3 border-2 rounded-lg cursor-pointer transition-all"
|
||||
:class="selectedCustomer?.id === c.id
|
||||
? 'border-primary-500 bg-primary-50'
|
||||
: 'border-gray-200 hover:border-gray-300 bg-white'"
|
||||
@click="selectCustomer(c)"
|
||||
>
|
||||
<UAvatar :alt="customerDisplayName(c)" size="sm" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<p class="font-medium text-sm text-slate-800 truncate">{{ customerDisplayName(c) }}</p>
|
||||
<UBadge
|
||||
:color="c.customer_type === 'corporate' ? 'purple' : 'blue'"
|
||||
variant="soft" size="xs" class="flex-shrink-0"
|
||||
>
|
||||
{{ c.customer_type === 'corporate' ? 'Corp' : 'Ind' }}
|
||||
</UBadge>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 truncate">{{ customerSubtitle(c) }}</p>
|
||||
</div>
|
||||
<UIcon
|
||||
v-if="selectedCustomer?.id === c.id"
|
||||
name="i-heroicons-check-circle"
|
||||
class="w-5 h-5 text-primary-500 flex-shrink-0"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="customerItems.length === 0" class="col-span-3 text-center py-6 text-gray-400 text-sm">
|
||||
No customers found.
|
||||
<NuxtLink to="/customers/new" class="text-primary-500 underline ml-1">Create one</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="customerMeta && customerMeta.total_pages > 1" class="flex justify-between items-center text-sm text-gray-500">
|
||||
<span>{{ customerMeta.total_count }} customers</span>
|
||||
<UPagination
|
||||
v-model="customerPage"
|
||||
:total="customerMeta.total_count"
|
||||
:page-count="customerMeta.page_size"
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Selected summary -->
|
||||
<div
|
||||
v-if="selectedCustomer"
|
||||
class="flex items-center gap-4 p-3 bg-primary-50 border border-primary-200 rounded-lg text-sm"
|
||||
>
|
||||
<UAvatar :alt="customerDisplayName(selectedCustomer)" size="sm" />
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<p class="font-medium text-primary-800">{{ customerDisplayName(selectedCustomer) }}</p>
|
||||
<UBadge
|
||||
:color="selectedCustomer.customer_type === 'corporate' ? 'purple' : 'blue'"
|
||||
variant="soft" size="xs"
|
||||
>
|
||||
{{ selectedCustomer.customer_type === 'corporate' ? 'Corporate' : 'Individual' }}
|
||||
</UBadge>
|
||||
</div>
|
||||
<p class="text-primary-600 text-xs">{{ selectedCustomer.email }}</p>
|
||||
</div>
|
||||
<div class="text-xs text-primary-600 text-right space-y-0.5">
|
||||
<template v-if="selectedCustomer.customer_type === 'corporate'">
|
||||
<p>RUC: {{ selectedCustomer.ruc ?? '—' }}</p>
|
||||
<p>Rep: {{ selectedCustomer.legal_rep_name ?? '—' }}</p>
|
||||
</template>
|
||||
<template v-else>
|
||||
<p>DOB: {{ selectedCustomer.birth_date ?? '—' }}</p>
|
||||
<p>Doc: {{ selectedCustomer.document_id ?? '—' }}</p>
|
||||
</template>
|
||||
</div>
|
||||
<UButton size="xs" color="gray" variant="ghost" @click="selectedCustomer = null">Change</UButton>
|
||||
</div>
|
||||
|
||||
<!-- Warn if individual customer missing required fields -->
|
||||
<UAlert
|
||||
v-if="selectedCustomer && selectedCustomer.customer_type !== 'corporate' && (!selectedCustomer.birth_date || !selectedCustomer.document_id)"
|
||||
color="yellow" variant="soft" icon="i-heroicons-exclamation-triangle"
|
||||
title="Incomplete customer record"
|
||||
description="This customer is missing date of birth or document ID. Please update their record before submitting."
|
||||
/>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Policy Type -->
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700">Policy Type</p>
|
||||
</template>
|
||||
<div class="flex gap-4">
|
||||
<div
|
||||
v-for="item in policyTypeItems"
|
||||
:key="item.value"
|
||||
class="flex-1 border-2 rounded-xl p-4 text-center transition-all"
|
||||
:class="[
|
||||
item.disabled
|
||||
? 'border-gray-100 bg-gray-50 opacity-40 cursor-not-allowed'
|
||||
: policyType === item.value
|
||||
? 'border-primary-500 bg-primary-50 cursor-pointer'
|
||||
: 'border-gray-200 bg-white hover:border-gray-300 cursor-pointer'
|
||||
]"
|
||||
@click="!item.disabled && (policyType = item.value as any)"
|
||||
>
|
||||
<UIcon
|
||||
:name="item.value === 'car' ? 'i-heroicons-truck' : item.value === 'life' ? 'i-heroicons-heart' : 'i-heroicons-home'"
|
||||
class="w-8 h-8 mx-auto mb-2"
|
||||
:class="policyType === item.value ? 'text-primary-500' : 'text-gray-400'"
|
||||
/>
|
||||
<p class="font-medium text-sm" :class="policyType === item.value ? 'text-primary-700' : 'text-gray-600'">
|
||||
{{ item.label }}
|
||||
</p>
|
||||
<p v-if="item.disabled" class="text-xs text-gray-400 mt-1">Coming soon</p>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Car Form -->
|
||||
<template v-if="policyType === 'car'">
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-truck" class="w-4 h-4" />
|
||||
Vehicle Details
|
||||
</p>
|
||||
</template>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<UFormField label="Plate" required>
|
||||
<UInput v-model="carForm.car_details.plate" placeholder="ABC-1234" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Make" required>
|
||||
<UInput v-model="carForm.car_details.make" placeholder="Toyota" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Model" required>
|
||||
<UInput v-model="carForm.car_details.model" placeholder="Corolla" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Year" required>
|
||||
<UInput
|
||||
v-model.number="carForm.car_details.year"
|
||||
type="number"
|
||||
:min="1886"
|
||||
:max="new Date().getFullYear() + 1"
|
||||
class="w-full"
|
||||
/>
|
||||
</UFormField>
|
||||
<UFormField label="Car Value (USD)" required>
|
||||
<UInput v-model="carForm.car_details.car_value" type="number" placeholder="18000" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Use Type" required>
|
||||
<USelect v-model="carForm.car_details.use_type" :items="useTypeItems" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Car Type" required>
|
||||
<USelect v-model="carForm.car_details.car_type" :items="carTypeItems" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Chassis Number" required>
|
||||
<UInput v-model="carForm.car_details.chassis_number" placeholder="9BWZZZ377VT004251" class="w-full" />
|
||||
</UFormField>
|
||||
<UFormField label="Engine Number" required>
|
||||
<UInput v-model="carForm.car_details.engine_number" placeholder="1NZ-FE-1234567" class="w-full" />
|
||||
</UFormField>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Provider Selection -->
|
||||
<UCard>
|
||||
<template #header>
|
||||
<p class="font-semibold text-slate-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-building-office" class="w-4 h-4" />
|
||||
Selected Providers
|
||||
<UBadge color="gray" variant="soft" size="xs">
|
||||
{{ carForm.selected_providers.length }} selected
|
||||
</UBadge>
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<div class="space-y-4">
|
||||
<UInput
|
||||
v-model="providerSearch"
|
||||
icon="i-heroicons-magnifying-glass"
|
||||
placeholder="Search providers..."
|
||||
class="w-full max-w-sm"
|
||||
/>
|
||||
|
||||
<div v-if="providersPending" class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||
<div v-for="n in 3" :key="n" class="h-16 animate-pulse bg-gray-100 rounded-lg" />
|
||||
</div>
|
||||
|
||||
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 max-h-72 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="p in providerItems"
|
||||
:key="p.provider_id"
|
||||
class="flex items-center gap-3 p-3 border-2 rounded-lg cursor-pointer transition-all"
|
||||
:class="isProviderSelected(p)
|
||||
? 'border-primary-500 bg-primary-50'
|
||||
: 'border-gray-200 hover:border-gray-300 bg-white'"
|
||||
@click="toggleProvider(p)"
|
||||
>
|
||||
<div class="w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center flex-shrink-0">
|
||||
<UIcon name="i-heroicons-building-office" class="w-4 h-4 text-gray-500" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="font-medium text-sm text-slate-800 truncate">{{ p.name }}</p>
|
||||
<p class="text-xs text-gray-400 truncate">{{ p.email }}</p>
|
||||
</div>
|
||||
<UIcon
|
||||
v-if="isProviderSelected(p)"
|
||||
name="i-heroicons-check-circle"
|
||||
class="w-5 h-5 text-primary-500 flex-shrink-0"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="providerItems.length === 0" class="col-span-3 text-center py-6 text-gray-400 text-sm">
|
||||
No providers found.
|
||||
<NuxtLink to="/providers/new" class="text-primary-500 underline ml-1">Create one</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="carForm.selected_providers.length > 0" class="flex flex-wrap gap-2 pt-2 border-t">
|
||||
<div
|
||||
v-for="p in carForm.selected_providers"
|
||||
:key="p.id"
|
||||
class="flex items-center gap-1.5 px-3 py-1 bg-primary-50 border border-primary-200 rounded-full text-sm"
|
||||
>
|
||||
<UIcon name="i-heroicons-building-office" class="w-3.5 h-3.5 text-primary-500" />
|
||||
<span class="text-primary-800 font-medium">
|
||||
{{ providerItems.find(x => x.provider_id === p.id)?.name ?? p.id }}
|
||||
</span>
|
||||
<UButton
|
||||
icon="i-heroicons-x-mark"
|
||||
size="xs" color="gray" variant="ghost"
|
||||
class="w-4 h-4 p-0"
|
||||
@click="carForm.selected_providers = carForm.selected_providers.filter(x => x.id !== p.id)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<!-- Submit -->
|
||||
<div class="flex justify-end gap-3">
|
||||
<NuxtLink to="/policies">
|
||||
<UButton color="gray" variant="soft">Cancel</UButton>
|
||||
</NuxtLink>
|
||||
<UButton
|
||||
color="primary"
|
||||
icon="i-heroicons-paper-airplane"
|
||||
:loading="submitting"
|
||||
:disabled="!isCarFormValid"
|
||||
@click="submitCarPolicy"
|
||||
>
|
||||
Submit Quote Request
|
||||
</UButton>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user