From aa6ab634ff987ad35d960efcad6eb0f7c6af6ea7 Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期五, 11 四月 2025 16:24:14 +0800
Subject: [PATCH] 修改路径

---
 src/views/applicationBatchList/components/UploadDialog.vue |   81 ++++++++++++++++++++++++++--------------
 1 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/src/views/applicationBatchList/components/UploadDialog.vue b/src/views/applicationBatchList/components/UploadDialog.vue
index 158226e..b6dbc5a 100644
--- a/src/views/applicationBatchList/components/UploadDialog.vue
+++ b/src/views/applicationBatchList/components/UploadDialog.vue
@@ -6,8 +6,8 @@
     @close="handleClose"
   >
     <el-form ref="uploadForm" :model="form" :rules="rules" label-width="180px">
-      <el-form-item label="批次号" prop="batchNumber">
-        <el-input v-model="form.batchNumber" placeholder="请输入" />
+      <el-form-item label="批次号" prop="batchNumber" v-if="!info.id">
+        <el-input v-model="form.batchNumber" placeholder="自动生成" disabled />
       </el-form-item>
       <el-form-item :label="'导入安置申请表'" prop="file">
         <el-upload
@@ -36,13 +36,23 @@
 
 <script>
 import { importBatch } from "@/api/application-batch";
+
 export default {
   name: 'UploadDialog',
   props: {
+    info: {
+      type: Object,
+      default: () => {
+       return {
+        id: 0,
+        batchNumber: ''
+       }
+      }
+    },
     visible: {
       type: Boolean,
       default: false
-    },
+    }
   },
   data() {
     return {
@@ -52,14 +62,20 @@
         file: null
       },
       rules: {
-        batchNumber: [{ required: true, message: '请输入批次号', trigger: 'blur' }],
-        file: [ { required: true, message: '请选择上传文件', trigger: 'change' }]
+        batchNumber: [{ required: false, message: '请输入批次号', trigger: 'blur' }],
+        file: [{ required: true, message: '请选择上传文件', trigger: 'change' }]
       }
     }
   },
   watch: {
-    visible(val) {
-      this.dialogVisible = val;
+    visible: {
+      handler(val) {
+        this.dialogVisible = val;
+        if (!val) {
+          this.handleClose();
+        }
+      },
+      immediate: true
     },
     dialogVisible(val) {
       this.$emit('update:visible', val);
@@ -67,9 +83,13 @@
   },
   methods: {
     handleClose() {
-      this.form.batchNumber = '';
-      this.form.file = null;
-      this.$refs.uploadForm && this.$refs.uploadForm.resetFields();
+      this.form = {
+        batchNumber: '',
+        file: null
+      };
+      if (this.$refs.uploadForm) {
+        this.$refs.uploadForm.resetFields();
+      }
       this.dialogVisible = false;
     },
     handleFileChange(file) {
@@ -80,28 +100,31 @@
         this.form.file = null;
         return;
       }
-      this.form.file = file;
-      this.$refs.uploadForm.validateField('file');
+      this.form.file = file.raw;
+      if (this.$refs.uploadForm) {
+        this.$refs.uploadForm.validateField('file');
+      }
     },
-    submitUpload() {
-      this.$refs.uploadForm.validate(valid => {
-        if (!valid) {
-          return;
-        }
+    async submitUpload() {
+      try {
+        await this.$refs.uploadForm.validate();
         
         const formData = new FormData();
-        formData.append('file', this.form.file.raw);
-        console.log('22222222222222222',formData)
-        importBatch({batchNumber:this.form.batchNumber,file:formData})
-          .then(res => {
-            this.$message.success('导入成功');
-            this.$emit('success');
-            this.handleClose();
-          })
-          .catch(error => {
-            this.$message.error(error.message || '导入失败');
-          });
-      });
+        formData.append('file', this.form.file);
+        
+        if (this.info?.id) {
+          formData.append('applyId', this.info.id);
+          formData.append('batchNumber', this.info.batchNumber);
+        } else {
+          formData.append('batchNumber', this.form.batchNumber);
+        }
+        await importBatch(formData);
+        this.$message.success('导入成功');
+        this.$emit('success');
+        this.handleClose();
+      } catch (error) {
+        this.$message.error(error.message || '导入失败');
+      }
     }
   }
 }

--
Gitblit v1.7.1