| | |
| | | |
| | | // 页面参数 |
| | | const reportId = ref(""); |
| | | const reportType = ref("拉丝"); |
| | | const reportType = ref("绞线"); |
| | | const attachmentList = ref<any[]>([]); |
| | | |
| | | const detailData = ref<any>({}); |
| | | // 获取附件列表 |
| | | const getAttachmentList = async () => { |
| | | const getAttachmentList = async (data: any) => { |
| | | try { |
| | | detailData.value = data; |
| | | console.log(" detailData.value", detailData.value); |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = (currentPage as any).options; |
| | | const currentReportId = options?.reportId; |
| | | const currentReportId = detailData.value.id; |
| | | |
| | | if (currentReportId) { |
| | | reportId.value = currentReportId; |
| | | |
| | | // 直接调用通用查看接口查询附件列表 |
| | | // 使用示例中的附件ID数组 [850,851] |
| | | const attachmentIds: number[] = [850, 851]; // 使用HTTP文件中的示例数据 |
| | | |
| | | const attachmentIds: number[] = detailData.value.attachmentId !== null? detailData.value.attachmentId.split(",") : []; // 使用HTTP文件中的示例数据 |
| | | if (attachmentIds.length === 0) { |
| | | return; |
| | | } |
| | | const { data } = await AttachmentAPI.listAttachmentFiles(attachmentIds); |
| | | attachmentList.value = data || []; |
| | | } else { |
| | |
| | | const filePaths = Array.isArray(res.tempFilePaths) |
| | | ? res.tempFilePaths |
| | | : [res.tempFilePaths]; |
| | | const uploadResults = await AttachmentAPI.uploadAttachmentFiles(filePaths); |
| | | |
| | | const uploadResults: any = await AttachmentAPI.uploadAttachmentFiles(filePaths); |
| | | const result = uploadResults.map((it) => { |
| | | return it.data; |
| | | }); |
| | | console.log("result", result); |
| | | // 更新附件列表 |
| | | const flattenedResult = result.flat(); |
| | | attachmentList.value.push(...flattenedResult); |
| | | console.log(attachmentList.value); |
| | | // 提取附件ID |
| | | const attachmentIds = uploadResults.map((result) => result.data.id).join(","); |
| | | const attachmentId = attachmentList.value.map((item: any) => item.id).join(","); |
| | | |
| | | // 关联到报工 |
| | | if (attachmentId) { |
| | | await AttachmentAPI.addOutputAttachments({ |
| | | id: parseInt(reportId.value), |
| | | attachmentIds: attachmentIds, |
| | | id: parseInt(detailData.value.id), |
| | | attachmentId: attachmentId, |
| | | }); |
| | | detailData.value.attachmentId = attachmentId; |
| | | } |
| | | |
| | | toast.show("上传成功"); |
| | | // 重新获取附件列表 |
| | | await getAttachmentList(); |
| | | // await getAttachmentList(); |
| | | } catch (error) { |
| | | console.error("上传失败:", error); |
| | | toast.show("上传失败"); |
| | |
| | | }; |
| | | |
| | | // 删除附件 |
| | | const deleteAttachment = async (attachmentId: number) => { |
| | | const deleteAttachment = async (aid: number) => { |
| | | try { |
| | | uni.showModal({ |
| | | title: "确认删除", |
| | |
| | | success: async (res) => { |
| | | if (res.confirm) { |
| | | // 前端手动删除:直接从列表中移除这条数据 |
| | | attachmentList.value = attachmentList.value.filter((item) => item.id !== attachmentId); |
| | | attachmentList.value = attachmentList.value.filter((item) => item.id !== aid); |
| | | |
| | | // 获取剩余的附件ID组合 |
| | | const remainingIds = attachmentList.value.map((item) => item.id); |
| | | const attachmentIds = remainingIds.join(","); |
| | | const attachmentId = attachmentList.value.map((item) => item.id).join(","); |
| | | |
| | | // 调用报工添加附件接口,更新附件关联 |
| | | await AttachmentAPI.addOutputAttachments({ |
| | | id: parseInt(reportId.value), |
| | | attachmentIds: attachmentIds, |
| | | id: parseInt(detailData.value.id), |
| | | attachmentId: attachmentId, |
| | | }); |
| | | |
| | | detailData.value.attachmentId = attachmentId; |
| | | toast.show("删除成功"); |
| | | } |
| | | }, |
| | |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getAttachmentList(); |
| | | uni.$on("detailData", (data) => { |
| | | // 处理接收到的数据 |
| | | getAttachmentList(data); |
| | | }); |
| | | }); |
| | | </script> |
| | | |