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

152 lines
4.7 KiB
Vue
Raw Normal View History

2026-05-14 13:44:43 +03:30
<template>
<div :class="rootClass">
<div
v-if="!boursecuLayout && meta?.has_count_based_products"
:class="rowClass"
class="flex justify-center w-full z-20"
>
2026-05-14 13:44:43 +03:30
محصولات:
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(countBasedInventory, false) }} عدد</div>
2026-05-14 13:44:43 +03:30
</div>
<template v-if="boursecuAssetRows.length">
<div
v-for="(row, index) in boursecuAssetRows"
:key="row.id"
:class="[rowClass, index > 0 ? 'mt-2' : '']"
class="flex justify-center w-full z-20"
>
{{ row.label }}:
<div class="text-l mr-2 font-bold">{{ row.value }}</div>
<BasicIcon
v-if="row.info !== 'none'"
icon="vuesax-linear:info-circle"
size="18"
:color="iconColor"
@click="handleRowInfo(row)"
/>
</div>
</template>
<template v-else-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-if="!boursecuLayout">
2026-06-09 21:04:22 +03:30
<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>
<div :class="[rowClass, 'mt-2']" class="flex justify-center w-full z-20">
دارایی ریالی:
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(totalRialValue) }} ریال</div>
<BasicIcon
icon="vuesax-linear:info-circle"
size="18"
:color="iconColor"
@click="$emit('openRialModal')"
/>
</div>
2026-06-09 21:04:22 +03:30
</template>
2026-05-14 13:44:43 +03:30
</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'
import {
buildBoursecuHomeAssetRows,
resolveSummaryMetalWeight,
type HomeAssetRow,
} from '@/utils/productAssets'
2026-05-14 13:44:43 +03:30
const props = withDefaults(
defineProps<{
plain?: boolean
boursecuLayout?: boolean
}>(),
{ plain: false, boursecuLayout: false }
)
const emit = defineEmits<{
openGoldModal: [metal: WalletMetalTotal, modalText?: string, modalTitle?: string, modalContent?: string]
2026-05-14 13:44:43 +03:30
openRialModal: []
}>()
2026-06-09 21:04:22 +03:30
const { assetsSummary } = useWalletAssets()
const rowClass = computed(() => (props.plain ? 'text-primary' : 'text-tertiary'))
const iconColor = computed(() => (props.plain ? 'primary' : 'tertiary'))
const rootClass = computed(() => {
if (props.boursecuLayout) {
return 'assets-section assets-section--boursecu rounded-lg px-3 py-3 mt-2'
}
if (props.plain) {
return 'py-2'
}
return 'bg-primary rounded-lg p-2 py-3 mt-2'
})
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])
const boursecuAssetRows = computed(() =>
props.boursecuLayout ? buildBoursecuHomeAssetRows(assetsSummary.value) : []
)
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) {
return `${usePriceWithoutType(resolveSummaryMetalWeight(metal, inventoryCards.value), false)}${metal.unit}`
2026-06-09 21:04:22 +03:30
}
function handleRowInfo(row: HomeAssetRow) {
if (row.info === 'rial') {
emit('openRialModal')
return
}
if (row.metal) {
emit('openGoldModal', row.metal, row.modalText, row.modalTitle, row.modalContent)
}
}
2026-06-09 21:04:22 +03:30
</script>
<style scoped lang="less">
@boursecu-surface-border: #d4e3de;
.assets-section--boursecu {
background-color: #eff5f3;
border: 2px solid @boursecu-surface-border;
}
</style>