92 lines
2.9 KiB
Vue
92 lines
2.9 KiB
Vue
<script setup lang="ts">
|
|
|
|
import type { Invoice } from "@vmall/shared";
|
|
|
|
definePageMeta({ middleware: "auth" });
|
|
|
|
const { $api } = useNuxtApp();
|
|
const { locale, t: translate } = useI18n();
|
|
const { load: loadMoney, fmt } = useMoney();
|
|
const invoices = ref<Invoice[]>([]);
|
|
const loading = ref(true);
|
|
const error = ref("");
|
|
const actionId = ref("");
|
|
|
|
function statusClass(value: Invoice["status"]): string {
|
|
return value === "issued" ? "green" : value === "cancelled" ? "red" : "orange";
|
|
}
|
|
|
|
async function loadInvoices(): Promise<void> {
|
|
loading.value = true;
|
|
error.value = "";
|
|
try {
|
|
invoices.value = await $api.shop.listInvoices();
|
|
} catch (err: unknown) {
|
|
error.value = err instanceof Error ? err.message : translate("common.error");
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
async function issueInvoice(invoice: Invoice): Promise<void> {
|
|
actionId.value = invoice.id;
|
|
error.value = "";
|
|
try {
|
|
await $api.shop.issueInvoice(invoice.id);
|
|
await loadInvoices();
|
|
} catch (err: unknown) {
|
|
error.value = err instanceof Error ? err.message : translate("common.error");
|
|
} finally {
|
|
actionId.value = "";
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadMoney();
|
|
loadInvoices();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="page">
|
|
<h1 class="page-title">{{ $t("shop.invoiceList") }}</h1>
|
|
<div v-if="error" class="error-text" role="alert">{{ error }}</div>
|
|
<p v-if="loading" class="muted">{{ $t("common.loading") }}</p>
|
|
<div v-else-if="!invoices.length" class="card muted">{{ $t("common.empty") }}</div>
|
|
<div v-else class="table-wrap">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>{{ $t("shop.invoiceNo") }}</th>
|
|
<th>{{ $t("shop.orderNo") }}</th>
|
|
<th>{{ $t("invoice.invoiceTitle") }}</th>
|
|
<th>{{ $t("shop.kind") }}</th>
|
|
<th>{{ $t("shop.taxNo") }}</th>
|
|
<th>{{ $t("invoice.amount") }}</th>
|
|
<th>{{ $t("common.status") }}</th>
|
|
<th>{{ $t("common.actions") }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="invoice in invoices" :key="invoice.id">
|
|
<td>{{ invoice.invoice_no || $t("shop.noInvoice") }}</td>
|
|
<td><NuxtLink :to="`/orders/${invoice.order_id}`">{{ invoice.order_no ?? invoice.order_id }}</NuxtLink></td>
|
|
<td>{{ invoice.title }}</td>
|
|
<td>{{ $t(`invoice.${invoice.kind}`) }}</td>
|
|
<td>{{ invoice.tax_no || $t("shop.noInvoice") }}</td>
|
|
<td>{{ fmt(invoice.amount_minor, invoice.currency) }}</td>
|
|
<td><span class="badge" :class="statusClass(invoice.status)">{{ $t(`invoice.status.${invoice.status}`) }}</span></td>
|
|
<td><button v-if="invoice.status === 'requested'" class="btn sm primary" :disabled="actionId === invoice.id" @click="issueInvoice(invoice)">{{ $t("shop.issueInvoice") }}</button></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.table-wrap {
|
|
overflow-x: auto;
|
|
}
|
|
</style>
|