From 677a8679b5140ca6019f974c092de103df8f8559 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 01 六月 2026 17:52:16 +0800
Subject: [PATCH] 新疆马铃薯 1.库存管理绑定设备,添加查看数采功能

---
 src/views/qualityManagement/finalInspection/components/quickCheckDia.vue |    9 ++-
 src/views/inventoryManagement/stockManagement/IotDataDialog.vue          |   48 +++++++++++++---
 src/views/inventoryManagement/stockManagement/Record.vue                 |   44 +++++++++++++-
 src/api/inventoryManagement/stockInventory.js                            |   10 +-
 src/views/inventoryManagement/stockManagement/BindDeviceDialog.vue       |   12 +++
 5 files changed, 101 insertions(+), 22 deletions(-)

diff --git a/src/api/inventoryManagement/stockInventory.js b/src/api/inventoryManagement/stockInventory.js
index 0671391..12f5402 100644
--- a/src/api/inventoryManagement/stockInventory.js
+++ b/src/api/inventoryManagement/stockInventory.js
@@ -111,12 +111,12 @@
     });
 };
 
-// 缁戝畾鐗╄仈璁惧鍒板簱瀛�
-export const bindIotDevice = (id, warehouse) => {
+// 鎵归噺鑾峰彇鐗╄仈璁惧瀹炴椂鏁伴噰鏁版嵁锛圥OST璇锋眰锛屼紶閫掕澶嘔D鏁扮粍锛�
+export const batchGetIotRealtimeData = (deviceIds) => {
     return request({
-        url: `/stockInventory/bindIotDevice/${id}`,
-        method: "put",
-        data: { warehouse },
+        url: `/stockInventory/iotRealtime`,
+        method: "post",
+        data: deviceIds,
     });
 };
 
diff --git a/src/views/inventoryManagement/stockManagement/BindDeviceDialog.vue b/src/views/inventoryManagement/stockManagement/BindDeviceDialog.vue
index 31a72c4..3dab100 100644
--- a/src/views/inventoryManagement/stockManagement/BindDeviceDialog.vue
+++ b/src/views/inventoryManagement/stockManagement/BindDeviceDialog.vue
@@ -53,7 +53,7 @@
 <script setup>
   import { ref, computed, onMounted, getCurrentInstance } from "vue";
   import { getLedgerPage } from "@/api/equipmentManagement/ledger.js";
-  import { bindIotDevice } from "@/api/inventoryManagement/stockInventory.js";
+  import { createStockInventory } from "@/api/inventoryManagement/stockInventory.js";
 
   const props = defineProps({
     visible: {
@@ -124,7 +124,15 @@
         submitLoading.value = true;
         // 灏嗚澶嘔D鏁扮粍杞崲涓洪�楀彿鍒嗛殧鐨勫瓧绗︿覆
         const warehouse = formState.value.deviceIds.join(",");
-        bindIotDevice(props.record.id, warehouse)
+        // 浣跨敤搴撳瓨鏂板/缂栬緫鎺ュ彛锛寃arehouse 瀛楁浼犺澶嘔D
+        const submitData = {
+          id: props.record.id,
+          productModelId: props.record.productModelId,
+          batchNo: props.record.batchNo,
+          qualitity: props.record.qualitity,
+          warehouse: warehouse,
+        };
+        createStockInventory(submitData)
           .then(res => {
             submitLoading.value = false;
             proxy.$modal.msgSuccess("缁戝畾鎴愬姛");
diff --git a/src/views/inventoryManagement/stockManagement/IotDataDialog.vue b/src/views/inventoryManagement/stockManagement/IotDataDialog.vue
index 2f12009..8a34b8f 100644
--- a/src/views/inventoryManagement/stockManagement/IotDataDialog.vue
+++ b/src/views/inventoryManagement/stockManagement/IotDataDialog.vue
@@ -29,7 +29,7 @@
                 </div>
                 <div class="device-status">
                   <span class="status-dot" :class="getStatusClass(device.status)"></span>
-                  <span :class="getStatusTextClass(device.status)">{{ device.status || '鏈煡' }}</span>
+                  <span :class="getStatusTextClass(device.status)">{{ getStatusLabel(device.status) }}</span>
                 </div>
               </div>
             </template>
@@ -83,7 +83,7 @@
               </el-row>
             </div>
             <div v-else class="device-offline">
-              <el-alert :title="device.statusMessage || '璁惧绂荤嚎'" type="warning" :closable="false" show-icon />
+              <el-alert :title="device.statusMessage || (device.status === 'error' ? '璁惧寮傚父' : '璁惧绂荤嚎')" :type="device.status === 'error' ? 'error' : 'warning'" :closable="false" show-icon />
             </div>
           </el-card>
         </div>
@@ -99,7 +99,7 @@
 
 <script setup>
   import { ref, computed, onMounted, onUnmounted, watch } from "vue";
-  import { getIotRealtimeData } from "@/api/inventoryManagement/stockInventory.js";
+  import { batchGetIotRealtimeData } from "@/api/inventoryManagement/stockInventory.js";
   import { Refresh, Sunny, Drizzling, WindPower, Sunrise, Lightning } from "@element-plus/icons-vue";
 
   const props = defineProps({
@@ -163,13 +163,36 @@
     }
   };
 
+  const getStatusLabel = (status) => {
+    switch (status) {
+      case "鍦ㄧ嚎":
+        return "鍦ㄧ嚎";
+      case "offline":
+        return "绂荤嚎";
+      case "error":
+        return "寮傚父";
+      default:
+        return "绂荤嚎";
+    }
+  };
+
   const fetchData = async () => {
-    if (!props.record.id) return;
+    const deviceIdsStr = props.record?.warehouse;
+    console.log("fetchData called, warehouse:", deviceIdsStr);
+    if (!deviceIdsStr) {
+      console.warn("warehouse is empty, skip fetch");
+      deviceData.value = { inventoryId: null, iotDeviceIds: "", devices: [] };
+      return;
+    }
     loading.value = true;
     try {
-      const res = await getIotRealtimeData(props.record.id);
+      const deviceIds = deviceIdsStr.split(",").map(id => id.trim()).filter(id => id);
+      const res = await batchGetIotRealtimeData(deviceIds);
+      
       if (res.code === 200 && res.data) {
         deviceData.value = res.data;
+      } else {
+        deviceData.value = { inventoryId: null, iotDeviceIds: deviceIdsStr, devices: [] };
       }
     } catch (error) {
       console.error("鑾峰彇鐗╄仈璁惧鏁版嵁澶辫触:", error);
@@ -183,6 +206,17 @@
     isShow.value = false;
   };
 
+  // 鐩戝惉寮圭獥鏄剧ず鐘舵�侊紝姣忔鎵撳紑鏃惰幏鍙栨暟鎹�
+  watch(() => props.visible, (val) => {
+    console.log("visible changed:", val, "record:", props.record);
+    if (val) {
+      fetchData();
+    } else {
+      // 鍏抽棴鏃跺仠姝㈣嚜鍔ㄥ埛鏂�
+      autoRefresh.value = false;
+    }
+  }, { immediate: true });
+
   // 鑷姩鍒锋柊
   watch(autoRefresh, (val) => {
     if (val) {
@@ -195,10 +229,6 @@
         refreshTimer = null;
       }
     }
-  });
-
-  onMounted(() => {
-    fetchData();
   });
 
   onUnmounted(() => {
diff --git a/src/views/inventoryManagement/stockManagement/Record.vue b/src/views/inventoryManagement/stockManagement/Record.vue
index 1ce95be..1263dad 100644
--- a/src/views/inventoryManagement/stockManagement/Record.vue
+++ b/src/views/inventoryManagement/stockManagement/Record.vue
@@ -87,9 +87,14 @@
         <el-table-column label="鎵瑰彿"
                          prop="batchNo"
                          show-overflow-tooltip />
-        <el-table-column label="浠撳簱"
+        <el-table-column label="鐗╄仈璁惧"
                          prop="warehouse"
-                         show-overflow-tooltip />
+                         show-overflow-tooltip
+                         min-width="150">
+          <template #default="scope">
+            {{ getDeviceNames(scope.row.warehouse) }}
+          </template>
+        </el-table-column>
         <el-table-column label="鍚堟牸搴撳瓨鏁伴噺"
                          prop="qualifiedQuantity"
                          show-overflow-tooltip />
@@ -113,7 +118,7 @@
                          show-overflow-tooltip />
         <el-table-column fixed="right"
                          label="鎿嶄綔"
-                         min-width="190"
+                         width="210"
                          align="center">
           <template #default="scope">
             <el-button link
@@ -179,6 +184,7 @@
   import { ref, reactive, toRefs, onMounted, getCurrentInstance } from "vue";
   import { ElMessage, ElMessageBox } from "element-plus";
   import { getStockInventoryListPageCombined } from "@/api/inventoryManagement/stockInventory.js";
+  import { getLedgerPage } from "@/api/equipmentManagement/ledger.js";
   const props = defineProps({
     productId: {
       type: Number,
@@ -234,6 +240,8 @@
   const isShowBindDeviceModal = ref(false);
   // 鏄惁鏄剧ず鐗╄仈鏁伴噰寮规
   const isShowIotDataModal = ref(false);
+  // 璁惧鍒楄〃锛堢敤浜庢樉绀鸿澶囧悕绉帮級
+  const deviceList = ref([]);
   const data = reactive({
     searchForm: {
       productName: "",
@@ -382,8 +390,38 @@
       });
   };
 
+  // 鑾峰彇璁惧鍒楄〃
+  const getDeviceList = async () => {
+    try {
+      const res = await getLedgerPage({
+        isIotDevice: 1,
+        page: 1,
+        size: 999,
+      });
+      if (res.data && res.data.records) {
+        deviceList.value = res.data.records;
+      }
+    } catch (error) {
+      console.error("鑾峰彇璁惧鍒楄〃澶辫触:", error);
+    }
+  };
+
+  // 鏍规嵁璁惧ID鑾峰彇璁惧鍚嶇О
+  const getDeviceNames = (warehouse) => {
+    if (!warehouse) return "-";
+    const deviceIds = warehouse.split(",").map(id => id.trim());
+    const names = deviceIds
+      .map(id => {
+        const device = deviceList.value.find(d => String(d.id) === id);
+        return device ? device.deviceName : id;
+      })
+      .filter(name => name);
+    return names.length > 0 ? names.join(", ") : warehouse;
+  };
+
   onMounted(() => {
     getList();
+    getDeviceList();
   });
 </script>
 
diff --git a/src/views/qualityManagement/finalInspection/components/quickCheckDia.vue b/src/views/qualityManagement/finalInspection/components/quickCheckDia.vue
index cf78973..d4aef09 100644
--- a/src/views/qualityManagement/finalInspection/components/quickCheckDia.vue
+++ b/src/views/qualityManagement/finalInspection/components/quickCheckDia.vue
@@ -173,6 +173,9 @@
   selectedRows.value = rows;
   dialogVisible.value = true;
   
+  // 璁$畻閫変腑琛岀殑鎬绘暟閲�
+  const totalQuantity = rows.reduce((sum, row) => sum + (Number(row.quantity) || 0), 0);
+  
   // 鍔犺浇鐢ㄦ埛鍒楄〃
   const userListsRes = await userListNoPage();
   userList.value = userListsRes.data;
@@ -193,9 +196,9 @@
   form.value = {
     checkResult: '',
     testStandardId: '',
-    quantity: undefined,
-    qualifiedQuantity: undefined,
-    unqualifiedQuantity: undefined,
+    quantity: totalQuantity,
+    qualifiedQuantity: totalQuantity,
+    unqualifiedQuantity: 0,
     checkCompany: '',
     checkName: '',
     checkTime: '',

--
Gitblit v1.9.3