From f9adfa16fdf2012e915908ea1fed19f75d5107a4 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期六, 30 五月 2026 17:14:02 +0800
Subject: [PATCH] 新疆马铃薯 1.报价提交问题

---
 src/views/basicData/product/ImportExcel/index.vue |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/src/views/basicData/product/ImportExcel/index.vue b/src/views/basicData/product/ImportExcel/index.vue
new file mode 100644
index 0000000..2afbb64
--- /dev/null
+++ b/src/views/basicData/product/ImportExcel/index.vue
@@ -0,0 +1,115 @@
+<template>
+  <el-button type="info" plain icon="Upload" @click="handleImport">
+    瀵煎叆
+  </el-button>
+  <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 @click="upload.open = false">鍙� 娑�</el-button>
+      </div>
+    </template>
+  </el-dialog>
+</template>
+
+<script setup>
+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/product.js";
+
+defineOptions({
+  name: "浜у搧缁存姢瀵煎叆",
+});
+
+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 +
+    "/basic/product/import" +
+    (props.productId ? `?productId=${props.productId}` : "")
+);
+// 鐐瑰嚮瀵煎叆
+const handleImport = () => {
+  if (!props.productId) {
+    ElMessage({ message: "璇峰厛閫夋嫨浜у搧", type: "warning" });
+    return;
+  }
+  upload.open = true;
+  upload.title = "浜у搧瀵煎叆";
+};
+
+const submitFileForm = () => {
+  fileUploadRef.value.uploadApi();
+};
+
+// 鍏抽棴寮圭獥鏃舵竻闄ゅ凡閫夋枃浠�
+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