Files
boursecu_admin/src/pages/menuPages/customers/base/hooks/customerColumns.tsx
T

190 lines
5.3 KiB
TypeScript
Raw Normal View History

2026-01-24 17:45:54 +03:30
import type { BaseTableColumn } from '@core/type/baseTable'
2026-06-23 22:31:07 +03:30
import { toJalali } from '@core/utils/useDataTime'
2026-01-24 17:45:54 +03:30
import CustomTag from '@/components/CustomTag.vue'
import { usePrice } from '@core/utils/usePrice'
2026-06-23 22:31:07 +03:30
import { getCashBalance } from '@/components/mobile/utils/wallet'
import { customerWalletMetalBalanceTitle } from '@/utils/adminMetalLabels'
import { formatMetalDisplayValue, metalCellValue } from '@/utils/metalWeight'
import type { AccountingProvider } from '@/utils/config'
2026-01-24 17:45:54 +03:30
2026-06-23 22:31:07 +03:30
export type CustomerMetalColumn = { metal_id: number; label: string; display_unit?: string }
2026-01-24 17:45:54 +03:30
export type CustomerColumnOptions = {
accountingProvider?: AccountingProvider
}
function accountingCodeColumn(provider: AccountingProvider | undefined): BaseTableColumn | null {
if (provider === 'pargar' || provider === 'tahesab') {
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)
2026-06-23 22:31:07 +03:30
const baseColumns: BaseTableColumn[] = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
2026-01-24 17:45:54 +03:30
filterable: false,
sortable: false,
2026-06-23 22:31:07 +03:30
customRender: (record: any) => {
return record.index + 1
2026-01-24 17:45:54 +03:30
}
},
{
2026-06-23 22:31:07 +03:30
title: 'کد کاربری',
dataIndex: 'id',
key: 'id',
type: 'Number'
},
...(accountingColumn ? [accountingColumn] : []),
2026-06-23 22:31:07 +03:30
{
title: 'نام و نام خانوادگی',
dataIndex: 'name',
key: 'name',
type: 'Text'
2026-01-24 17:45:54 +03:30
},
{
title: 'شماره موبایل',
dataIndex: 'mobile',
2026-06-23 22:31:07 +03:30
key: 'mobile',
type: 'Number'
2026-01-24 17:45:54 +03:30
},
{
2026-06-23 22:31:07 +03:30
title: 'نوع کاربر',
dataIndex: 'type_str',
key: 'type_str',
type: 'Text'
},
{
title: 'کد معرف',
dataIndex: 'referral_id',
key: 'referral_id',
type: 'Text'
},
{
title: 'نام معرف کاربر',
dataIndex: 'referral.name',
key: 'referral.name',
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, '')
2026-01-24 17:45:54 +03:30
}
2026-06-23 22:31:07 +03:30
}
]
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,
2026-07-16 11:36:16 +03:30
/* {
2026-06-23 22:31:07 +03:30
title: 'اخرین بازدید',
dataIndex: 'last_seen_at',
key: 'last_seen_at',
type: 'DateTime',
customRender(data) {
return toJalali(data.record.last_seen_at)
}
2026-07-16 11:36:16 +03:30
},*/
2026-06-23 22:31:07 +03:30
{
title: 'وضعیت کاربر',
dataIndex: 'active',
key: 'active',
type: 'Boolean',
customRender: ({ record }) => {
return record.active ? (
<div class="flex justify-center">
<CustomTag textColor="#25855A" bgColor="#E3F4E9" class={'font-bold px-6'}>
فعال
</CustomTag>
</div>
) : (
<div class="flex justify-center">
<CustomTag textColor="#C53030" bgColor="#FECACA" class={'font-bold px-6'}>
غیر فعال
</CustomTag>
</div>
)
}
},
{
title: 'وضعیت سفارش دهی',
dataIndex: 'trade_active',
key: 'trade_active',
sortable: false,
type: 'Boolean',
customRender: ({ record }) => {
return record.trade_active ? (
<div class="flex justify-center">
<CustomTag textColor="#25855A" bgColor="#E3F4E9" class={'font-bold px-6'}>
مجاز
</CustomTag>
</div>
) : (
<div class="flex justify-center">
<CustomTag textColor="#C53030" bgColor="#FECACA" class={'font-bold px-6'}>
غیر مجاز
</CustomTag>
</div>
)
}
},
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
]
}
export function getCustomerColumns(): BaseTableColumn[] {
return buildCustomerColumns()
}