From de4e098a962e8403d9b32590f0acba025b8072f6 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期六, 14 三月 2026 17:51:27 +0800
Subject: [PATCH] 一些修改
---
src/views/basicData/product/ImportExcel/index.vue | 162 +++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 111 insertions(+), 51 deletions(-)
diff --git a/src/views/basicData/product/ImportExcel/index.vue b/src/views/basicData/product/ImportExcel/index.vue
index c25d254..3611960 100644
--- a/src/views/basicData/product/ImportExcel/index.vue
+++ b/src/views/basicData/product/ImportExcel/index.vue
@@ -1,20 +1,25 @@
<template>
- <el-button type="info" plain icon="Upload" @click="handleImport">
+ <el-button type="info"
+ plain
+ icon="Upload"
+ @click="handleImport">
瀵煎叆
</el-button>
- <el-dialog v-model="upload.open" :title="upload.title">
- <FileUpload
- ref="fileUploadRef"
- accept=".xlsx, .xls"
- :headers="upload.headers"
- :action="upload.url + '?updateSupport=' + upload.updateSupport"
- :disabled="upload.isUploading"
- :showTip="false"
- @success="handleFileSuccess"
- />
+ <el-dialog v-model="upload.open"
+ :title="upload.title"
+ @close="handleDialogClose">
+ <FileUpload ref="fileUploadRef"
+ accept=".xlsx, .xls"
+ :headers="upload.headers"
+ :action="uploadUrl"
+ :disabled="upload.isUploading"
+ :showTip="true"
+ @success="handleFileSuccess"
+ :downloadTemplate="handleDownloadTemplate" />
<template #footer>
<div class="dialog-footer">
- <el-button type="primary" @click="submitFileForm">纭� 瀹�</el-button>
+ <el-button type="primary"
+ @click="submitFileForm">纭� 瀹�</el-button>
<el-button @click="upload.open = false">鍙� 娑�</el-button>
</div>
</template>
@@ -22,47 +27,102 @@
</template>
<script setup>
-import { reactive } from "vue";
-import { getToken } from "@/utils/auth.js";
-import { FileUpload } from "@/components/Upload";
-import { ElMessage } from "element-plus";
+ import { reactive, computed } from "vue";
+ import { getToken } from "@/utils/auth.js";
+ import { FileUpload } from "@/components/Upload";
+ import { ElMessage } from "element-plus";
+ import { downloadProductModelImportTemplate } from "@/api/basicData/newProduct.js";
-defineOptions({
- name: "浜у搧缁存姢瀵煎叆",
-});
+ defineOptions({
+ name: "浜у搧缁存姢瀵煎叆",
+ });
-const emits = defineEmits(["uploadSuccess"]);
-const fileUploadRef = ref();
-const upload = reactive({
- // 鏄惁鏄剧ず寮瑰嚭灞傦紙渚涘簲鍟嗗鍏ワ級
- open: false,
- // 寮瑰嚭灞傛爣棰橈紙渚涘簲鍟嗗鍏ワ級
- title: "",
- // 鏄惁绂佺敤涓婁紶
- isUploading: false,
- // 璁剧疆涓婁紶鐨勮姹傚ご閮�
- headers: { Authorization: "Bearer " + getToken() },
- // 涓婁紶鐨勫湴鍧�
- url: import.meta.env.VITE_APP_BASE_API + "/system/supplier/import",
-});
-// 鐐瑰嚮瀵煎叆
-const handleImport = () => {
- upload.open = true;
- upload.title = "浜у搧瀵煎叆";
-};
+ const props = defineProps({
+ productId: { type: [String, Number], default: "" },
+ });
+ const emits = defineEmits(["uploadSuccess"]);
+ const fileUploadRef = ref();
+ const upload = reactive({
+ // 鏄惁鏄剧ず寮瑰嚭灞傦紙渚涘簲鍟嗗鍏ワ級
+ open: false,
+ // 寮瑰嚭灞傛爣棰橈紙渚涘簲鍟嗗鍏ワ級
+ title: "",
+ // 鏄惁绂佺敤涓婁紶
+ isUploading: false,
+ // 璁剧疆涓婁紶鐨勮姹傚ご閮�
+ headers: { Authorization: "Bearer " + getToken() },
+ });
+ // 涓婁紶鐨勫湴鍧�锛堟惡甯� productId 鍙傛暟锛屼紶缁欏悗绔殑 importProduct 鎺ュ彛锛�
+ const uploadUrl = computed(
+ () =>
+ import.meta.env.VITE_APP_BASE_API +
+ "/productMaterialSku/import" +
+ (props.productId ? `?materialId=${props.productId}` : "")
+ );
+ // 鐐瑰嚮瀵煎叆
+ const handleImport = () => {
+ if (!props.productId) {
+ ElMessage({ message: "璇峰厛閫夋嫨浜у搧", type: "warning" });
+ return;
+ }
+ upload.open = true;
+ upload.title = "浜у搧瑙勬牸瀵煎叆";
+ };
-const submitFileForm = () => {
- fileUploadRef.value.uploadApi();
-};
+ const submitFileForm = () => {
+ fileUploadRef.value.uploadApi();
+ };
-const handleFileSuccess = (response) => {
- const { code, msg } = response;
- if (code == 200) {
- ElMessage({ message: "瀵煎叆鎴愬姛", type: "success" });
- upload.open = false;
- emits("uploadSuccess");
- } else {
- ElMessage({ message: msg, type: "error" });
- }
-};
+ // 鍏抽棴寮圭獥鏃舵竻闄ゅ凡閫夋枃浠�
+ const handleDialogClose = () => {
+ fileUploadRef.value?.clearFiles?.();
+ };
+
+ const handleFileSuccess = response => {
+ const { code, msg } = response;
+ if (code == 200) {
+ ElMessage({ message: msg || "瀵煎叆鎴愬姛", type: "success" });
+ upload.open = false;
+ emits("uploadSuccess");
+ } else {
+ ElMessage({ message: msg, type: "error" });
+ }
+ };
+
+ // 涓嬭浇 Excel 瀵煎叆妯℃澘
+ const handleDownloadTemplate = () => {
+ downloadProductModelImportTemplate()
+ .then(blobData => {
+ const blob =
+ blobData instanceof Blob
+ ? blobData
+ : new Blob([blobData], {
+ type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ });
+ const url = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.href = url;
+ link.download = "浜у搧瑙勬牸瀵煎叆妯℃澘.xlsx";
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ window.URL.revokeObjectURL(url);
+ ElMessage({ message: "妯℃澘涓嬭浇鎴愬姛", type: "success" });
+ })
+ .catch(() => {
+ ElMessage({ message: "妯℃澘涓嬭浇澶辫触", type: "error" });
+ });
+ };
</script>
+
+<style scoped>
+ .import-tip {
+ margin-top: 12px;
+ font-size: 12px;
+ color: var(--el-text-color-secondary);
+ }
+
+ .import-tip .el-button {
+ margin-left: 8px;
+ }
+</style>
--
Gitblit v1.9.3