2024-03-04 17:31:39 +08:00
|
|
|
import type { TableColumn } from '@/components/core/dynamic-table';
|
|
|
|
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
|
|
|
|
import { formatToDate } from '@/utils/dateUtil';
|
|
|
|
import { Tag } from 'ant-design-vue';
|
2024-03-08 13:19:09 +08:00
|
|
|
import { getProjectOptions } from './formSchemas';
|
|
|
|
import { debounce } from 'lodash-es';
|
2024-03-04 17:31:39 +08:00
|
|
|
|
|
|
|
export type TableListItem = API.MaterialsInOutEntity;
|
2024-03-06 17:13:27 +08:00
|
|
|
export type TableQueryItem = API.MaterialsInOutListParams;
|
2024-03-04 17:31:39 +08:00
|
|
|
export type TableColumnItem = TableColumn<TableListItem>;
|
|
|
|
export const baseColumns: TableColumnItem[] = [
|
2024-03-06 17:13:27 +08:00
|
|
|
{
|
2024-03-22 16:47:44 +08:00
|
|
|
title: '出入库单号',
|
2024-03-06 17:13:27 +08:00
|
|
|
width: 100,
|
|
|
|
fixed: 'left',
|
|
|
|
dataIndex: 'inventoryNumber',
|
|
|
|
customRender: ({ record }) => {
|
|
|
|
return record.inventoryNumber || '';
|
|
|
|
},
|
|
|
|
formItemProps: {
|
|
|
|
labelWidth: 120,
|
|
|
|
},
|
|
|
|
},
|
2024-03-07 11:11:01 +08:00
|
|
|
{
|
|
|
|
title: '项目',
|
|
|
|
width: 80,
|
2024-03-08 13:19:09 +08:00
|
|
|
dataIndex: 'projectId',
|
2024-03-07 11:11:01 +08:00
|
|
|
customRender: ({ record }) => {
|
|
|
|
return record?.project?.name || '';
|
|
|
|
},
|
2024-03-08 13:19:09 +08:00
|
|
|
formItemProps: {
|
2024-03-22 16:47:44 +08:00
|
|
|
component: 'Select',
|
2024-03-08 13:19:09 +08:00
|
|
|
componentProps: ({ formInstance, schema, formModel }) => ({
|
|
|
|
showSearch: true,
|
|
|
|
filterOption: false,
|
|
|
|
fieldNames: {
|
|
|
|
label: 'label',
|
|
|
|
value: 'value',
|
|
|
|
},
|
|
|
|
getPopupContainer: () => document.body,
|
|
|
|
defaultActiveFirstOption: true,
|
|
|
|
onClear: async () => {
|
|
|
|
const newSchema = {
|
|
|
|
field: schema.field,
|
|
|
|
componentProps: {
|
|
|
|
options: [] as LabelValueOptions,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const options = await getProjectOptions().finally(() => (schema.loading = false));
|
|
|
|
newSchema.componentProps.options = options;
|
|
|
|
formInstance?.updateSchema([newSchema]);
|
|
|
|
},
|
|
|
|
request: () => {
|
|
|
|
return getProjectOptions();
|
|
|
|
},
|
|
|
|
onSearch: debounce(async (keyword) => {
|
|
|
|
schema.loading = true;
|
|
|
|
const newSchema = {
|
|
|
|
field: schema.field,
|
|
|
|
componentProps: {
|
|
|
|
options: [] as LabelValueOptions,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
formInstance?.updateSchema([newSchema]);
|
|
|
|
const options = await getProjectOptions(keyword).finally(() => (schema.loading = false));
|
|
|
|
newSchema.componentProps.options = options;
|
|
|
|
formInstance?.updateSchema([newSchema]);
|
|
|
|
}, 500),
|
|
|
|
}),
|
|
|
|
},
|
2024-03-07 11:11:01 +08:00
|
|
|
},
|
2024-03-06 17:13:27 +08:00
|
|
|
{
|
|
|
|
title: '所属公司',
|
|
|
|
width: 100,
|
|
|
|
dataIndex: 'company',
|
|
|
|
customRender: ({ record }) => {
|
|
|
|
return record.product?.company?.name || '';
|
|
|
|
},
|
|
|
|
},
|
2024-03-04 17:31:39 +08:00
|
|
|
{
|
|
|
|
title: '产品名称',
|
2024-03-06 17:13:27 +08:00
|
|
|
width: 100,
|
2024-03-04 17:31:39 +08:00
|
|
|
dataIndex: 'product',
|
2024-03-06 11:39:41 +08:00
|
|
|
customRender: ({ record }) => {
|
|
|
|
return record.product?.name || '';
|
|
|
|
},
|
2024-03-04 17:31:39 +08:00
|
|
|
},
|
2024-03-06 17:13:27 +08:00
|
|
|
|
2024-03-04 17:31:39 +08:00
|
|
|
{
|
|
|
|
title: '单位',
|
2024-03-06 11:39:41 +08:00
|
|
|
width: 40,
|
2024-03-04 17:31:39 +08:00
|
|
|
hideInSearch: true,
|
|
|
|
dataIndex: 'unit',
|
|
|
|
customRender: ({ record }) => {
|
2024-03-06 17:13:27 +08:00
|
|
|
return record?.product?.unit?.label || '';
|
2024-03-04 17:31:39 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
title: '入库/出库',
|
2024-03-06 11:39:41 +08:00
|
|
|
width: 60,
|
2024-03-04 17:31:39 +08:00
|
|
|
dataIndex: 'inOrOut',
|
|
|
|
formItemProps: {
|
|
|
|
component: 'Select',
|
|
|
|
componentProps: {
|
|
|
|
options: Object.values(MaterialsInOutEnum)
|
|
|
|
.filter((value) => typeof value === 'number')
|
|
|
|
.map((item) => formatStatus(item as MaterialsInOutEnum)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
customRender: ({ record }) => {
|
|
|
|
const { color, label } = formatStatus(record.inOrOut);
|
|
|
|
return <Tag color={color}>{label}</Tag>;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '时间',
|
2024-03-06 11:39:41 +08:00
|
|
|
width: 60,
|
2024-03-04 17:31:39 +08:00
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'time',
|
2024-03-06 11:39:41 +08:00
|
|
|
formItemProps: {
|
|
|
|
component: 'MonthPicker',
|
|
|
|
},
|
2024-03-04 17:31:39 +08:00
|
|
|
customRender: ({ record }) => {
|
|
|
|
return formatToDate(record.time);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '数量',
|
|
|
|
hideInSearch: true,
|
2024-03-06 11:39:41 +08:00
|
|
|
width: 60,
|
2024-03-04 17:31:39 +08:00
|
|
|
dataIndex: 'quantity',
|
2024-03-06 17:13:27 +08:00
|
|
|
customRender: ({ record }) => {
|
|
|
|
return parseFloat(record.quantity) || 0;
|
|
|
|
},
|
2024-03-04 17:31:39 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '单价',
|
|
|
|
hideInSearch: true,
|
|
|
|
width: 80,
|
|
|
|
dataIndex: 'unitPrice',
|
2024-03-06 17:13:27 +08:00
|
|
|
customRender: ({ record }) => {
|
|
|
|
return parseFloat(record.unitPrice) || 0;
|
|
|
|
},
|
2024-03-04 17:31:39 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '金额',
|
|
|
|
width: 80,
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'amount',
|
2024-03-05 22:26:43 +08:00
|
|
|
hideInSearch: true,
|
2024-03-06 17:13:27 +08:00
|
|
|
customRender: ({ record }) => {
|
|
|
|
return parseFloat(record.amount) || 0;
|
|
|
|
},
|
2024-03-04 17:31:39 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '经办人',
|
|
|
|
width: 80,
|
|
|
|
dataIndex: 'agent',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '领料单号',
|
|
|
|
width: 80,
|
|
|
|
dataIndex: 'issuanceNumber',
|
|
|
|
},
|
2024-03-07 11:11:01 +08:00
|
|
|
|
2024-03-04 17:31:39 +08:00
|
|
|
{
|
|
|
|
title: '备注',
|
|
|
|
width: 80,
|
|
|
|
dataIndex: 'remark',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export function formatStatus(status: MaterialsInOutEnum): {
|
|
|
|
color: string;
|
|
|
|
label: string;
|
|
|
|
value: number;
|
|
|
|
} {
|
|
|
|
switch (status) {
|
|
|
|
case MaterialsInOutEnum.In:
|
|
|
|
return {
|
|
|
|
color: 'green',
|
|
|
|
label: '入库',
|
|
|
|
value: MaterialsInOutEnum.In,
|
|
|
|
};
|
|
|
|
case MaterialsInOutEnum.Out:
|
|
|
|
return {
|
|
|
|
color: 'red',
|
|
|
|
label: '出库',
|
|
|
|
value: MaterialsInOutEnum.Out,
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return {
|
|
|
|
color: 'green',
|
|
|
|
label: '入库',
|
|
|
|
value: MaterialsInOutEnum.In,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|