179 lines
4.6 KiB
TypeScript
179 lines
4.6 KiB
TypeScript
import type { BaseTableColumn } from '@core/type/baseTable'
|
|
import { toJalali } from '@core/utils/useDataTime'
|
|
import CustomTag from '@/components/CustomTag.vue'
|
|
import { usePrice } from '@core/utils/usePrice'
|
|
import { formatAmountWithUnit } from '@/utils/weightUnit'
|
|
|
|
export type OrderMetalColumn = { metal_id: number; label: string; display_unit?: string }
|
|
|
|
export function buildOrderColumns(_metals: OrderMetalColumn[] = []): BaseTableColumn[] {
|
|
return [
|
|
{
|
|
title: 'ردیف',
|
|
dataIndex: 'id',
|
|
key: 'id',
|
|
filterable: false,
|
|
sortable: false,
|
|
customRender: (record: any) => {
|
|
return record.index + 1
|
|
}
|
|
},
|
|
{
|
|
title: 'کد سفارش',
|
|
dataIndex: 'id',
|
|
key: 'id',
|
|
type: 'Number'
|
|
},
|
|
{
|
|
title: 'نوع سفارش',
|
|
dataIndex: 'direction',
|
|
key: 'direction',
|
|
filterable: false,
|
|
customRender: ({ record }) => {
|
|
switch (record.direction) {
|
|
case 2:
|
|
return (
|
|
<div class="flex justify-center">
|
|
<CustomTag textColor="#C53030" bgColor="#FECACA">
|
|
فروش
|
|
</CustomTag>
|
|
</div>
|
|
)
|
|
case 1:
|
|
return (
|
|
<div class="flex justify-center">
|
|
<CustomTag textColor="#25855A" bgColor="#E3F4E9">
|
|
خرید
|
|
</CustomTag>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
},
|
|
{
|
|
title: 'نام و نام خانوادگی',
|
|
dataIndex: 'customer.name',
|
|
key: 'customer.name',
|
|
type: 'Text'
|
|
},
|
|
{
|
|
title: 'شماره موبایل',
|
|
dataIndex: 'customer.mobile',
|
|
key: 'customer.mobile',
|
|
type: 'Number'
|
|
},
|
|
{
|
|
title: 'نوع فلز',
|
|
dataIndex: 'order_metal_label',
|
|
key: 'order_metal_label',
|
|
type: 'Text',
|
|
filterable: false,
|
|
customRender({ record }) {
|
|
return (
|
|
<div class="flex justify-center">
|
|
<CustomTag textColor="#ca8a04" bgColor="#fef3c7" class={'font-bold px-6'}>
|
|
{record.order_metal_label ?? '-'}
|
|
</CustomTag>
|
|
</div>
|
|
)
|
|
}
|
|
},
|
|
{
|
|
title: 'مقدار',
|
|
dataIndex: 'amount',
|
|
key: 'amount',
|
|
type: 'Text',
|
|
customRender({ record }) {
|
|
const amount = record.amount_display ?? record.amount
|
|
return formatAmountWithUnit(amount, record.amount_unit)
|
|
}
|
|
},
|
|
{
|
|
title: 'کارمزد',
|
|
dataIndex: 'service_charge',
|
|
key: 'service_charge',
|
|
type: 'Number',
|
|
customRender({ record }) {
|
|
const value = record.service_charge
|
|
if (value == null || value === '') {
|
|
return '-'
|
|
}
|
|
return formatAmountWithUnit(Number(value), record.amount_unit)
|
|
}
|
|
},
|
|
{
|
|
title: 'قیمت زمان معامله (ریال)',
|
|
dataIndex: 'price',
|
|
key: 'price',
|
|
type: 'Text',
|
|
customRender({ record }) {
|
|
return usePrice(record.price ?? 0, true, '')
|
|
}
|
|
},
|
|
{
|
|
title: 'قیمت کل برای مشتری (ریال)',
|
|
dataIndex: 'total_price',
|
|
key: 'total_price',
|
|
type: 'Text',
|
|
customRender(data) {
|
|
return usePrice(data.record?.total_price ?? 0, true, '')
|
|
}
|
|
},
|
|
{
|
|
title: 'وضعیت',
|
|
dataIndex: 'sts',
|
|
key: 'sts',
|
|
filterable: false,
|
|
customRender: ({ record }) => {
|
|
switch (record.sts) {
|
|
case 1:
|
|
return (
|
|
<div class="flex justify-center">
|
|
<CustomTag textColor="#ca8a04" bgColor="#fef3c7">
|
|
{record.sts_str}
|
|
</CustomTag>
|
|
</div>
|
|
)
|
|
case 2:
|
|
return (
|
|
<div class="flex justify-center">
|
|
<CustomTag textColor="#25855A" bgColor="#E3F4E9">
|
|
{record.sts_str}
|
|
</CustomTag>
|
|
</div>
|
|
)
|
|
default:
|
|
return (
|
|
<div class="flex justify-center">
|
|
<CustomTag textColor="#C53030" bgColor="#FECACA">
|
|
{record.sts_str}
|
|
</CustomTag>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
},
|
|
{
|
|
title: 'تاریخ ثبت',
|
|
dataIndex: 'created_at',
|
|
key: 'created_at',
|
|
type: 'DateTime',
|
|
customRender: (record: any) => {
|
|
return toJalali(record.record.created_at)
|
|
}
|
|
},
|
|
{
|
|
title: 'عملیات',
|
|
dataIndex: 'action',
|
|
key: 'action',
|
|
slot: 'action',
|
|
fixed: 'right',
|
|
filterable: false
|
|
}
|
|
]
|
|
}
|
|
|
|
export function getOrderColumns(): BaseTableColumn[] {
|
|
return buildOrderColumns()
|
|
}
|