95 lines
2.3 KiB
Vue
95 lines
2.3 KiB
Vue
<script setup lang="ts">
|
|||
|
|
import { computed } from 'vue';
|
||
|
|
import { theme } from 'ant-design-vue';
|
||
|
|
import type { ActivityAccountBalanceDto } from '@mento/shared';
|
||
|
|
import { formatTahesabBedBes } from '@/lib/tahesab';
|
||
|
|
|
||
|
|
const props = withDefaults(
|
||
|
|
defineProps<{
|
||
|
|
balance: ActivityAccountBalanceDto | null | undefined;
|
||
|
|
/** فشردهتر برای کارت کانبان */
|
||
|
|
compact?: boolean;
|
||
|
|
}>(),
|
||
|
|
{ compact: false },
|
||
|
|
);
|
||
|
|
|
||
|
|
const { token } = theme.useToken();
|
||
|
|
|
||
|
|
type Line = {
|
||
|
|
key: string;
|
||
|
|
label: string;
|
||
|
|
text: string;
|
||
|
|
value: number | null;
|
||
|
|
};
|
||
|
|
|
||
|
|
const lines = computed<Line[]>(() => {
|
||
|
|
const bal = props.balance;
|
||
|
|
if (!bal) return [];
|
||
|
|
const out: Line[] = [];
|
||
|
|
if (bal.rialBalance != null && Number.isFinite(bal.rialBalance)) {
|
||
|
|
out.push({
|
||
|
|
key: 'rial',
|
||
|
|
label: 'مانده ریالی',
|
||
|
|
text: `${formatTahesabBedBes(bal.rialBalance, 0)} ریال`,
|
||
|
|
value: bal.rialBalance,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
for (const w of bal.weights ?? []) {
|
||
|
|
if (w.value == null || !Number.isFinite(w.value)) continue;
|
||
|
|
out.push({
|
||
|
|
key: w.key,
|
||
|
|
label: w.label,
|
||
|
|
text: `${formatTahesabBedBes(w.value, 3)} گرم`,
|
||
|
|
value: w.value,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
return out;
|
||
|
|
});
|
||
|
|
|
||
|
|
const visible = computed(() => lines.value.length > 0);
|
||
|
|
|
||
|
|
function toneColor(value: number | null) {
|
||
|
|
if (value == null || !Number.isFinite(value) || value === 0) {
|
||
|
|
return token.value.colorTextSecondary;
|
||
|
|
}
|
||
|
|
return value < 0 ? token.value.colorError : token.value.colorSuccess;
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<template>
|
||
|
|
<a-flex
|
||
|
|
v-if="visible"
|
||
|
|
vertical
|
||
|
|
:gap="compact ? 2 : 4"
|
||
|
|
:style="{ minWidth: 0, width: '100%' }"
|
||
|
|
>
|
||
|
|
<a-typography-text
|
||
|
|
v-for="line in lines"
|
||
|
|
:key="line.key"
|
||
|
|
dir="ltr"
|
||
|
|
:style="{
|
||
|
|
margin: 0,
|
||
|
|
display: 'block',
|
||
|
|
fontSize: `${compact ? token.fontSizeSM : token.fontSize}px`,
|
||
|
|
fontWeight: 600,
|
||
|
|
color: toneColor(line.value),
|
||
|
|
textAlign: 'right',
|
||
|
|
direction: 'rtl',
|
||
|
|
}"
|
||
|
|
:title="`${line.label}: ${line.text}`"
|
||
|
|
>
|
||
|
|
<a-typography-text
|
||
|
|
type="secondary"
|
||
|
|
:style="{
|
||
|
|
fontSize: `${token.fontSizeSM}px`,
|
||
|
|
fontWeight: 500,
|
||
|
|
marginInlineEnd: '6px',
|
||
|
|
}"
|
||
|
|
>
|
||
|
|
{{ line.label }}:
|
||
|
|
</a-typography-text>
|
||
|
|
{{ line.text }}
|
||
|
|
</a-typography-text>
|
||
|
|
</a-flex>
|
||
|
|
</template>
|