fix some bug

This commit is contained in:
2026-07-01 22:28:09 +03:30
parent d2c5c20729
commit 3bf249377f
38 changed files with 1872 additions and 1610 deletions
@@ -2,20 +2,32 @@ import type { BaseTableColumn } from '@core/type/baseTable'
import { usePrice } from '@core/utils/usePrice'
import { metalLabel, walletMetalBalanceTitle } from '@/utils/adminMetalLabels'
import { formatMetalDisplayValue, metalCellValue } from '@/utils/metalWeight'
import { walletKindTagStyle } from '@/utils/walletDisplay'
export type WalletMetalColumn = { metal_id: number; label: string; display_unit?: string }
function kindTag(record: Record<string, unknown>) {
const label = String(record.wallet_kind_label ?? '—')
const style = walletKindTagStyle(record.wallet_kind as never)
return (
<span
class="inline-block rounded px-2 py-0.5 text-xs font-600"
style={{ color: style.textColor, backgroundColor: style.bgColor }}
>
{label}
</span>
)
}
export function buildWalletColumns(metals: WalletMetalColumn[] = []): BaseTableColumn[] {
const baseColumns: BaseTableColumn[] = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
key: 'row_index',
filterable: false,
sortable: false,
customRender: (record: any) => {
return record.index + 1
}
customRender: (record: { index: number }) => record.index + 1
},
{
title: 'کد کیف پول',
@@ -23,6 +35,58 @@ export function buildWalletColumns(metals: WalletMetalColumn[] = []): BaseTableC
key: 'id',
type: 'Number'
},
{
title: 'نوع کیف',
dataIndex: 'wallet_kind_label',
key: 'wallet_kind_label',
type: 'Text',
customRender(data) {
return kindTag(data.record as Record<string, unknown>)
}
},
{
title: 'موضوع / محصول',
dataIndex: 'wallet_subject',
key: 'wallet_subject',
type: 'Text',
customRender(data) {
const record = data.record
const subject = record.wallet_subject || '—'
const productId = record.product_id
if (record.wallet_kind === 'product' && productId) {
return (
<div>
<div>{subject}</div>
<div class="text-xs text-gray-500">کد محصول: {productId}</div>
</div>
)
}
if (record.wallet_kind === 'fund' && record.fund_id) {
return (
<div>
<div>{subject}</div>
<div class="text-xs text-gray-500">کد قلک: {record.fund_id}</div>
</div>
)
}
return subject
}
},
{
title: 'دسته محصول',
dataIndex: 'product_group_type',
key: 'product_group_type',
type: 'Text',
customRender(data) {
return data.record.product_group_type || '—'
}
},
{
title: 'کد مشتری',
dataIndex: 'customer.id',
key: 'customer.id',
type: 'Number'
},
{
title: 'نام مشتری',
dataIndex: 'customer.name',
@@ -30,7 +94,16 @@ export function buildWalletColumns(metals: WalletMetalColumn[] = []): BaseTableC
type: 'Text'
},
{
title: 'موجودی کیف پول (ریال)',
title: 'موبایل',
dataIndex: 'customer.mobile',
key: 'customer.mobile',
type: 'Text',
customRender(data) {
return data.record.customer?.mobile || '—'
}
},
{
title: 'موجودی ریالی',
dataIndex: 'cash',
key: 'cash',
type: 'Text',
@@ -40,34 +113,53 @@ export function buildWalletColumns(metals: WalletMetalColumn[] = []): BaseTableC
}
]
if (metals.length === 0) {
return [
...baseColumns,
{
title: metalLabel.goldWalletBalanceGram(),
dataIndex: 'gold',
key: 'gold',
type: 'Text',
customRender(data) {
const value = Number(data.record?.gold ?? 0)
return formatMetalDisplayValue(value, 1)
}
const metalColumns: BaseTableColumn[] =
metals.length === 0
? [
{
title: metalLabel.goldWalletBalanceGram(),
dataIndex: 'gold',
key: 'gold',
type: 'Text',
customRender(data) {
const value = Number(data.record?.gold ?? 0)
return formatMetalDisplayValue(value, 1)
}
}
]
: metals.map((metal) => ({
title: walletMetalBalanceTitle(metal.metal_id, metal.label),
dataIndex: `metal_gold_${metal.metal_id}`,
key: `metal_${metal.metal_id}`,
type: 'Text',
customRender(data) {
const value = metalCellValue(data.record, metal.metal_id)
return formatMetalDisplayValue(value, metal.metal_id)
}
}))
const tailColumns: BaseTableColumn[] = [
{
title: 'ارزش ریالی فلز',
dataIndex: 'gold_to_cash',
key: 'gold_to_cash',
type: 'Text',
customRender(data) {
return usePrice(data.record.gold_to_cash ?? 0, true, '')
}
},
{
title: 'جمع ارزش (ریال)',
dataIndex: 'total_rial_value',
key: 'total_rial_value',
type: 'Text',
customRender(data) {
return usePrice(data.record.total_rial_value ?? 0, true, '')
}
]
}
const metalColumns: BaseTableColumn[] = metals.map((metal) => ({
title: walletMetalBalanceTitle(metal.metal_id, metal.label),
dataIndex: `metal_gold_${metal.metal_id}`,
key: `metal_${metal.metal_id}`,
type: 'Text',
customRender(data) {
const value = metalCellValue(data.record, metal.metal_id)
return formatMetalDisplayValue(value, metal.metal_id)
}
}))
]
return [...baseColumns, ...metalColumns]
return [...baseColumns, ...metalColumns, ...tailColumns]
}
export function getWalletColumns(): BaseTableColumn[] {