Files
boursecu_admin/src/pages/menuPages/customers/base/hooks/customerColumns.tsx
T
2026-07-23 22:24:26 +03:30

167 lines
5.0 KiB
TypeScript

import type { BaseTableColumn } from '@core/type/baseTable'
import CustomTag from '@/components/CustomTag.vue'
import { usePrice } from '@core/utils/usePrice'
import { getCashBalance } from '@/components/mobile/utils/wallet'
import { customerWalletMetalBalanceTitle } from '@/utils/adminMetalLabels'
import { formatMetalDisplayValue, metalCellValue } from '@/utils/metalWeight'
import type { AccountingProvider } from '@/utils/config'
import CustomerPresenceCell from '@/pages/menuPages/customers/base/components/CustomerPresenceCell.vue'
export type CustomerMetalColumn = { metal_id: number; label: string; display_unit?: string }
export type CustomerColumnOptions = {
accountingProvider?: AccountingProvider
}
function accountingCodeColumn(provider: AccountingProvider | undefined): BaseTableColumn | null {
if (provider === 'pargar' || provider === 'tahesab' || provider === 'zarin') {
return {
title: 'کد حسابداری',
dataIndex: provider === 'pargar' ? 'pargar_account_id' : 'moshtari_code',
key: 'accounting_code',
type: 'Text',
filterable: false,
slot: 'accountingCode'
}
}
return null
}
export function buildCustomerColumns(
metals: CustomerMetalColumn[] = [],
options: CustomerColumnOptions = {}
): BaseTableColumn[] {
const accountingColumn = accountingCodeColumn(options.accountingProvider)
const baseColumns: BaseTableColumn[] = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
filterable: false,
sortable: false,
customRender: (record: any) => {
return record.index + 1
}
},
{
title: 'کد کاربری',
dataIndex: 'id',
key: 'id',
type: 'Number'
},
...(accountingColumn ? [accountingColumn] : []),
{
title: 'نام و نام خانوادگی',
dataIndex: 'name',
key: 'name',
type: 'Text'
},
{
title: 'شماره موبایل',
dataIndex: 'mobile',
key: 'mobile',
type: 'Number'
},
{
title: 'کد معرف',
dataIndex: 'referral_id',
key: 'referral_id',
type: 'Text'
},
{
title: 'موجودی ریالی (ریال)',
dataIndex: 'wallet.cash',
key: 'wallet.cash',
type: 'Number',
customRender(data) {
return usePrice(getCashBalance(data.record?.wallet, { walletCash: data.record?.wallet_cash }), true, '')
}
}
]
const metalColumns: BaseTableColumn[] =
metals.length > 0
? metals.map((metal) => ({
title: customerWalletMetalBalanceTitle(metal.metal_id, metal.label),
dataIndex: `wallet_metal_gold_${metal.metal_id}`,
key: `wallet_metal_${metal.metal_id}`,
type: 'Number',
filterable: false,
customRender(data) {
const value = metalCellValue(data.record, metal.metal_id, 'wallet_metal_gold')
return formatMetalDisplayValue(value, metal.metal_id)
}
}))
: [
{
title: customerWalletMetalBalanceTitle(1, 'طلا'),
dataIndex: 'wallet.gold',
key: 'wallet.gold',
type: 'Number',
filterable: false,
customRender(data) {
const value = Number(data.record?.wallet_gold ?? 0)
return formatMetalDisplayValue(value, 1)
}
}
]
return [
...baseColumns,
...metalColumns,
{
title: 'آخرین بازدید',
dataIndex: 'last_seen_at',
key: 'last_seen_at',
type: 'DateTime',
width: 130,
filterable: false,
sortable: true,
customRender: ({ record }) => <CustomerPresenceCell lastSeenAt={record.last_seen_at} />
},
{
title: 'وضعیت',
dataIndex: 'active',
key: 'status',
type: 'Boolean',
width: 132,
filterable: false,
sortable: false,
customRender: ({ record }) => {
const userOk = Boolean(record.active)
const tradeOk = Boolean(record.trade_active)
return (
<div class="flex flex-col items-center gap-1">
<CustomTag
textColor={userOk ? '#25855A' : '#C53030'}
bgColor={userOk ? '#E3F4E9' : '#FECACA'}
class="m-0 font-bold !px-2.5 !py-0 text-xs leading-6 whitespace-nowrap"
>
{userOk ? 'حساب فعال' : 'حساب غیرفعال'}
</CustomTag>
<CustomTag
textColor={tradeOk ? '#25855A' : '#C53030'}
bgColor={tradeOk ? '#E3F4E9' : '#FECACA'}
class="m-0 font-bold !px-2.5 !py-0 text-xs leading-6 whitespace-nowrap"
>
{tradeOk ? 'سفارش مجاز' : 'سفارش غیرمجاز'}
</CustomTag>
</div>
)
}
},
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
]
}
export function getCustomerColumns(): BaseTableColumn[] {
return buildCustomerColumns()
}