2024-02-29 11:04:38 +08:00
|
|
|
<template>
|
2024-03-04 09:59:48 +08:00
|
|
|
<div v-if="columns?.length">
|
2024-03-22 16:47:44 +08:00
|
|
|
<DynamicTable row-key="id"
|
2024-03-06 11:39:41 +08:00
|
|
|
header-title="原材料出入库记录"
|
2024-03-07 14:11:29 +08:00
|
|
|
title-tooltip="要创建入库记录,必须创建入库产品,产品所属公司。"
|
2024-03-04 17:31:39 +08:00
|
|
|
:data-request="Api.materialsInOut.materialsInOutList"
|
2024-03-04 09:59:48 +08:00
|
|
|
:columns="columns"
|
|
|
|
bordered
|
|
|
|
:scroll="{ x: 1920 }"
|
2024-03-22 16:47:44 +08:00
|
|
|
size="small">
|
2024-03-04 09:59:48 +08:00
|
|
|
<template #toolbar>
|
2024-03-22 16:47:44 +08:00
|
|
|
<a-button type="primary"
|
2024-03-06 11:39:41 +08:00
|
|
|
:disabled="!$auth('materials_inventory:history_in_out:create')"
|
2024-03-22 16:47:44 +08:00
|
|
|
@click="openEditModal({})">
|
2024-03-04 09:59:48 +08:00
|
|
|
新增
|
2024-03-22 16:47:44 +08:00
|
|
|
</a-button> <a-button type="primary"
|
|
|
|
@click="openExportModal">导出</a-button>
|
2024-03-04 09:59:48 +08:00
|
|
|
</template>
|
|
|
|
</DynamicTable>
|
2024-03-22 16:47:44 +08:00
|
|
|
|
2024-03-04 09:59:48 +08:00
|
|
|
</div>
|
2024-02-29 11:04:38 +08:00
|
|
|
</template>
|
|
|
|
|
2024-03-22 16:47:44 +08:00
|
|
|
<script setup
|
|
|
|
lang="tsx">
|
2024-03-04 09:59:48 +08:00
|
|
|
import { useTable } from '@/components/core/dynamic-table';
|
2024-03-06 17:13:27 +08:00
|
|
|
import {
|
|
|
|
baseColumns,
|
|
|
|
type TableColumnItem,
|
|
|
|
type TableListItem,
|
|
|
|
} from './columns';
|
2024-03-04 09:59:48 +08:00
|
|
|
import Api from '@/api/';
|
2024-03-22 16:47:44 +08:00
|
|
|
import { onMounted, ref, type FunctionalComponent } from 'vue';
|
2024-03-04 09:59:48 +08:00
|
|
|
import { useFormModal, useModal } from '@/hooks/useModal';
|
2024-03-07 14:11:29 +08:00
|
|
|
import { Button } from 'ant-design-vue';
|
2024-03-05 22:26:43 +08:00
|
|
|
import { formSchemas } from './formSchemas';
|
2024-03-11 13:41:59 +08:00
|
|
|
|
2024-03-04 09:59:48 +08:00
|
|
|
import AttachmentManage from '@/components/business/attachment-manage/index.vue';
|
|
|
|
import AttachmentUpload from '@/components/business/attachment-upload/index.vue';
|
2024-03-22 16:47:44 +08:00
|
|
|
import { useExportExcelModal, jsonToSheetXlsx } from '@/components/basic/excel';
|
|
|
|
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
|
|
|
|
import { formatToDate } from '@/utils/dateUtil';
|
2024-02-29 11:04:38 +08:00
|
|
|
defineOptions({
|
2024-03-04 17:31:39 +08:00
|
|
|
name: 'MaterialsInOut',
|
2024-02-29 11:04:38 +08:00
|
|
|
});
|
2024-03-07 16:27:48 +08:00
|
|
|
const [DynamicTable, dynamicTableInstance] = useTable({ formProps: { autoSubmitOnEnter: true } });
|
2024-03-04 09:59:48 +08:00
|
|
|
const [showModal] = useFormModal();
|
2024-03-22 16:47:44 +08:00
|
|
|
const exportExcelModal = useExportExcelModal();
|
2024-03-04 09:59:48 +08:00
|
|
|
const [fnModal] = useModal();
|
|
|
|
const isUploadPopupVisiable = ref(false);
|
|
|
|
|
|
|
|
let columns = ref<TableColumnItem[]>();
|
|
|
|
onMounted(() => {
|
2024-03-04 14:17:40 +08:00
|
|
|
columns.value = [
|
|
|
|
...baseColumns,
|
|
|
|
{
|
|
|
|
title: '附件',
|
2024-03-06 17:13:27 +08:00
|
|
|
width: 40,
|
|
|
|
maxWidth: 40,
|
2024-03-04 14:17:40 +08:00
|
|
|
hideInSearch: true,
|
|
|
|
fixed: 'right',
|
|
|
|
dataIndex: 'files',
|
|
|
|
customRender: ({ record }) => <FilesRender {...record} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '操作',
|
2024-03-06 11:39:41 +08:00
|
|
|
maxWidth: 80,
|
|
|
|
width: 80,
|
2024-03-04 14:17:40 +08:00
|
|
|
dataIndex: 'ACTION',
|
|
|
|
hideInSearch: true,
|
|
|
|
fixed: 'right',
|
|
|
|
actions: ({ record }) => [
|
|
|
|
{
|
|
|
|
icon: 'ant-design:edit-outlined',
|
|
|
|
tooltip: '编辑',
|
|
|
|
auth: {
|
2024-03-06 11:39:41 +08:00
|
|
|
perm: 'materials_inventory:history_in_out:update',
|
2024-03-04 14:17:40 +08:00
|
|
|
effect: 'disable',
|
2024-03-04 09:59:48 +08:00
|
|
|
},
|
2024-03-04 14:17:40 +08:00
|
|
|
onClick: () => openEditModal(record),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'ant-design:delete-outlined',
|
|
|
|
color: 'red',
|
|
|
|
tooltip: '删除此记录',
|
2024-03-06 11:39:41 +08:00
|
|
|
auth: 'materials_inventory:history_in_out:delete',
|
2024-03-04 14:17:40 +08:00
|
|
|
popConfirm: {
|
|
|
|
title: '你确定要删除吗?',
|
|
|
|
placement: 'left',
|
|
|
|
onConfirm: () => delRowConfirm(record.id),
|
2024-03-04 09:59:48 +08:00
|
|
|
},
|
2024-03-04 14:17:40 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'ant-design:cloud-upload-outlined',
|
|
|
|
tooltip: '上传附件',
|
|
|
|
onClick: () => openAttachmentUploadModal(record),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2024-03-04 09:59:48 +08:00
|
|
|
});
|
2024-03-22 16:47:44 +08:00
|
|
|
|
|
|
|
const openExportModal = () => {
|
|
|
|
exportExcelModal.openModal({
|
|
|
|
onOk: ({ filename, bookType }) => {
|
|
|
|
const tableData: TableListItem[] = dynamicTableInstance.tableData;
|
|
|
|
let exportData: any[] = []
|
|
|
|
for (let item of tableData) {
|
|
|
|
exportData.push({
|
|
|
|
projectName:item.project?.name,
|
|
|
|
inOrOut: item.inOrOut === MaterialsInOutEnum.In ? '入库' : '出库',
|
|
|
|
inventoryNumber:item.inventoryNumber,
|
|
|
|
time:formatToDate(item.time),
|
|
|
|
company:item.product?.company?.name,
|
|
|
|
productName:item.product?.name,
|
|
|
|
productSpecification:item.product?.productSpecification,
|
|
|
|
unit:item.product?.unit?.label,
|
|
|
|
quantity:item.quantity,
|
|
|
|
unitPrice:parseFloat(item.unitPrice),
|
|
|
|
amount:parseFloat(item.amount),
|
|
|
|
agent:item.agent,
|
|
|
|
issuanceNumber:item.issuanceNumber,
|
|
|
|
remark:item.remark
|
|
|
|
})
|
|
|
|
}
|
|
|
|
jsonToSheetXlsx({
|
|
|
|
data: exportData,
|
|
|
|
header: {
|
|
|
|
inOrOut: '出/入库',
|
|
|
|
inventoryNumber: '出入库单号',
|
|
|
|
time: '时间',
|
|
|
|
projectName:'项目',
|
|
|
|
company: '公司',
|
|
|
|
productName: '产品名',
|
|
|
|
productSpecification: "产品规格",
|
|
|
|
unit: '单位',
|
|
|
|
quantity: '数量',
|
|
|
|
unitPrice: '单价',
|
|
|
|
amount: '金额',
|
|
|
|
agent: '经办人',
|
|
|
|
issuanceNumber: '领料单号',
|
|
|
|
remark: '备注'
|
|
|
|
},
|
|
|
|
filename,
|
|
|
|
write2excelOpts: {
|
|
|
|
bookType,
|
|
|
|
},
|
|
|
|
json2sheetOpts: {
|
|
|
|
// 指定顺序
|
|
|
|
header: [
|
|
|
|
'inOrOut', 'inventoryNumber', 'time','projectName', 'company', 'productName', 'productSpecification', 'unit', 'quantity',
|
|
|
|
'unitPrice', 'amount', 'agent', 'issuanceNumber', 'remark'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2024-03-04 14:17:40 +08:00
|
|
|
const openAttachmentUploadModal = async (record: TableListItem) => {
|
2024-03-05 22:26:43 +08:00
|
|
|
isUploadPopupVisiable.value = true;
|
|
|
|
fnModal.show({
|
|
|
|
width: 800,
|
|
|
|
title: `上传附件: ${record.id}`,
|
|
|
|
content: () => {
|
|
|
|
return (
|
|
|
|
<AttachmentUpload
|
|
|
|
onClose={handleUploadClose}
|
2024-03-08 13:19:09 +08:00
|
|
|
bussinessModule="materialsInOut"
|
|
|
|
bussinessRecordId={record.id}
|
2024-03-05 22:26:43 +08:00
|
|
|
afterUploadCallback={(files) => {
|
|
|
|
afterUploadCallback(files, record.id);
|
|
|
|
}}
|
|
|
|
></AttachmentUpload>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
destroyOnClose: true,
|
|
|
|
open: isUploadPopupVisiable.value,
|
|
|
|
footer: null,
|
|
|
|
});
|
2024-03-04 09:59:48 +08:00
|
|
|
};
|
|
|
|
const handleUploadClose = (hasSuccess: boolean) => {
|
|
|
|
fnModal.hide();
|
|
|
|
isUploadPopupVisiable.value = false;
|
|
|
|
};
|
|
|
|
const afterUploadCallback = async (
|
|
|
|
files: { filename: { path: string; id: number } }[],
|
|
|
|
id: number,
|
|
|
|
) => {
|
2024-03-06 11:39:41 +08:00
|
|
|
await Api.materialsInOut.materialsInOutUpdate(
|
|
|
|
{ id },
|
|
|
|
{ fileIds: files.map((item) => item.filename.id) },
|
|
|
|
);
|
2024-03-04 09:59:48 +08:00
|
|
|
dynamicTableInstance?.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description 打开新增/编辑弹窗
|
|
|
|
*/
|
|
|
|
const openEditModal = async (record: Partial<TableListItem>) => {
|
2024-03-05 22:26:43 +08:00
|
|
|
const [formRef] = await showModal({
|
|
|
|
modalProps: {
|
|
|
|
title: `${record.id ? '编辑' : '新增'}出入库记录`,
|
|
|
|
width: '50%',
|
|
|
|
onFinish: async (values) => {
|
2024-03-06 11:39:41 +08:00
|
|
|
const params = {
|
2024-03-05 22:26:43 +08:00
|
|
|
...values,
|
|
|
|
// signingDate: formatToDate(values.signingDate),
|
|
|
|
// deliveryDeadline: formatToDate(values.deliveryDeadline),
|
|
|
|
};
|
|
|
|
if (record.id) {
|
2024-03-06 11:39:41 +08:00
|
|
|
await Api.materialsInOut.materialsInOutUpdate(
|
|
|
|
{ id: record.id },
|
|
|
|
params as API.MaterialsInOutUpdateDto,
|
|
|
|
);
|
2024-03-05 22:26:43 +08:00
|
|
|
} else {
|
2024-03-06 11:39:41 +08:00
|
|
|
await Api.materialsInOut.materialsInOutCreate(params as API.MaterialsInOutDto);
|
2024-03-05 22:26:43 +08:00
|
|
|
}
|
|
|
|
dynamicTableInstance?.reload();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
formProps: {
|
|
|
|
labelWidth: 100,
|
2024-03-06 17:13:27 +08:00
|
|
|
schemas: formSchemas(!!record.id),
|
2024-03-05 22:26:43 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
// 如果是编辑的话,需要获取详情
|
|
|
|
if (record.id) {
|
2024-03-06 11:39:41 +08:00
|
|
|
const info = await Api.materialsInOut.materialsInOutInfo({ id: record.id });
|
2024-03-05 22:26:43 +08:00
|
|
|
formRef?.setFieldsValue({
|
|
|
|
...info,
|
|
|
|
});
|
|
|
|
}
|
2024-03-04 09:59:48 +08:00
|
|
|
};
|
|
|
|
const delRowConfirm = async (record) => {
|
2024-03-06 11:39:41 +08:00
|
|
|
await Api.materialsInOut.materialsInOutDelete({ id: record });
|
2024-03-04 09:59:48 +08:00
|
|
|
dynamicTableInstance?.reload();
|
|
|
|
};
|
|
|
|
|
2024-03-06 11:39:41 +08:00
|
|
|
const FilesRender: FunctionalComponent<TableListItem> = (materialsInOut: TableListItem) => {
|
2024-03-04 09:59:48 +08:00
|
|
|
const [fnModal] = useModal();
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
onClick={() => {
|
2024-03-06 11:39:41 +08:00
|
|
|
openFilesManageModal(fnModal, materialsInOut);
|
2024-03-04 09:59:48 +08:00
|
|
|
}}
|
|
|
|
>
|
2024-03-06 11:39:41 +08:00
|
|
|
{materialsInOut.files?.length || 0}
|
2024-03-04 09:59:48 +08:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-03-06 11:39:41 +08:00
|
|
|
const openFilesManageModal = (fnModal, tableData: TableListItem) => {
|
|
|
|
const fileIds = tableData.files?.map((item) => item.id) || [];
|
|
|
|
fnModal.show({
|
|
|
|
width: 1200,
|
|
|
|
title: `附件管理`,
|
|
|
|
content: () => {
|
|
|
|
return (
|
|
|
|
<AttachmentManage
|
|
|
|
fileIds={fileIds}
|
|
|
|
onDelete={(unlinkIds) => unlinkAttachments(tableData.id, unlinkIds)}
|
|
|
|
></AttachmentManage>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
destroyOnClose: true,
|
|
|
|
footer: null,
|
|
|
|
});
|
2024-03-04 09:59:48 +08:00
|
|
|
};
|
|
|
|
const unlinkAttachments = async (id: number, unlinkIds: number[]) => {
|
2024-03-06 11:39:41 +08:00
|
|
|
await Api.materialsInOut.unlinkAttachments({ id }, { fileIds: unlinkIds });
|
2024-03-04 09:59:48 +08:00
|
|
|
dynamicTableInstance?.reload();
|
|
|
|
};
|
2024-02-29 11:04:38 +08:00
|
|
|
</script>
|
|
|
|
|
2024-03-22 16:47:44 +08:00
|
|
|
<style lang="less"
|
|
|
|
scoped></style>
|