wallet handling
This commit is contained in:
@@ -93,9 +93,47 @@ function formatRialNumber(value: number): string {
|
|||||||
return Math.round(value).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
return Math.round(value).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||||
}
|
}
|
||||||
|
|
||||||
/** متن توضیح مودال دارایی ریالی — cash_wallet + assets_rial_value */
|
/** متن توضیح مودال دارایی ریالی */
|
||||||
export function formatRialAssetsInfoText(cashWallet: number, assetsRialValue: number): string {
|
export function formatRialAssetsInfoText(cashWallet: number, metalRialValue: number): string {
|
||||||
return `مجموع کیف پول ریالی (${formatRialNumber(cashWallet)} ریال) + معادل ریالی محصولات (${formatRialNumber(assetsRialValue)} ریال)`
|
const total = cashWallet + metalRialValue
|
||||||
|
return [
|
||||||
|
`کیف پول ریالی: ${formatRialNumber(cashWallet)} ریال`,
|
||||||
|
`ارزش ریالی طلا (وزن × قیمت زنده): ${formatRialNumber(metalRialValue)} ریال`,
|
||||||
|
`مجموع: ${formatRialNumber(total)} ریال`,
|
||||||
|
].join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ارزش ریالی فلزات از وزن × قیمت زنده — fallback کلاینت قبل از deploy بکاند */
|
||||||
|
export function computeMetalRialValue(
|
||||||
|
metalTotals: Array<{ metal_id?: number; total_weight?: number }>,
|
||||||
|
liveGoldPrice: number,
|
||||||
|
livePricesByMetal?: Partial<Record<number, number>>
|
||||||
|
): number {
|
||||||
|
return metalTotals.reduce((sum, metal) => {
|
||||||
|
const weight = Number(metal.total_weight ?? 0)
|
||||||
|
if (weight <= 0) {
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
const metalId = Number(metal.metal_id ?? 0)
|
||||||
|
const unitPrice =
|
||||||
|
livePricesByMetal?.[metalId] ??
|
||||||
|
(metalId === METAL_GOLD ? liveGoldPrice : 0)
|
||||||
|
|
||||||
|
return sum + weight * unitPrice
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveAssetsRialValue(
|
||||||
|
summary: { assets_rial_value?: number; metal_totals?: Array<{ metal_id?: number; total_weight?: number }> } | null | undefined,
|
||||||
|
liveGoldPrice: number
|
||||||
|
): number {
|
||||||
|
const fromServer = Number(summary?.assets_rial_value ?? 0)
|
||||||
|
if (fromServer > 0) {
|
||||||
|
return fromServer
|
||||||
|
}
|
||||||
|
|
||||||
|
return computeMetalRialValue(summary?.metal_totals ?? [], liveGoldPrice)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatInventoryCardValue(card: {
|
export function formatInventoryCardValue(card: {
|
||||||
|
|||||||
@@ -61,8 +61,8 @@
|
|||||||
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(cashWallet) }}ریال</div>
|
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(cashWallet) }}ریال</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center mt-2 w-full z-20">
|
<div class="flex justify-center mt-2 w-full z-20">
|
||||||
معادل ریالی مجموع دارایی ها:
|
مجموع دارایی ریالی:
|
||||||
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(totalRialValue) }}ریال</div>
|
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(cashWallet + metalRialValue) }}ریال</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -108,8 +108,9 @@ import { usePriceWithoutType } from '@/utils/usePrice'
|
|||||||
import { useConfigStore } from '@/store/configStore'
|
import { useConfigStore } from '@/store/configStore'
|
||||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||||
import { resolveSummaryMetalWeight, fundPageInventoryCards } from '@/utils/productAssets'
|
import { resolveSummaryMetalWeight, fundPageInventoryCards, resolveAssetsRialValue } from '@/utils/productAssets'
|
||||||
import { useWalletStore } from '@/store/walletStore'
|
import { useWalletStore } from '@/store/walletStore'
|
||||||
|
import { getTradeBuyPrice, lastPrice } from '@/utils/price'
|
||||||
import {
|
import {
|
||||||
getProjectFundEmptyImage,
|
getProjectFundEmptyImage,
|
||||||
getProjectFundEmptyText,
|
getProjectFundEmptyText,
|
||||||
@@ -129,7 +130,9 @@ const inventoryCards = computed(() => fundPageInventoryCards(assetsSummary.value
|
|||||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||||
const primaryMetalTotal = computed(() => metalTotals.value[0])
|
const primaryMetalTotal = computed(() => metalTotals.value[0])
|
||||||
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||||
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
|
const metalRialValue = computed(() =>
|
||||||
|
resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
|
||||||
|
)
|
||||||
const countBasedInventory = computed(() =>
|
const countBasedInventory = computed(() =>
|
||||||
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
||||||
)
|
)
|
||||||
@@ -137,7 +140,7 @@ const countBasedInventory = computed(() =>
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const tasks = [loadWalletAssets(true)]
|
const tasks = [loadWalletAssets(true), getLastPrices()]
|
||||||
if (isBazretalaProject()) {
|
if (isBazretalaProject()) {
|
||||||
tasks.push(walletStore.getMyWallet())
|
tasks.push(walletStore.getMyWallet())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<div class="flex mt-2 justify-center text-tertiary w-full z-20">
|
<div class="flex mt-2 justify-center text-tertiary w-full z-20">
|
||||||
دارایی ریالی:
|
دارایی ریالی:
|
||||||
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(totalRialValue) }} ریال</div>
|
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(cashWallet) }} ریال</div>
|
||||||
<BasicIcon @click="$emit('openRialModal')" icon="vuesax-linear:info-circle" size="18" color="tertiary" />
|
<BasicIcon @click="$emit('openRialModal')" icon="vuesax-linear:info-circle" size="18" color="tertiary" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -59,7 +59,7 @@ defineEmits<{
|
|||||||
const meta = computed(() => assetsSummary.value?.meta)
|
const meta = computed(() => assetsSummary.value?.meta)
|
||||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||||
const primaryMetalTotal = computed(() => metalTotals.value[0])
|
const primaryMetalTotal = computed(() => metalTotals.value[0])
|
||||||
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
|
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||||
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
||||||
const countBasedInventory = computed(() =>
|
const countBasedInventory = computed(() =>
|
||||||
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
||||||
|
|||||||
@@ -31,9 +31,9 @@
|
|||||||
<a-divider class="!my-1" />
|
<a-divider class="!my-1" />
|
||||||
<BasicInfoItem
|
<BasicInfoItem
|
||||||
class="flex justify-between"
|
class="flex justify-between"
|
||||||
title="معادل ریالی محصولات"
|
title="ارزش ریالی طلا (وزن × قیمت زنده)"
|
||||||
is-line
|
is-line
|
||||||
:value="usePrice(assetsRialValue)"
|
:value="usePrice(metalRialValue)"
|
||||||
/>
|
/>
|
||||||
<a-divider class="!my-1" />
|
<a-divider class="!my-1" />
|
||||||
<BasicInfoItem
|
<BasicInfoItem
|
||||||
@@ -56,7 +56,8 @@ import BasicInfoItem from '@/components/BasicPacks/BasicInfoItem.vue'
|
|||||||
import { usePrice } from '@/utils/usePrice'
|
import { usePrice } from '@/utils/usePrice'
|
||||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||||
import { formatInventoryCardValue, assetSheetInventoryCards } from '@/utils/productAssets'
|
import { formatInventoryCardValue, assetSheetInventoryCards, resolveAssetsRialValue } from '@/utils/productAssets'
|
||||||
|
import { getTradeBuyPrice, lastPrice } from '@/utils/price'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
show: boolean
|
show: boolean
|
||||||
@@ -78,8 +79,10 @@ const visible = computed({
|
|||||||
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
||||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||||
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||||
const assetsRialValue = computed(() => assetsSummary.value?.assets_rial_value ?? 0)
|
const metalRialValue = computed(() =>
|
||||||
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
|
resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
|
||||||
|
)
|
||||||
|
const totalRialValue = computed(() => cashWallet.value + metalRialValue.value)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void loadWalletAssets()
|
void loadWalletAssets()
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ import {useUserStore} from '@/store/userStore'
|
|||||||
import {useWalletStore} from '@/store/walletStore'
|
import {useWalletStore} from '@/store/walletStore'
|
||||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||||
import { formatMetalAssetsInfoText, formatRialAssetsInfoText } from '@/utils/productAssets'
|
import { formatMetalAssetsInfoText, formatRialAssetsInfoText, resolveAssetsRialValue } from '@/utils/productAssets'
|
||||||
|
import {getLastPrices, getTradeBuyPrice, lastPrice, price, startLastPricePolling, stopLastPricePolling} from '@/utils/price'
|
||||||
import {useConfigStore} from '@/store/configStore'
|
import {useConfigStore} from '@/store/configStore'
|
||||||
import {useFundUserStore} from '@/store/fundStore'
|
import {useFundUserStore} from '@/store/fundStore'
|
||||||
import {usePriceWithoutType} from '../../../utils/usePrice'
|
import {usePriceWithoutType} from '../../../utils/usePrice'
|
||||||
import {getLastPrices, lastPrice, price, startLastPricePolling, stopLastPricePolling} from '@/utils/price'
|
|
||||||
import { getStoreClosedMessage, isStoreClosed } from '@/utils/storeHours'
|
import { getStoreClosedMessage, isStoreClosed } from '@/utils/storeHours'
|
||||||
import {getConstByKey} from '@/api/const'
|
import {getConstByKey} from '@/api/const'
|
||||||
import {message, Modal} from 'ant-design-vue'
|
import {message, Modal} from 'ant-design-vue'
|
||||||
@@ -228,11 +228,11 @@ function openGoldModal(metal: WalletMetalTotal) {
|
|||||||
|
|
||||||
function openRialModal() {
|
function openRialModal() {
|
||||||
const summary = assetsSummary.value
|
const summary = assetsSummary.value
|
||||||
|
const cash = summary?.cash_wallet ?? 0
|
||||||
|
const metalRial = resolveAssetsRialValue(summary, getTradeBuyPrice(lastPrice.value))
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: formatRialAssetsInfoText(
|
title: 'دارایی ریالی',
|
||||||
summary?.cash_wallet ?? 0,
|
content: formatRialAssetsInfoText(cash, metalRial),
|
||||||
summary?.assets_rial_value ?? 0
|
|
||||||
),
|
|
||||||
okText: 'متوجه شدم',
|
okText: 'متوجه شدم',
|
||||||
centered: true,
|
centered: true,
|
||||||
cancelButtonProps: {style: {display: 'none'}}
|
cancelButtonProps: {style: {display: 'none'}}
|
||||||
|
|||||||
Reference in New Issue
Block a user