added gholak
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
import homeImg from '@/assets/img/cash_home.svg'
|
||||
import giftImg from '@/assets/img/cash_gift.svg'
|
||||
import circulationImg from '@/assets/img/cash_circulation.svg'
|
||||
import loveImg from '@/assets/img/cash_love.svg'
|
||||
import repairsImg from '@/assets/img/cash_repairs.svg'
|
||||
import savingImg from '@/assets/img/cash_saving.svg'
|
||||
import type { Fund } from '@/models/fund'
|
||||
|
||||
export const PIGGY_PRESETS = [
|
||||
@@ -15,21 +9,22 @@ export const PIGGY_PRESETS = [
|
||||
'خرید لوازم منزل',
|
||||
] as const
|
||||
|
||||
export function piggyIconForTitle(title?: string | null): string {
|
||||
/** آیکون vuesax برای عنوان قلک — بدون تصویر سهبعدی گیجکننده */
|
||||
export function piggyIconName(title?: string | null): string {
|
||||
switch ((title ?? '').trim()) {
|
||||
case 'خرید لوازم منزل':
|
||||
return homeImg
|
||||
return 'vuesax-linear:house-2'
|
||||
case 'هدیه':
|
||||
return giftImg
|
||||
return 'vuesax-linear:gift'
|
||||
case 'گردش':
|
||||
return circulationImg
|
||||
return 'vuesax-linear:airplane'
|
||||
case 'ازدواج':
|
||||
return loveImg
|
||||
return 'vuesax-linear:heart'
|
||||
case 'تعمیرات':
|
||||
return repairsImg
|
||||
return 'vuesax-linear:setting-2'
|
||||
case 'پس انداز':
|
||||
default:
|
||||
return savingImg
|
||||
return 'vuesax-linear:safe-home'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +39,35 @@ export function fundProductLabel(item?: Fund | null): string {
|
||||
return item.product?.title || (item as { product_title?: string }).product_title || '—'
|
||||
}
|
||||
|
||||
export function fundProductId(item?: Fund | null): number {
|
||||
return Number(item?.product_id ?? item?.product?.id ?? 0)
|
||||
}
|
||||
|
||||
export function formatPiggyAmount(value: number): string {
|
||||
const n = Number(value) || 0
|
||||
if (Math.abs(n) < 0.0005) return '۰'
|
||||
return n.toLocaleString('fa-IR', { maximumFractionDigits: 3 })
|
||||
}
|
||||
|
||||
export type PiggyProductGroup = {
|
||||
productId: number
|
||||
productTitle: string
|
||||
totalGold: number
|
||||
funds: Fund[]
|
||||
}
|
||||
|
||||
export function groupFundsByProduct(funds: Fund[]): PiggyProductGroup[] {
|
||||
const map = new Map<number, PiggyProductGroup>()
|
||||
for (const fund of funds) {
|
||||
const productId = fundProductId(fund) || -1
|
||||
const productTitle = fundProductLabel(fund)
|
||||
let group = map.get(productId)
|
||||
if (!group) {
|
||||
group = { productId, productTitle, totalGold: 0, funds: [] }
|
||||
map.set(productId, group)
|
||||
}
|
||||
group.funds.push(fund)
|
||||
group.totalGold += fundWalletGold(fund)
|
||||
}
|
||||
return [...map.values()].sort((a, b) => a.productTitle.localeCompare(b.productTitle, 'fa'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user