main
vue 69 lines 1.61 KB
Raw
1 <template>
2 <n-spin :show="loading">
3 <CardStatsMulti
4 title="Customers"
5 hovered
6 class="h-full cursor-pointer"
7 :values="[{ value: total, label: 'Total' }]"
8 @click="routeCustomer().navigate()"
9 >
10 <template #icon>
11 <CardStatsIcon :icon-name="CustomersIcon" boxed :box-size="30"></CardStatsIcon>
12 </template>
13 </CardStatsMulti>
14 </n-spin>
15 </template>
16
17 <script setup lang="ts">
18 import type { Customer } from "@/types/customers.d"
19 import { NSpin, useMessage } from "naive-ui"
20 import { computed, onBeforeMount, ref } from "vue"
21 import Api from "@/api"
22 import CardStatsIcon from "@/components/common/cards/CardStatsIcon.vue"
23 import CardStatsMulti from "@/components/common/cards/CardStatsMulti.vue"
24 import { useNavigation } from "@/composables/useNavigation"
25
26 const CustomersIcon = "carbon:user-multiple"
27 const { routeCustomer } = useNavigation()
28 const message = useMessage()
29 const loading = ref(false)
30 const customers = ref<Customer[]>([])
31
32 const total = computed<number>(() => {
33 return customers.value.length || 0
34 })
35
36 function getData() {
37 loading.value = true
38
39 Api.customers
40 .getCustomers()
41 .then(res => {
42 if (res.data.success) {
43 customers.value = res.data?.customers || []
44 } else {
45 message.warning(res.data?.message || "An error occurred. Please try again later.")
46 }
47 })
48 .catch(err => {
49 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
50 })
51 .finally(() => {
52 loading.value = false
53 })
54 }
55
56 onBeforeMount(() => {
57 getData()
58 })
59 </script>
60
61 <style lang="scss" scoped>
62 .n-spin-container {
63 :deep() {
64 .n-spin-content {
65 height: 100%;
66 }
67 }
68 }
69 </style>