From 2b72d8220cf274e9b6586c7d4d9fae612fec3a14 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 03 四月 2026 11:24:51 +0800
Subject: [PATCH] 军泰伟业 1.部署修改

---
 src/views/basicData/product/index.vue |  294 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 270 insertions(+), 24 deletions(-)

diff --git a/src/views/basicData/product/index.vue b/src/views/basicData/product/index.vue
index 24a4659..b2e169a 100644
--- a/src/views/basicData/product/index.vue
+++ b/src/views/basicData/product/index.vue
@@ -96,19 +96,17 @@
             clearable
           />
         </el-form-item>
-        <el-form-item label="瑙勬牸鍨嬪彿" prop="drawingNumber">
-          <el-input
-            v-model="modelForm.drawingNumber"
-            placeholder="璇疯緭鍏ヨ鏍煎瀷鍙�"
-            clearable
-          />
-        </el-form-item>
         <el-form-item label="鍗曚綅" prop="unit">
-          <el-input
+          <el-select
             v-model="modelForm.unit"
-            placeholder="璇疯緭鍏ュ崟浣�"
+            placeholder="璇烽�夋嫨鍗曚綅"
             clearable
-          />
+            style="width: 100%"
+          >
+            <el-option label="浠�" value="浠�" />
+            <el-option label="濂�" value="濂�" />
+            <el-option label="鍙�" value="鍙�" />
+          </el-select>
         </el-form-item>
         <el-form-item label="浜у搧灞炴��" prop="productType">
           <el-select
@@ -121,6 +119,43 @@
             <el-option label="澶栬喘" :value="2" />
             <el-option label="濮斿" :value="3" />
           </el-select>
+        </el-form-item>
+        <el-form-item label="宸ヨ壓璺嚎" prop="routeId">
+          <el-select
+            v-model="modelForm.routeId"
+            placeholder="璇烽�夋嫨宸ヨ壓璺嚎"
+            clearable
+            style="width: 100%"
+            filterable
+          >
+            <el-option
+              v-for="item in processRouteList"
+              :key="item.id"
+              :label="item.processRouteName"
+              :value="item.id"
+            />
+          </el-select>
+        </el-form-item>
+        <el-form-item label="涓婁紶鍥剧焊" prop="drawingFile">
+          <el-upload
+            v-model:file-list="drawingFileList"
+            :action="upload.url"
+            :headers="upload.headers"
+            :data="upload.data"
+            :on-success="handleDrawingUploadSuccess"
+            :on-remove="handleDrawingRemove"
+            :before-upload="handleDrawingBeforeUpload"
+            :limit="5"
+            accept=".pdf,.jpg,.jpeg,.png,.dwg"
+            list-type="picture-card"
+          >
+            <el-icon class="avatar-uploader-icon"><Plus /></el-icon>
+            <template #tip>
+              <div class="el-upload__tip">
+                鏀寔 pdf銆乯pg銆乯peg銆乸ng銆乨wg 鏍煎紡锛屽ぇ灏忎笉瓒呰繃 10MB
+              </div>
+            </template>
+          </el-upload>
         </el-form-item>
       </el-form>
     </FormDialog>
@@ -137,6 +172,7 @@
         :limit="1"
         accept=".xlsx,.xls"
         :action="importUpload.url"
+        :http-request="importUpload.httpRequest"
         :headers="importUpload.headers"
         :before-upload="importUpload.beforeUpload"
         :on-success="importUpload.onSuccess"
@@ -162,10 +198,11 @@
 </template>
 
 <script setup>
-import { ref, reactive } from "vue";
+import { ref, reactive, onMounted } from "vue";
+import axios from "axios";
 import { ElMessageBox } from "element-plus";
+import { Plus } from "@element-plus/icons-vue";
 import { getToken } from "@/utils/auth.js";
