| | |
| | | <el-button |
| | | type="primary" |
| | | link |
| | | @click="downLoadFile(row)" |
| | | @click="openFileDialog(row)" |
| | | > |
| | | 附件 |
| | | </el-button> |
| | |
| | | </template> |
| | | </PIMTable> |
| | | </div> |
| | | <FileListDialog |
| | | ref="fileListRef" |
| | | v-model="fileListDialogVisible" |
| | | title="附件列表" |
| | | :showUploadButton="true" |
| | | :showDeleteButton="true" |
| | | :deleteMethod="handleDeleteFile" |
| | | :uploadMethod="handleFileUpload" |
| | | :rulesRegulationsManagementId="currentRowId" |
| | | /> |
| | | <FileList v-if="fileDialogVisible" v-model:visible="fileDialogVisible" record-type="ticket_registration" :record-id="recordId" /> |
| | | <EditModal ref="editmodalRef" @success="getTableData"></EditModal> |
| | | </div> |
| | | </template> |
| | |
| | | import { onMounted } from "vue"; |
| | | import { ElMessageBox } from "element-plus"; |
| | | import EditModal from "./Modal/EditModal.vue"; |
| | | import FileListDialog from '@/components/Dialog/FileListDialog.vue'; |
| | | import useUserStore from "@/store/modules/user.js"; |
| | | const userStore = useUserStore(); |
| | | const FileList = defineAsyncComponent(() => import("@/components/Dialog/FileList.vue")); |
| | | |
| | | defineOptions({ |
| | | name: "来票台账", |
| | |
| | | const keySet = new Set(); |
| | | let taxInclusiveSum = 0; |
| | | (param.data || []).forEach((row) => { |
| | | const key = `${row.purchaseContractNumber ?? ""}\n${row.salesContractNo ?? ""}`; |
| | | const key = `${row.purchaseContractNumber ?? ""}\n${row.salesContractNo ?? ""}\n${row.productCategory ?? ""}\n${row.specificationModel ?? ""}`; |
| | | if (keySet.has(key)) return; |
| | | keySet.add(key); |
| | | const val = Number(row.taxInclusiveTotalPrice); |
| | |
| | | onCurrentChange(page); |
| | | }; |
| | | |
| | | const downLoadFile = row => { |
| | | currentRowId.value = row.id; |
| | | if (fileListRef.value) { |
| | | fileListRef.value.open(row.commonFiles || []); |
| | | } |
| | | }; |
| | | // 打开附件弹窗 |
| | | const recordId =ref(0) |
| | | const fileDialogVisible = ref(false) |
| | | |
| | | // 上传附件(自定义上传方法) |
| | | const handleFileUpload = async () => { |
| | | if (!currentRowId.value) { |
| | | proxy.$modal.msgWarning("缺少登记ID,无法保存附件"); |
| | | return; |
| | | } |
| | | |
| | | return new Promise((resolve) => { |
| | | // 创建一个隐藏的文件输入元素 |
| | | const input = document.createElement('input'); |
| | | input.type = 'file'; |
| | | input.style.display = 'none'; |
| | | input.onchange = async (e) => { |
| | | const file = e.target.files[0]; |
| | | if (!file) { |
| | | resolve(null); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 使用 FormData 上传文件 |
| | | const formData = new FormData(); |
| | | formData.append('file', file); |
| | | formData.append('type', '4'); // type 参数,用户未指定具体值,先传空字符串 |
| | | formData.append('id', currentRowId.value); // 当前行的 id |
| | | |
| | | const uploadRes = await request({ |
| | | url: '/file/uploadByCommon', |
| | | method: 'post', |
| | | data: formData, |
| | | headers: { |
| | | 'Content-Type': 'multipart/form-data', |
| | | Authorization: `Bearer ${getToken()}` |
| | | } |
| | | }); |
| | | |
| | | if (uploadRes.code === 200) { |
| | | proxy.$modal.msgSuccess("附件上传成功"); |
| | | |
| | | // 刷新列表获取最新数据 |
| | | await new Promise((resolveRefresh) => { |
| | | // 调用 API 获取最新列表数据 |
| | | productRecordPage({ |
| | | ...filters, |
| | | current: pagination.currentPage, |
| | | size: pagination.pageSize |
| | | }).then(({ code, data }) => { |
| | | if (code === 200) { |
| | | // 更新数据列表 |
| | | dataList.value = data.records; |
| | | pagination.total = data.total; |
| | | |
| | | // 从外部数据获取 commonFiles |
| | | const currentRow = dataList.value.find(row => row.id === currentRowId.value); |
| | | if (currentRow && fileListRef.value) { |
| | | // 刷新附件列表,使用从外部获取的最新 commonFiles |
| | | fileListRef.value.open(currentRow.commonFiles || []); |
| | | } |
| | | resolveRefresh(); |
| | | } else { |
| | | resolveRefresh(); |
| | | } |
| | | }).catch(() => { |
| | | resolveRefresh(); |
| | | }); |
| | | }); |
| | | |
| | | resolve({ |
| | | name: uploadRes.data?.originalName || file.name, |
| | | url: uploadRes.data?.tempPath || uploadRes.data?.url, |
| | | id: uploadRes.data?.id |
| | | }); |
| | | } else { |
| | | proxy.$modal.msgError(uploadRes.msg || "文件上传失败"); |
| | | resolve(null); |
| | | } |
| | | } catch (error) { |
| | | console.error("附件上传失败:", error); |
| | | proxy.$modal.msgError("附件上传失败"); |
| | | resolve(null); |
| | | } finally { |
| | | document.body.removeChild(input); |
| | | } |
| | | }; |
| | | |
| | | document.body.appendChild(input); |
| | | input.click(); |
| | | }); |
| | | }; |
| | | |
| | | // 删除附件 |
| | | const handleDeleteFile = async (file) => { |
| | | try { |
| | | await delCommonFile([file.id]); |
| | | proxy.$modal.msgSuccess("删除成功"); |
| | | |
| | | // 刷新列表获取最新数据 |
| | | await new Promise((resolveRefresh) => { |
| | | // 调用 API 获取最新列表数据 |
| | | productRecordPage({ |
| | | ...filters, |
| | | current: pagination.currentPage, |
| | | size: pagination.pageSize |
| | | }).then(({ code, data }) => { |
| | | if (code === 200) { |
| | | // 更新数据列表 |
| | | dataList.value = data.records; |
| | | pagination.total = data.total; |
| | | |
| | | // 从外部数据获取 commonFiles |
| | | const currentRow = dataList.value.find(row => row.id === currentRowId.value); |
| | | if (currentRow && fileListRef.value) { |
| | | // 刷新附件列表,使用从外部获取的最新 commonFiles |
| | | fileListRef.value.open(currentRow.commonFiles || []); |
| | | } |
| | | resolveRefresh(); |
| | | } else { |
| | | resolveRefresh(); |
| | | } |
| | | }).catch(() => { |
| | | resolveRefresh(); |
| | | }); |
| | | }); |
| | | |
| | | return true; |
| | | } catch (error) { |
| | | proxy.$modal.msgError("删除失败"); |
| | | return false; |
| | | } |
| | | }; |
| | | // 打开附件弹框 |
| | | const openFileDialog = async (row) => { |
| | | recordId.value = row.id |
| | | fileDialogVisible.value = true |
| | | } |
| | | |
| | | const openEdit = (row) => { |
| | | editmodalRef.value.open(row); |