Files
tehran_tala/apps/admin-panel/src/views/DashboardView.vue
T
2026-09-09 06:46:27 +03:30

74 lines
1.6 KiB
Vue

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { api, type CustomerSummary } from '../api/client';
import { useSessionStore } from '../stores/session';
const customers = ref<CustomerSummary[]>([]);
const loading = ref(true);
const error = ref<string | null>(null);
const router = useRouter();
const session = useSessionStore();
onMounted(async () => {
try {
customers.value = await api.listCustomers();
} catch (e) {
error.value = (e as Error).message;
} finally {
loading.value = false;
}
});
function goToNewOrder(customerId: string) {
session.selectCustomer(customerId);
router.push({ name: 'order-new' });
}
</script>
<template>
<section>
<h1>Customers</h1>
<p v-if="loading">Loading…</p>
<p v-else-if="error" class="error">{{ error }}</p>
<table v-else>
<thead>
<tr>
<th>Name</th>
<th>Mobile</th>
<th>Gold debt (g)</th>
<th>Rial debt</th>
<th>Credit limit (g)</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="c in customers" :key="c.id">
<td>{{ c.fullName }}</td>
<td>{{ c.mobile }}</td>
<td>{{ c.goldDebtGrams }}</td>
<td>{{ c.fiatDebtRial }}</td>
<td>{{ c.goldCreditLimitGrams }}</td>
<td><button @click="goToNewOrder(c.id)">New order</button></td>
</tr>
</tbody>
</table>
</section>
</template>
<style scoped>
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
text-align: left;
padding: 0.5rem;
border-bottom: 1px solid #ddd;
}
.error {
color: #b00020;
}
</style>