diff --git a/src/utils/productAssets.ts b/src/utils/productAssets.ts index eccd939..653d9c9 100644 --- a/src/utils/productAssets.ts +++ b/src/utils/productAssets.ts @@ -426,6 +426,48 @@ export function formatPortfolioProfitPercent(percent?: number | null): string { return `${sign}${value.toFixed(2)}٪` } +/** متن توضیح مودال سود/زیان تحقق‌نیافته طلا */ +export function formatPortfolioProfitInfoText( + portfolio: { + average_buy_price?: number | null + live_gold_price?: number | null + cost_basis_rial?: number | null + gold_weight?: number | null + gold_rial_value?: number | null + unrealized_profit_rial?: number | null + unrealized_profit_percent?: number | null + }, + weightUnit = 'گرم' +): string { + const lines: string[] = [] + + if (portfolio.average_buy_price != null && portfolio.average_buy_price > 0) { + lines.push(`میانگین قیمت خرید: ${formatRialNumber(portfolio.average_buy_price)} ریال`) + } + if (portfolio.live_gold_price != null && portfolio.live_gold_price > 0) { + lines.push(`قیمت فعلی طلا: ${formatRialNumber(portfolio.live_gold_price)} ریال`) + } + if (portfolio.gold_weight != null && portfolio.gold_weight > 0) { + lines.push(`وزن طلای شما: ${formatWeightAmount(portfolio.gold_weight)} ${weightUnit}`) + } + if (portfolio.cost_basis_rial != null && portfolio.cost_basis_rial > 0) { + lines.push(`بهای تمام‌شده طلا: ${formatRialNumber(portfolio.cost_basis_rial)} ریال`) + } + if (portfolio.gold_rial_value != null && portfolio.gold_rial_value > 0) { + lines.push(`ارزش فعلی طلا: ${formatRialNumber(portfolio.gold_rial_value)} ریال`) + } + if (portfolio.unrealized_profit_rial != null) { + const pct = formatPortfolioProfitPercent(portfolio.unrealized_profit_percent) + lines.push( + `سود/زیان تحقق‌نیافته: ${formatPortfolioProfitText(portfolio.unrealized_profit_rial)}${pct ? ` (${pct})` : ''}` + ) + } + + lines.push('محاسبه بر اساس میانگین وزنی قیمت خرید و قیمت لحظه‌ای بازار است.') + + return lines.join('\n') +} + /** متن توضیح مودال دارایی ریالی */ export function formatRialAssetsInfoText( cashWallet: number, diff --git a/src/views/base/home/components/PortfolioOverview.vue b/src/views/base/home/components/PortfolioOverview.vue index 9b559eb..9cee976 100644 --- a/src/views/base/home/components/PortfolioOverview.vue +++ b/src/views/base/home/components/PortfolioOverview.vue @@ -16,9 +16,21 @@ 'portfolio-overview__profit--down': profitTone === 'loss', }" > - {{ profitText }} - {{ profitPercent }} - سود/زیان تحقق‌نیافته طلا +
+ {{ profitText }} + {{ profitPercent }} +
+
+ سود/زیان تحقق‌نیافته طلا + +
@@ -36,17 +48,16 @@
-

- بر اساس میانگین خرید {{ usePriceWithoutType(averageBuyPrice) }} ریال و قیمت فعلی - {{ usePriceWithoutType(liveGoldPrice) }} ریال -