Files
hedena_gold/apps/admin-panel/src/views/DashboardECommerce.vue
T

134 lines
4.2 KiB
Vue
Raw Normal View History

<template>
<!--
Ported from legacy henza_admin/src/views/DashboardECommerce.vue — the
wholesale dashboard ("آمار عمده فروشی").
Legacy's file is a Vuexy template whose English demo cards are all COMMENTED
OUT (Congratulations, Support Tracker, Product Orders, Sales Stats, Activity
Timeline — verified line by line). The live content is the three 30-day stat
cards plus three Farsi tables, and that is what is ported.
-->
<a-spin :spinning="loading">
<div class="grid-3">
<StatisticsCardLine
icon="UsersIcon"
color="warning"
:statistic="`${omdeData.customerCount} نفر `"
statistic-title="تعداد مشتریان ثبت نامی در 30 روز گذشته"
/>
<StatisticsCardLine
icon="ShoppingBagIcon"
:statistic="`${omdeData.allgram} گرم `"
statistic-title="طلای فروش رفته در 30 روز گذشته"
/>
<StatisticsCardLine
icon="ShoppingBagIcon"
color="warning"
:statistic="`${omdeData.ordercount} سفارش `"
statistic-title="تعداد سفارشات 30 روز گذشته"
/>
</div>
<div class="grid-2 mt-4">
<a-card title="عملکرد کارشناسان فروش">
<a-table
size="small"
:data-source="omdeData.reagent"
:columns="agentColumns"
:pagination="false"
row-key="id"
/>
</a-card>
<a-card title="میزان فروش">
<a-descriptions bordered size="small" :column="1">
<a-descriptions-item label="تعداد سفارش (۳۰ روز)">
{{ omdeData.sumLastOrder }}
</a-descriptions-item>
<a-descriptions-item label="مجموع وزن (۳۰ روز)">
{{ omdeData.sumLastOrderMonth }} گرم
</a-descriptions-item>
</a-descriptions>
</a-card>
</div>
<a-card title="سفارشات هفته جاری" class="mt-4">
<a-table
size="small"
:data-source="omdeData.lastOrder"
:columns="orderColumns"
:pagination="{ pageSize: 10 }"
row-key="id"
>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'sts_str'">
<a-tag :color="tagColor(record.statusColor)">{{ record.sts_str }}</a-tag>
</template>
<template v-else-if="column.dataIndex === 'caj'">
{{ jdate(record.caj) }}
</template>
</template>
</a-table>
</a-card>
</a-spin>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue';
import StatisticsCardLine from '../components/statistics-cards/StatisticsCardLine.vue';
import { jdate } from '../utils/filters';
import api from '../api/client';
const loading = ref(false);
const omdeData = reactive<Record<string, any>>({
customerCount: 0,
allgram: 0,
ordercount: 0,
reagent: [],
lastOrder: [],
sumLastOrder: 0,
sumLastOrderMonth: 0,
});
const agentColumns = [
{ title: 'کارشناس فروش', dataIndex: 'name' },
{ title: 'میزان فروش (گرم)', dataIndex: 'grams_sell' },
{ title: 'تعداد سفارش', dataIndex: 'order_count' },
];
const orderColumns = [
{ title: 'شماره سفارش', dataIndex: 'name' },
{ title: 'مشتری', dataIndex: 'customer' },
{ title: 'وزن', dataIndex: 'w' },
{ title: 'وضعیت', dataIndex: 'sts_str' },
{ title: 'تاریخ', dataIndex: 'caj' },
];
function tagColor(c: string) {
return { success: 'green', warning: 'orange', danger: 'red', primary: 'blue' }[c] ?? '';
}
onMounted(async () => {
try {
loading.value = true;
const { data } = await api.get('get-analytics');
Object.assign(omdeData, data);
// legacy sorts both lists client-side after the fetch
omdeData.reagent.sort((a: any, b: any) => Number(b.grams_sell) - Number(a.grams_sell));
omdeData.lastOrder.sort((a: any, b: any) => Number(b.w) - Number(a.w));
} catch (e) {
console.error(e);
} finally {
loading.value = false;
}
});
</script>
<style scoped>
/* .grid-2/.grid-3 now come from the global utilities.less (dedup) */
.mt-4 {
margin-top: 1rem;
}
</style>