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 (
فروش
) case 1: return (
خرید
) } } }, { 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 (
{record.order_metal_label ?? '-'}
) } }, { 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 (
{record.sts_str}
) case 2: return (
{record.sts_str}
) default: return (
{record.sts_str}
) } } }, { 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() }