| | |
| | | <el-dialog v-model="upload.open" :title="upload.title" :width="500"> |
| | | <FileUpload |
| | | ref="fileUploadRef" |
| | | accept=".xlsx, .xls" |
| | | accept=".xlsx, .xls, .pdf" |
| | | :headers="upload.headers" |
| | | :action="upload.url + '?updateSupport=' + upload.updateSupport" |
| | | :autoUpload="true" |
| | | :action="upload.url" |
| | | :disabled="upload.isUploading" |
| | | :showTip="false" |
| | | :limit="10" |
| | | @success="handleFileSuccess" |
| | | @remove="removeFile" |
| | | /> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | |
| | | import { getToken } from "@/utils/auth.js"; |
| | | import { FileUpload } from "@/components/Upload"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { ref } from "vue"; |
| | | import useFormData from "@/hooks/useFormData"; |
| | | |
| | | defineOptions({ |
| | | name: "来票台账附件补充", |
| | | }); |
| | | |
| | | const { form, resetForm } = useFormData({ |
| | | id: undefined, |
| | | tempFileIds: [], |
| | | }); |
| | | const emits = defineEmits(["uploadSuccess"]); |
| | | const fileUploadRef = ref(); |
| | | const upload = reactive({ |
| | |
| | | // 设置上传的请求头部 |
| | | headers: { Authorization: "Bearer " + getToken() }, |
| | | // 上传的地址 |
| | | url: import.meta.env.VITE_APP_BASE_API + "/system/supplier/import", |
| | | url: import.meta.env.VITE_APP_BASE_API + "/file/upload", |
| | | }); |
| | | // 点击导入 |
| | | const handleImport = () => { |
| | | const handleImport = (id) => { |
| | | form.id = id; |
| | | upload.open = true; |
| | | upload.title = "来票台账附件补充"; |
| | | }; |
| | | |
| | | const submitFileForm = () => { |
| | | fileUploadRef.value.uploadApi(); |
| | | upload.open = false; |
| | | resetForm(); |
| | | emits("uploadSuccess", form); |
| | | }; |
| | | |
| | | const handleFileSuccess = (response) => { |
| | | const { code, msg } = response; |
| | | form.tempFileIds.push(response.data.tempId); |
| | | if (code == 200) { |
| | | ElMessage({ message: "导入成功", type: "success" }); |
| | | upload.open = false; |
| | | emits("uploadSuccess"); |
| | | } else { |
| | | ElMessage({ message: msg, type: "error" }); |
| | | } |
| | | }; |
| | | |
| | | const removeFile = (file) => { |
| | | const { tempId } = file.response.data; |
| | | form.tempFileIds = form.tempFileIds.filter((item) => item !== tempId); |
| | | }; |
| | | |
| | | defineExpose({ |
| | | handleImport, |
| | | }); |