From 714ab13b7d3ad5be0e2ec3af2eaa240c9d3f43f3 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 02 二月 2026 15:36:05 +0800
Subject: [PATCH] 进销存升级 1.生产报工带出来的原材料、过程、出厂检数据编辑时,规格型号回显还是有问题

---
 src/views/safeProduction/hazardousMaterialsControl/index.vue |   91 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/src/views/safeProduction/hazardousMaterialsControl/index.vue b/src/views/safeProduction/hazardousMaterialsControl/index.vue
index 63d9a5b..b2048fe 100644
--- a/src/views/safeProduction/hazardousMaterialsControl/index.vue
+++ b/src/views/safeProduction/hazardousMaterialsControl/index.vue
@@ -53,7 +53,8 @@
                v-if="dialogType === 'add'"
                :model="form"
                :rules="rules"
-               label-width="120px">
+               label-width="140px"
+               label-position="top">
         <el-row :gutter="20">
           <el-col :span="12">
             <el-form-item label="鍗遍櫓婧�"
@@ -161,7 +162,9 @@
           <span>{{ form.name }}</span>
         </el-descriptions-item>
         <el-descriptions-item label="鍗遍櫓婧愮被鍨�">
-          <span>{{ getTypeLabel(form.type) }}</span>
+          <el-tag type="info">
+            {{ getTypeLabel(form.type) }}
+          </el-tag>
         </el-descriptions-item>
         <el-descriptions-item label="鎵�鍦ㄤ綅缃�">
           <span>{{ form.location }}</span>
@@ -200,7 +203,8 @@
                v-if="dialogType === 'edit'"
                :model="form"
                :rules="rules1"
-               label-width="120px">
+               label-width="140px"
+               label-position="top">
         <el-row :gutter="20">
           <el-col :span="12">
             <el-form-item label="褰掕繕浜�"
@@ -240,9 +244,9 @@
       </el-form>
       <template #footer>
         <span class="dialog-footer">
-          <el-button @click="dialogVisible = false">鍙栨秷</el-button>
           <el-button type="primary"
                      @click="submitForm">纭畾</el-button>
+          <el-button @click="dialogVisible = false">鍙栨秷</el-button>
         </span>
       </template>
     </el-dialog>
@@ -254,9 +258,14 @@
       <div>
         <el-table :data="safeHazardList"
                   border
+                  ref="safeHazardTableRef"
                   v-loading="safeHazardLoading"
-                  style="width: 100%"
-                  @row-click="handleSafeHazardSelect">
+                  :selection="selectedSafeHazardIds"
+                  @selection-change="handleSafeHazardSelectionChange"
+                  style="width: 100%">
+          <el-table-column type="selection"
+                           width="55"
+                           :selectable="isSelectable" />
           <el-table-column prop="code"
                            label="鍗遍櫓婧愮紪鐮�"
                            width="180"
@@ -298,6 +307,8 @@
       </div>
       <template #footer>
         <span class="dialog-footer">
+          <el-button type="primary"
+                     @click="handleSafeHazardSelect">纭畾</el-button>
           <el-button @click="safeHazardSelectVisible = false">鍙栨秷</el-button>
         </span>
       </template>
