|
| 1 | +import { Icon } from '#components'; |
| 2 | +import type { DeviceSchema } from './schema'; |
| 3 | +import type { AugmentedColumnDef } from '~/components/common/DataTable/column'; |
| 4 | +import moment from 'moment'; |
| 5 | + |
| 6 | +const statusMap = { |
| 7 | + healthy: 'Tốt', |
| 8 | + broken: 'Hư', |
| 9 | + discarded: 'Đã thanh lý', |
| 10 | + assessing: 'Đang kiểm kê', |
| 11 | + shipping: 'Đang vận chuyển', |
| 12 | + maintaining: 'Bảo trì', |
| 13 | + borrowing: 'Đang mượn', |
| 14 | + lost: 'Mất', |
| 15 | +}; |
| 16 | + |
| 17 | +export function createColumns ({ |
| 18 | + onDeviceKindLinkClick, |
| 19 | +}: { |
| 20 | + onDeviceKindLinkClick: (id: string) => void; |
| 21 | +}): AugmentedColumnDef<DeviceSchema>[] { |
| 22 | + return [ |
| 23 | + { |
| 24 | + id: 'fullId', |
| 25 | + title: 'Mã định danh', |
| 26 | + cell: ({ row }) => |
| 27 | + h('p', { class: 'text-normal pl-3' }, [ |
| 28 | + `${row.original.kind}/${row.original.id}`.toUpperCase(), |
| 29 | + ]), |
| 30 | + enableSorting: true, |
| 31 | + }, |
| 32 | + { |
| 33 | + id: 'status', |
| 34 | + title: 'Tình trạng', |
| 35 | + cell: ({ row }) => |
| 36 | + h( |
| 37 | + 'span', |
| 38 | + { |
| 39 | + class: |
| 40 | + 'bg-gray-100 text-black rounded-sm p-1 px-2 border border-gray-200 text-normal', |
| 41 | + }, |
| 42 | + (statusMap as any)[row.original.status], |
| 43 | + ), |
| 44 | + }, |
| 45 | + { |
| 46 | + id: 'room', |
| 47 | + title: 'Phòng thí nghiệm', |
| 48 | + cell: ({ row }) => |
| 49 | + h( |
| 50 | + 'p', |
| 51 | + { |
| 52 | + class: |
| 53 | + 'line-clamp-2 text-slate-500 text-normal leading-6 font-normal', |
| 54 | + }, |
| 55 | + `${row.original.room}, ${row.original.branch}`, |
| 56 | + ), |
| 57 | + enableSorting: true, |
| 58 | + }, |
| 59 | + { |
| 60 | + id: 'price', |
| 61 | + title: 'Đơn giá (VND)', |
| 62 | + cell: ({ row }) => |
| 63 | + h( |
| 64 | + 'p', |
| 65 | + { |
| 66 | + class: |
| 67 | + 'text-slate-500 text-center text-normal leading-6 font-normal', |
| 68 | + }, |
| 69 | + row.original.price, |
| 70 | + ), |
| 71 | + enableSorting: true, |
| 72 | + }, |
| 73 | + { |
| 74 | + id: 'createdAt', |
| 75 | + title: 'Ngày nhập', |
| 76 | + cell: ({ row }) => { |
| 77 | + return h( |
| 78 | + 'span', |
| 79 | + { |
| 80 | + class: |
| 81 | + 'text-slate-500 text-center text-sm font-normal leading-tight', |
| 82 | + }, |
| 83 | + moment(row.original.createdAt).format('DD/MM/YYYY'), |
| 84 | + ); |
| 85 | + }, |
| 86 | + enableSorting: true, |
| 87 | + }, |
| 88 | + { |
| 89 | + id: 'printedAt', |
| 90 | + title: 'Ngày in', |
| 91 | + cell: ({ row }) => { |
| 92 | + return h( |
| 93 | + 'span', |
| 94 | + { |
| 95 | + class: 'text-slate-500 text-sm font-normal leading-tight', |
| 96 | + }, |
| 97 | + row.original.printedAt, |
| 98 | + ); |
| 99 | + }, |
| 100 | + enableSorting: true, |
| 101 | + }, |
| 102 | + { |
| 103 | + id: 'link', |
| 104 | + title: '', |
| 105 | + cell: ({ row }) => |
| 106 | + h( |
| 107 | + 'div', |
| 108 | + { |
| 109 | + class: 'flex justify-end items-center text-lg hover:cursor-pointer', |
| 110 | + onClick: () => onDeviceKindLinkClick(row.original.id), |
| 111 | + }, |
| 112 | + h(Icon, { name: 'i-heroicons-arrow-top-right-on-square' }), |
| 113 | + ), |
| 114 | + }, |
| 115 | + ]; |
| 116 | +} |
0 commit comments