-import { FileUpload } from "@/components/Upload";
 import FormDialog from "@/components/Dialog/FormDialog.vue";
 import {
   addOrEditProductModel,
@@ -173,6 +210,7 @@
   productListPage,
   downloadTemplate,
 } from "@/api/basicData/product.js";
+import { listPage as getProcessRouteList } from "@/api/productionManagement/processRoute.js";
 import ImportExcel from "./ImportExcel/index.vue";
 
 const { proxy } = getCurrentInstance();
@@ -185,6 +223,14 @@
 const tableLoading = ref(false);
 const selectedRows = ref([]);
 const modelFormRef = ref();
+const processRouteList = ref([]);
+const drawingFileList = ref([]);
+
+const upload = reactive({
+  url: import.meta.env.VITE_APP_BASE_API + "/file/upload",
+  headers: { Authorization: "Bearer " + getToken() },
+  data: { type: 13 },
+});
 
 const queryForm = reactive({
   productName: "",
@@ -210,13 +256,18 @@
     minWidth: 150,
   },
   {
-    label: "瑙勬牸鍨嬪彿",
-    prop: "drawingNumber",
-    minWidth: 150,
-  },
-  {
     label: "鍗曚綅",
     prop: "unit",
+    minWidth: 100,
+  },
+  {
+    label: "宸ヨ壓璺嚎",
+    prop: "routeName",
+    minWidth: 100,
+  },
+  {
+    label: "瀛愰」鏁伴噺",
+    prop: "subItemCount",
     minWidth: 100,
   },
   {
@@ -230,6 +281,16 @@
       return typeMap[String(v)] || "info";
     },
   },
+	{
+		label: "鍒涘缓鏃堕棿",
+		prop: "createTime",
+		width: 120,
+	},
+	{
+		label: "淇敼鏃堕棿",
+		prop: "updateTime",
+		width: 120,
+	},
   {
     dataType: "action",
     label: "鎿嶄綔",
@@ -252,8 +313,11 @@
     productName: "",
     model: "",
     unit: "",
-    drawingNumber: "",
     productType: null,
+    routeId: null,
+    drawingFile: "",
+    tempFileIds: [],
+    salesLedgerFiles: [],
   },
   modelRules: {
     productName: [
@@ -261,12 +325,34 @@
       { max: 50, message: "浜у搧鍚嶇О涓嶈兘瓒呰繃50涓瓧绗�", trigger: "blur" },
     ],
     model: [{ required: true, message: "璇疯緭鍏ュ浘绾哥紪鍙�", trigger: "blur" }],
-    unit: [{ required: true, message: "璇疯緭鍏ュ崟浣�", trigger: "blur" }],
-    drawingNumber: [],
+    unit: [{ required: true, message: "璇烽�夋嫨鍗曚綅", trigger: "change" }],
     productType: [{ required: true, message: "璇烽�夋嫨浜у搧灞炴��", trigger: "change" }],
   },
 });
 const { modelForm, modelRules } = toRefs(data);