@@ -412,6 +423,12 @@
   // 琛ㄦ牸鍒楅厤缃�
   const tableColumn = ref([
     {
+      label: "棰嗙敤鍗曞彿",
+      prop: "materialRecordCode",
+      width: 130,
+      showOverflowTooltip: true,
+    },
+    {
       label: "鍗遍櫓婧愮紪鐮�",
       prop: "code",
       showOverflowTooltip: true,
@@ -480,16 +497,11 @@
       showOverflowTooltip: true,
     },
     {
-      label: "鍗曞彿",
-      prop: "materialRecordCode",
-      showOverflowTooltip: true,
-    },
-    {
       dataType: "action",
       label: "鎿嶄綔",
       align: "center",
       fixed: "right",
-      width: 200,
+      width: 130,
       operation: [
         {
           name: "褰掕繕",
@@ -536,11 +548,17 @@
     }
   };
   const handleApplyQtyChange = () => {
+    if (Number(form.value.applyQty) < 0) {
+      ElMessage.error("棰嗙敤鏁伴噺涓嶈兘灏忎簬0");
+      form.value.applyQty = 0;
+      return;
+    }
     if (form.value.applyQty > valueItem.value.stockQty) {
       ElMessage.error("棰嗙敤鏁伴噺涓嶈兘澶т簬搴撳瓨鏁伴噺");
       form.value.applyQty = "";
     }
   };
+  const selectedSafeHazardIds = ref([]);
 
   // 寮�濮嬭嚜鍔ㄥ埛鏂�
   const startAutoRefresh = () => {
@@ -575,7 +593,7 @@
   const fetchSafeHazardList = () => {
     safeHazardLoading.value = true;
     return safeHazardListPage({
-      page: safeHazardPage.value.current,
+      current: safeHazardPage.value.current,
       size: safeHazardPage.value.size,
     })
       .then(res => {
@@ -587,12 +605,36 @@
       });
   };
 
-  const handleSafeHazardSelect = item => {
+  const isSelectable = row => {
+    // 鍙湁搴撳瓨鏁伴噺澶т簬0鐨勮鎵嶈兘琚�夋嫨
+    return Number(row.stockQty) > 0;
+  };
+
+  const handleSafeHazardSelectionChange = selection => {
+    // 鍙繚鐣欐渶鍚庝竴涓�変腑鐨勯」
+    if (selection.length > 1) {
+      const lastSelected = selection[selection.length - 1];
+      selectedSafeHazardIds.value = [lastSelected];
+      proxy.$refs.safeHazardTableRef.clearSelection();
+      proxy.$refs.safeHazardTableRef.toggleRowSelection(lastSelected, true);
+    } else if (selection.length === 1) {
+      selectedSafeHazardIds.value = [selection[0]];
+    } else {
+      selectedSafeHazardIds.value = [];
+    }
+  };
+
+  const handleSafeHazardSelect = () => {
+    if (!selectedSafeHazardIds.value.length) {
+      ElMessage.error("璇烽�夋嫨涓�涓嵄闄╂簮");
+      return;
+    }
+
     valueItem.value = {
-      ...item,
+      ...selectedSafeHazardIds.value[0],
     };
     valueItem.value.type = getTypeLabel(valueItem.value.type);
-    form.value.safeHazardId = item.id;
+    form.value.safeHazardId = selectedSafeHazardIds.value[0].id;
     safeHazardSelectVisible.value = false;
   };
 
@@ -606,12 +648,20 @@
   const pagination1 = obj => {
     page.value.current = obj.page;
     page.value.size = obj.limit;
-    handleQuery();
+    getList();
   };
 
   // 閫夋嫨鍙樺寲澶勭悊
   const handleSelectionChange = selection => {
-    selectedIds.value = selection.map(item => item.id);
+    // 涓昏〃鏍间篃鍙繚鐣欐渶鍚庝竴涓�変腑鐨勯」
+    if (selection.length > 1) {
+      const lastSelected = selection[selection.length - 1];
+      selectedIds.value = [lastSelected.id];
+    } else if (selection.length === 1) {
+      selectedIds.value = [selection[0].id];
+    } else {
+      selectedIds.value = [];
+    }
   };
 
   // 鎵撳紑琛ㄥ崟
@@ -736,7 +786,7 @@
           .catch(err => {
             ElMessage.error(err.msg);
           });
-      } else {
+      } else if (dialogType.value === "edit") {
         await formRef1.value.validate();
         safeHazardRecordUpdate({ ...form.value })
           .then(res => {
@@ -749,6 +799,9 @@
           .catch(err => {
             ElMessage.error(err.msg);
           });
+      } else if (dialogType.value === "view") {
+        // 鏌ョ湅妯″紡涓嬩笉鎻愪氦琛ㄥ崟
+        dialogVisible.value = false;
       }
     } catch (error) {
       console.error("琛ㄥ崟楠岃瘉澶辫触:", error);

--
Gitblit v1.9.3