From 2adda5537ed677cb5b3a5a0ff434f2da92e87bf3 Mon Sep 17 00:00:00 2001 From: pyt <626651354@qq.com> Date: 星期一, 24 三月 2025 16:36:09 +0800 Subject: [PATCH] Merge branch 'main' of http://120.76.84.145:10101/gitblit/r/H5/chongzhouResettle --- src/views/applicationBatchList/components/UploadDialog.vue | 75 ++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/views/applicationBatchList/components/UploadDialog.vue b/src/views/applicationBatchList/components/UploadDialog.vue index e68430a..743a0eb 100644 --- a/src/views/applicationBatchList/components/UploadDialog.vue +++ b/src/views/applicationBatchList/components/UploadDialog.vue @@ -36,17 +36,23 @@ <script> import { importBatch } from "@/api/application-batch"; + export default { name: 'UploadDialog', props: { info: { type: Object, - default: () => {id:0} + default: () => { + return { + id: 0, + batchNumber: '' + } + } }, visible: { type: Boolean, default: false - }, + } }, data() { return { @@ -57,13 +63,19 @@ }, rules: { batchNumber: [{ required: true, message: '请输入批次号', trigger: 'blur' }], - file: [ { required: true, message: '请选择上传文件', trigger: 'change' }] + 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); @@ -71,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) { @@ -85,33 +101,30 @@ return; } this.form.file = file.raw; - this.$refs.uploadForm.validateField('file'); + 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); - if(this.info.id){ - formData.append('applyId',this.info.id); - formData.append('batchNumber',this.info.batchNumber); - }else{ - formData.append('batchNumber',this.form.batchNumber); + 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); } - // console.log('22222222222222222',formData) - importBatch(formData) - .then(res => { - this.$message.success('导入成功'); - this.$emit('success'); - this.handleClose(); - }) - .catch(error => { - this.$message.error(error.message || '导入失败'); - }); - }); + await importBatch(formData); + this.$message.success('导入成功'); + this.$emit('success'); + this.handleClose(); + } catch (error) { + this.$message.error(error.message || '导入失败'); + } } } } -- Gitblit v1.7.1