Files
boursecu_user/src/views/base/home/components/AssetsSection.vue
T

93 lines
3.3 KiB
Vue
Raw Normal View History

2026-05-14 13:44:43 +03:30
<template>
<div :class="plain ? 'py-2' : 'bg-primary rounded-lg p-2 py-3 mt-2'">
<div
v-if="meta?.has_count_based_products"
:class="rowClass"
class="flex justify-center w-full z-20"
>
2026-05-14 13:44:43 +03:30
محصولات:
2026-06-09 21:04:22 +03:30
<div class="text-l mr-2 font-bold">{{ countBasedInventory }} عدد</div>
2026-05-14 13:44:43 +03:30
</div>
2026-06-09 21:04:22 +03:30
<template v-if="meta?.single_metal && primaryMetalTotal">
<div :class="[rowClass, meta?.has_count_based_products ? 'mt-2' : '']" class="flex justify-center w-full z-20">
2026-06-09 21:04:22 +03:30
{{ primaryMetalTotal.label }}:
<div class="text-l mr-2 font-bold">{{ formatMetalTotal(primaryMetalTotal) }}</div>
<BasicIcon
icon="vuesax-linear:info-circle"
size="18"
:color="iconColor"
2026-06-10 18:40:29 +03:30
@click="$emit('openGoldModal', primaryMetalTotal)"
2026-06-09 21:04:22 +03:30
/>
</div>
</template>
<template v-else>
<div
v-for="(metal, index) in metalTotals"
2026-06-09 21:04:22 +03:30
:key="metal.metal_id"
:class="[rowClass, index > 0 || meta?.has_count_based_products ? 'mt-2' : '']"
class="flex justify-center w-full z-20"
2026-06-09 21:04:22 +03:30
>
{{ metal.label }}:
<div class="text-l mr-2 font-bold">{{ formatMetalTotal(metal) }}</div>
<BasicIcon
v-if="metal.metal_id === metalTotals[0]?.metal_id"
icon="vuesax-linear:info-circle"
size="18"
:color="iconColor"
2026-06-10 18:40:29 +03:30
@click="$emit('openGoldModal', metal)"
2026-06-09 21:04:22 +03:30
/>
</div>
</template>
<div :class="[rowClass, 'mt-2']" class="flex justify-center w-full z-20">
2026-05-14 13:44:43 +03:30
دارایی ریالی:
2026-06-10 18:40:29 +03:30
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(totalRialValue) }} ریال</div>
<BasicIcon
icon="vuesax-linear:info-circle"
size="18"
:color="iconColor"
@click="$emit('openRialModal')"
/>
2026-05-14 13:44:43 +03:30
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
2026-05-14 13:44:43 +03:30
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
2026-06-09 21:04:22 +03:30
import { usePriceWithoutType } from '@/utils/usePrice'
import { useWalletAssets } from '@/composables/useWalletAssets'
import type { WalletMetalTotal } from '@/models/walletAssets'
2026-06-10 11:36:45 +03:30
import { resolveSummaryMetalWeight } from '@/utils/productAssets'
2026-05-14 13:44:43 +03:30
const props = withDefaults(
defineProps<{
plain?: boolean
}>(),
{ plain: false }
)
/** Display-only — wallet assets are loaded once in useHomePageData.initHomePageData() */
const { assetsSummary } = useWalletAssets()
2026-05-14 13:44:43 +03:30
defineEmits<{
2026-06-10 18:40:29 +03:30
openGoldModal: [metal: WalletMetalTotal]
2026-05-14 13:44:43 +03:30
openRialModal: []
}>()
2026-06-09 21:04:22 +03:30
const rowClass = computed(() => (props.plain ? 'text-primary' : 'text-tertiary'))
const iconColor = computed(() => (props.plain ? 'primary' : 'tertiary'))
2026-06-09 21:04:22 +03:30
const meta = computed(() => assetsSummary.value?.meta)
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
const primaryMetalTotal = computed(() => metalTotals.value[0])
2026-06-10 18:40:29 +03:30
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
2026-06-09 21:04:22 +03:30
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
const countBasedInventory = computed(() =>
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
)
function formatMetalTotal(metal: WalletMetalTotal) {
2026-06-10 11:36:45 +03:30
return `${resolveSummaryMetalWeight(metal, inventoryCards.value)}${metal.unit}`
2026-06-09 21:04:22 +03:30
}
</script>