From 42feb0af0ae1d486d0474c76711fdb67c778bcf3 Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期六, 28 六月 2025 10:04:30 +0800
Subject: [PATCH] Merge branch 'main' of http://120.76.84.145:10101/gitblit/r/H5/leshan-laboratory

---
 culture/src/views/strainReportLibrary/reportLibraryOne/add.vue |   82 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/culture/src/views/strainReportLibrary/reportLibraryOne/add.vue b/culture/src/views/strainReportLibrary/reportLibraryOne/add.vue
index 79ccf8c..1a50dde 100644
--- a/culture/src/views/strainReportLibrary/reportLibraryOne/add.vue
+++ b/culture/src/views/strainReportLibrary/reportLibraryOne/add.vue
@@ -58,8 +58,10 @@
                     </div>
                 </div>
                 <el-form-item prop="name" style="margin-top: 38px">
-                    <el-upload action="https://jsonplaceholder.typicode.com/posts/" :file-list="fileList">
+                    <el-upload action="#" :file-list="fileList" :http-request="handleUpload"
+                        :before-upload="beforeUpload" :on-preview="handlePreview" :on-remove="handleRemove">
                         <el-button size="small" type="primary">点击上传</el-button>
+                        <div slot="tip" class="el-upload__tip">支持任意格式文件上传</div>
                     </el-upload>
                 </el-form-item>
                 <div class="header-title" style="width: 100%;">
@@ -160,6 +162,7 @@
 import { Card } from 'element-ui';
 import AiEditor from '@/components/AiEditor'
 import ChooseProject from '@/components/chooseProject/index.vue'
+import { customUploadRequest, getFullUrl } from "@/utils/utils";
 import SelectMember from '@/components/SelectMember'
 import { add, getDetail, update } from './service'
 
@@ -248,7 +251,6 @@
         if (this.$route.query.id) {
             getDetail(this.$route.query.id).then(res => {
                 const data = res.data || res;
-                console.log('qweqweqweq', data);
 
                 this.form = {
                     ...this.form,
@@ -257,7 +259,7 @@
                 };
 
                 let arr = data.evaluate.split(',')
-
+                this.fileList = (data.enclosureUrl ? JSON.parse(data.enclosureUrl) : [])
                 this.assessmentTable = this.assessmentTable.map((item, index) => {
                     item.selectedScore = Number(arr[index])
                     return item
@@ -282,6 +284,62 @@
         }
     },
     methods: {
+        handlePreview(file) {
+            if (file.url) {
+                window.open(file.url, '_blank');
+            } else {
+                this.$message.warning('无可预览地址');
+            }
+        },
+        // 上传前校验
+        beforeUpload(file) {
+            return true;
+        },
+        // 自定义上传处理
+        handleUpload(options) {
+            const { file, onSuccess, onError } = options;
+
+            // 使用封装的customUploadRequest方法
+            customUploadRequest({
+                file,
+                onSuccess: (res) => {
+                    if (res.code === 200) {
+                        const fileObj = {
+                            id: new Date().getTime(),
+                            reportId: this.$route.query.id ? this.$route.query.id : "",
+                            fileUrl: res.msg || res.data || "",
+                            reportType: 2, // 报告类型
+                            fileName: file.name,
+                            fileSize: file.size,
+                        };
+
+                        // 添加到文件列表显示
+                        this.fileList.push({
+                            name: file.name,
+                            url: getFullUrl(fileObj.fileUrl),
+                            uid: fileObj.id,
+                        });
+
+                        // 添加到表单数据
+                        this.form.feasibilityReportFiles.push(fileObj);
+                        this.$message.success("文件上传成功");
+                        onSuccess(res);
+                    }
+                },
+                onError: (err) => {
+                    this.$message.error("文件上传失败");
+                    onError(err);
+                },
+            });
+        },
+        // 删除文件
+        handleRemove(file) {
+            const index = this.fileList.findIndex((item) => item.name === file.name);
+            if (index !== -1) {
+                this.fileList.splice(index, 1);
+                this.form.feasibilityReportFiles.splice(index, 1);
+            }
+        },
         addData() {
             if (this.submitLoading) return;
             this.submitLoading = true;
@@ -309,9 +367,10 @@
                     return;
                 }
                 const params = {
-                    isDraft: this.form.isDraft ? this.form.isDraft : 0,
+                    isDraft: 0,
                     projectId: this.projectData[0].id,
                     experimentId: this.selectedMember[0].userId,
+                    enclosureUrl: this.fileList.length && JSON.stringify(this.fileList),
                     // reportCode: this.form.reportCode,
                     reportContent: this.$refs.materialEditor.getContent(),
                     reportName: this.form.reportName,
@@ -360,6 +419,7 @@
                     isDraft: 1,
                     projectId: this.projectData[0].id,
                     experimentId: this.selectedMember[0].userId,
+                    enclosureUrl: this.fileList.length && JSON.stringify(this.fileList),
                     // reportCode: this.form.reportCode,
                     reportContent: this.$refs.materialEditor.getContent(),
                     reportName: this.form.reportName,
@@ -367,6 +427,20 @@
                     evaluate: str.join(','),
                     reportType: 1
                 };
+                if (this.$route.query.id) {
+                    params.id = this.$route.query.id
+                    update(params).then(res => {
+                        this.submitLoading = false;
+                        if (res.code == 200) {
+                            this.$message.success('编辑成功');
+                            this.$router.back()
+                        } else {
+                            this.$message.error(res.msg || '编辑失败');
+                            this.submitLoading = false;
+                        }
+                    }).catch(() => { this.submitLoading = false; })
+                    return
+                }
                 add(params).then(res => {
                     this.submitLoading = false;
                     if (res.code == 200) {

--
Gitblit v1.7.1