+
+const downloadImportErrorFile = (blob, filename = "import-error.xlsx") => {
+  const downloadElement = document.createElement("a");
+  const href = window.URL.createObjectURL(blob);
+  downloadElement.href = href;
+  downloadElement.download = filename;
+  document.body.appendChild(downloadElement);
+  downloadElement.click();
+  document.body.removeChild(downloadElement);
+  window.URL.revokeObjectURL(href);
+};
+
+const tryParseJsonBlob = async (blob) => {
+  try {
+    const text = await blob.text();
+    if (!text || !text.trim()) {
+      return null;
+    }
+    return JSON.parse(text);
+  } catch (_) {
+    return null;
+  }
+};
 
 const importUpload = reactive({
   title: "浜у搧瀵煎叆",
@@ -274,6 +360,50 @@
   url: import.meta.env.VITE_APP_BASE_API + "/basic/product/import",
   headers: { Authorization: "Bearer " + getToken() },
   isUploading: false,
+  httpRequest: async (options) => {
+    const { file, onProgress, onSuccess, onError } = options;
+    importUpload.isUploading = true;
+    const formData = new FormData();
+    formData.append("file", file);
+    try {
+      const response = await axios({
+        url: importUpload.url,
+        method: "post",
+        headers: {
+          ...importUpload.headers,
+          "Content-Type": "multipart/form-data",
+        },
+        data: formData,
+        responseType: "blob",
+        onUploadProgress: (progressEvent) => {
+          const total = progressEvent.total || 1;
+          const percent = Math.round((progressEvent.loaded * 100) / total);
+          onProgress?.({ percent }, file);
+        },
+      });
+      importUpload.isUploading = false;
+      const blob = response.data;
+      // Contract: success => empty response body; failure => binary error file.
+      if (!blob || blob.size === 0) {
+        onSuccess?.({ code: 200, msg: "import success" }, file);
+        return;
+      }
+      const json = await tryParseJsonBlob(blob);
+      if (json) {
+        if (String(json.code) === "200" || json.success === true) {
+          onSuccess?.(json, file);
+        } else {
+          onError?.(new Error(json.msg || json.message || "import failed"), file);
+        }
+        return;
+      }
+      downloadImportErrorFile(blob);
+      onError?.(new Error("import failed, error file downloaded"), file);
+    } catch (error) {
+      importUpload.isUploading = false;
+      onError?.(error, file);
+    }
+  },
   beforeUpload: (file) => {
     const isExcel = file.name.endsWith('.xlsx') || file.name.endsWith('.xls');
     const isLt10M = file.size / 1024 / 1024 < 10;
@@ -296,7 +426,7 @@
   onSuccess: (response, file, fileList) => {
     console.log('涓婁紶鎴愬姛', response, file, fileList);
     importUpload.isUploading = false;
-    if (response.code === 200) {
+    if (String(response?.code) === "200" || response?.success === true) {
       proxy.$modal.msgSuccess("瀵煎叆鎴愬姛");
       importDia.value = false;
       if (importUploadRef.value) {
@@ -334,17 +464,42 @@
   modelForm.value.model = "";
   modelForm.value.id = "";
   modelForm.value.unit = "";
-  modelForm.value.drawingNumber = "";
   modelForm.value.productType = null;
+  modelForm.value.routeId = null;
+  modelForm.value.drawingFile = "";
+  modelForm.value.tempFileIds = [];
+  modelForm.value.salesLedgerFiles = [];
+  drawingFileList.value = [];
   if (type === "edit") {
     modelForm.value = { ...data };
+    modelForm.value.tempFileIds = data.tempFileIds || [];
+    modelForm.value.salesLedgerFiles = data.salesLedgerFiles || [];
+    // 澶勭悊鍥剧焊鏂囦欢鍙嶆樉
+    if (data.salesLedgerFiles && data.salesLedgerFiles.length > 0) {
+      drawingFileList.value = data.salesLedgerFiles.map(file => ({
+        id: file.id,  // 甯︿笂id鐢ㄤ簬鍒犻櫎鏃惰皟鐢ㄦ帴鍙�
+        name: file.name,
+        url: file.url
+      }));
+    } else if (data.drawingFile) {
+      drawingFileList.value = [{
+        name: data.drawingFile.split('/').pop(),
+        url: data.drawingFile
+      }];
+    }
   }
 };
 
 const submitModelForm = () => {
   modelFormRef.value.validate((valid) => {
     if (valid) {
-      addOrEditProductModel(modelForm.value).then((res) => {
+      // 鏋勫缓鎻愪氦鏁版嵁锛岀‘淇� routeId 涓虹┖鏃朵紶 null锛屽悓鏃舵竻绌� routeName
+      const submitData = {
+        ...modelForm.value,
+        routeId: modelForm.value.routeId || 0,
+        routeName: modelForm.value.routeId ? modelForm.value.routeName : null
+      };
+      addOrEditProductModel(submitData).then((res) => {
         proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
         closeModelDia();
         getModelList();
@@ -429,7 +584,78 @@
   proxy.download("/basic/product/downloadTemplate", {}, "浜у搧瀵煎叆妯℃澘.xlsx");
 };
 
-getModelList();
+const getProcessRouteListData = () => {
+  getProcessRouteList({ current: 1, size: 1000 }).then((res) => {
+    processRouteList.value = res.data.records || [];
+  }).catch(() => {
+    processRouteList.value = [];
+  });
+};
+
+const handleDrawingBeforeUpload = (file) => {
+  const isAllowed = [
+    'application/pdf',
+    'image/jpeg',
+    'image/jpg',
+    'image/png',
+    'application/dwg'
+  ].includes(file.type) || file.name.endsWith('.dwg');
+  const isLt10M = file.size / 1024 / 1024 < 10;
+  
+  if (!isAllowed) {
+    proxy.$modal.msgError("鍙兘涓婁紶 pdf銆乯pg銆乯peg銆乸ng銆乨wg 鏍煎紡鐨勬枃浠讹紒");
+    return false;
+  }
+  if (!isLt10M) {
+    proxy.$modal.msgError("涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 10MB锛�");
+    return false;
+  }
+  return true;
+};
+
+const handleDrawingUploadSuccess = (response, file, fileList) => {
+  console.log('涓婁紶鎴愬姛鍝嶅簲', response);
+  console.log('response.data', response.data);
+  if (response.code === 200) {
+    // 鏀寔澶氭枃浠讹紝杩藉姞鍒版暟缁�
+    modelForm.value.tempFileIds.push(response.data?.tempId);
+    modelForm.value.salesLedgerFiles.push({
+      tempId: response.data?.tempId,
+      originalName: response.data?.originalName || file.name,
+      tempPath: response.data?.tempPath,
+      type: response.data?.type || 13
+    });
+    proxy.$modal.msgSuccess("涓婁紶鎴愬姛");
+  } else {
+    proxy.$modal.msgError(response.msg || "涓婁紶澶辫触");
+  }
+};
+
+const handleDrawingRemove = (file) => {
+  // 濡傛灉鏄紪杈戞ā寮忎笅宸插瓨鍦ㄧ殑鏂囦欢锛堝甫鏈塱d锛夛紝璋冪敤鍒犻櫎鎺ュ彛
+  if (file.id) {
+    delLedgerFile({ id: file.id }).then(res => {
+      if (res.code === 200) {
+        proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
+      }
+    }).catch(err => {
+      console.error("鍒犻櫎鏂囦欢澶辫触锛�", err);
+    });
+  }
+  // 浠庢暟缁勪腑绉婚櫎瀵瑰簲鐨勬枃浠�
+  const index = modelForm.value.salesLedgerFiles.findIndex(item => 
+    item.tempId === file.response?.data?.tempId || item.tempId === file.tempId
+  );
+  if (index > -1) {
+    modelForm.value.tempFileIds.splice(index, 1);
+    modelForm.value.salesLedgerFiles.splice(index, 1);
+  }
+};
+
+onMounted(() => {
+  getModelList();
+  getProcessRouteListData();
+});
 </script>
 
 <style scoped>
@@ -469,6 +695,26 @@
   margin-top: 16px;
 }
 
+.avatar-uploader-icon {
+  font-size: 28px;
+  color: #8c939d;
+  width: 148px;
+  height: 148px;
+  text-align: center;
+  line-height: 148px;
+}
+
+:deep(.el-upload--picture-card) {
+  width: 148px;
+  height: 148px;
+}
+
+:deep(.el-upload__tip) {
+  font-size: 12px;
+  color: #909399;
+  margin-top: 8px;
+}
+
 :deep(.el-dialog__body) {
   padding: 20px 24px;
 }

--
Gitblit v1.9.3