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

76 lines
2.8 KiB
Vue
Raw Normal View History

2026-05-14 13:44:43 +03:30
<template>
<div class="bg-primary rounded-lg p-2 py-3 mt-2">
2026-06-09 21:04:22 +03:30
<div v-if="meta?.has_count_based_products" class="flex justify-center text-tertiary 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="flex mt-2 justify-center text-tertiary w-full z-20">
{{ primaryMetalTotal.label }}:
<div class="text-l mr-2 font-bold">{{ formatMetalTotal(primaryMetalTotal) }}</div>
<BasicIcon
icon="vuesax-linear:info-circle"
size="18"
color="tertiary"
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 in metalTotals"
:key="metal.metal_id"
class="flex mt-2 justify-center text-tertiary w-full z-20"
>
{{ 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="tertiary"
2026-06-10 18:40:29 +03:30
@click="$emit('openGoldModal', metal)"
2026-06-09 21:04:22 +03:30
/>
</div>
</template>
2026-05-14 13:44:43 +03:30
<div class="flex mt-2 justify-center text-tertiary w-full z-20">
دارایی ریالی:
2026-06-10 18:40:29 +03:30
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(totalRialValue) }} ریال</div>
2026-05-14 13:44:43 +03:30
<BasicIcon @click="$emit('openRialModal')" icon="vuesax-linear:info-circle" size="18" color="tertiary" />
</div>
</div>
</template>
<script setup lang="ts">
2026-06-09 21:04:22 +03:30
import { computed, onMounted } 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
2026-06-09 21:04:22 +03:30
const { assetsSummary, loadWalletAssets } = 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 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)
)
onMounted(() => {
void loadWalletAssets()
})
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>