From 9dcde5b27b70a4b0c0885347af5405eb2d1ef089 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期五, 12 十二月 2025 17:00:54 +0800
Subject: [PATCH] 修改前端状态显示变更,保持前端实时更新

---
 mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 169 insertions(+), 8 deletions(-)

diff --git a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
index 3021519..5f2b44e 100644
--- a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
+++ b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
@@ -35,12 +35,51 @@
     </div>
 
     <el-form :model="form" label-width="120px" :rules="rules" ref="formRef">
+      <div style="width: 350px; margin-bottom: 12px; margin-left: 120px;">
+          <el-select 
+            v-model="selectedEngineeringId" 
+            placeholder="閫夋嫨宸ョ▼鍙凤紙閫夋嫨鍚庤嚜鍔ㄥ~鍏呯幓鐠僆D锛�"
+            clearable
+            filterable
+            :disabled="!group"
+            :loading="engineeringListLoading"
+            @change="handleEngineeringChange"
+            style="width: 100%"
+          >
+            <el-option
+              v-for="item in engineeringList"
+              :key="item.engineeringId"
+              :label="item.engineeringId"
+              :value="item.engineeringId"
+            >
+              <div style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
+                <div style="flex: 1;">
+                  <span>{{ item.engineeringId }}</span>
+                  <span style="margin-left: 8px; color: #8492a6; font-size: 12px">
+                    {{ item.date ? new Date(item.date).toLocaleDateString() : '' }}
+                  </span>
+                </div>
+                <el-button
+                  type="danger"
+                  link
+                  size="small"
+                  :loading="deletingEngineeringId === item.engineeringId"
+                  @click.stop="handleDeleteEngineering(item.engineeringId)"
+                  style="margin-left: 8px; padding: 0 4px;"
+                >
+                  <el-icon><Delete /></el-icon>
+                </el-button>
+              </div>
+            </el-option>
+          </el-select>
+        </div>
+        
       <el-form-item label="鐜荤拑ID鍒楄〃" prop="glassIds">
         <el-input
           v-model="glassIdsInput"
           type="textarea"
           :rows="4"
-          placeholder="鍙�夛細杈撳叆鐜荤拑ID锛屽皢浣跨敤杈撳叆鐨処D杩涜娴嬭瘯"
+          placeholder="鍙�夛細杈撳叆鐜荤拑ID锛屽皢浣跨敤杈撳叆鐨処D杩涜娴嬭瘯锛堟垨閫氳繃涓婃柟閫夋嫨宸ョ▼鍙疯嚜鍔ㄥ~鍏咃級"
           show-word-limit
           :maxlength="5000"
         />
@@ -57,8 +96,8 @@
 </template>
 
 <script setup>
-import { computed, reactive, ref, watch } from 'vue'
-import { ElMessage } from 'element-plus'
+import { computed, reactive, ref, watch, onMounted } from 'vue'
+import { ElMessage, ElMessageBox } from 'element-plus'
 import { Delete, Promotion, Upload } from '@element-plus/icons-vue'
 import * as XLSX from 'xlsx'
 import { multiDeviceTaskApi } from '@/api/device/multiDeviceTask'
@@ -116,13 +155,27 @@
 const loadDeviceLoading = ref(false)
 const fileInputRef = ref(null)
 
+// 宸ョ▼鍙风浉鍏�
+const selectedEngineeringId = ref('')
+const engineeringList = ref([])
+const engineeringListLoading = ref(false)
+const glassIdsLoading = ref(false)
+const deletingEngineeringId = ref('')
+
 watch(
   () => props.group,
   () => {
     glassIdsInput.value = ''
+    selectedEngineeringId.value = ''
     fetchLoadDevice()
+    fetchEngineeringList()
   }
 )
+
+// 缁勪欢鎸傝浇鏃跺姞杞藉伐绋嬪彿鍒楄〃
+onMounted(() => {
+  fetchEngineeringList()
+})
 
 const glassIds = computed(() => {
   if (!glassIdsInput.value) return []
@@ -131,6 +184,108 @@
     .map((item) => item.trim())
     .filter((item) => item.length > 0)
 })
+
+// 鑾峰彇宸ョ▼鍙峰垪琛�
+const fetchEngineeringList = async () => {
+  try {
+    engineeringListLoading.value = true
+    const response = await engineeringApi.getEngineeringList()
+
+    if (Array.isArray(response)) {
+      engineeringList.value = response
+    } else if (Array.isArray(response?.data)) {
+      engineeringList.value = response.data
+    } else {
+      engineeringList.value = []
+    }
+    // 鎸夋棩鏈熷�掑簭鎺掑垪
+    engineeringList.value.sort((a, b) => {
+      const dateA = a.date ? new Date(a.date).getTime() : 0
+      const dateB = b.date ? new Date(b.date).getTime() : 0
+      return dateB - dateA
+    })
+  } catch (error) {
+    console.error('鑾峰彇宸ョ▼鍙峰垪琛ㄥけ璐�:', error)
+    ElMessage.error(error?.message || '鑾峰彇宸ョ▼鍙峰垪琛ㄥけ璐�')
+    engineeringList.value = []
+  } finally {
+    engineeringListLoading.value = false
+  }
+}
+
+// 澶勭悊宸ョ▼鍙烽�夋嫨鍙樺寲
+const handleEngineeringChange = async (engineeringId) => {
+  if (!engineeringId) {
+    // 娓呯┖閫夋嫨鏃讹紝涓嶆竻绌哄凡杈撳叆鐨勭幓鐠僆D锛岃鐢ㄦ埛淇濈暀
+    return
+  }
+  
+  try {
+    glassIdsLoading.value = true
+    const response = await engineeringApi.getGlassIdsByEngineeringId(engineeringId)
+
+    const glassIds = response?.glassIds || response?.data?.glassIds || []
+    
+    if (glassIds.length > 0) {
+      glassIdsInput.value = glassIds.join('\n')
+      ElMessage.success(`宸插姞杞藉伐绋嬪彿 ${engineeringId} 鐨� ${glassIds.length} 涓幓鐠僆D`)
+    } else {
+      ElMessage.warning(`宸ョ▼鍙� ${engineeringId} 涓嬫病鏈夋壘鍒扮幓鐠僆D`)
+    }
+  } catch (error) {
+    console.error('鑾峰彇鐜荤拑ID鍒楄〃澶辫触:', error)
+    ElMessage.error(error?.message || '鑾峰彇鐜荤拑ID鍒楄〃澶辫触')
+  } finally {
+    glassIdsLoading.value = false
+  }
+}
+
+// 澶勭悊鍒犻櫎宸ョ▼鍙�
+const handleDeleteEngineering = async (engineeringId) => {
+  if (!engineeringId) {
+    return
+  }
+
+  try {
+    await ElMessageBox.confirm(
+      `纭畾瑕佸垹闄ゅ伐绋嬪彿 "${engineeringId}" 鍙婂叾鍏宠仈鐨勬墍鏈夌幓鐠冧俊鎭悧锛熸鎿嶄綔涓嶅彲鎭㈠锛乣,
+      '纭鍒犻櫎',
+      {
+        confirmButtonText: '纭畾鍒犻櫎',
+        cancelButtonText: '鍙栨秷',
+        type: 'warning',
+        dangerouslyUseHTMLString: false
+      }
+    )
+
+    deletingEngineeringId.value = engineeringId
+    const response = await engineeringApi.deleteEngineering(engineeringId)
+    
+    const result = response?.data || response
+    if (result?.success !== false) {
+      const deletedCount = result?.deletedGlassCount || 0
+      ElMessage.success(`宸插垹闄ゅ伐绋嬪彿 ${engineeringId}锛屽叡鍒犻櫎 ${deletedCount} 鏉$幓鐠冧俊鎭痐)
+      
+      // 濡傛灉鍒犻櫎鐨勬槸褰撳墠閫変腑鐨勫伐绋嬪彿锛屾竻绌洪�夋嫨
+      if (selectedEngineeringId.value === engineeringId) {
+        selectedEngineeringId.value = ''
+        glassIdsInput.value = ''
+      }
+      
+      // 鍒锋柊宸ョ▼鍙峰垪琛�
+      await fetchEngineeringList()
+    } else {
+      throw new Error(result?.message || '鍒犻櫎澶辫触')
+    }
+  } catch (error) {
+    if (error !== 'cancel') {
+      console.error('鍒犻櫎宸ョ▼鍙峰け璐�:', error)
+      ElMessage.error(error?.message || '鍒犻櫎宸ョ▼鍙峰け璐�')
+    }
+  } finally {
+    deletingEngineeringId.value = ''
+  }
+}
 
 const normalizeType = (type) => (type || '').trim().toUpperCase()
 
@@ -461,7 +616,7 @@
     const qty = parseInt(quantity) || 1
     for (let j = 0; j < qty; j++) {
       // 濡傛灉鏁伴噺澶т簬1锛屼负姣忔潯璁板綍鐢熸垚鍞竴鐨勭幓鐠僆D锛堣拷鍔犲簭鍙凤級
-      const finalGlassId = qty > 1 ? `${glassId}_${j + 1}` : glassId
+      const finalGlassId = qty > 1 ? `${glassId}${j + 1}` : glassId
 
       result.push({
         glassId: finalGlassId,
@@ -508,10 +663,16 @@
         : `鎴愬姛瀵煎叆 ${glassDataList.length} 鏉$幓鐠冩暟鎹甡
       ElMessage.success(successMsg)
 
-      // 灏嗗鍏ョ殑鐜荤拑ID濉厖鍒拌緭鍏ユ锛屾柟渚跨敤鎴锋煡鐪嬪拰缂栬緫
-      const glassIds = glassDataList.map(item => item.glassId).filter(id => id)
-      if (glassIds.length > 0) {
-        glassIdsInput.value = glassIds.join('\n')
+      // 鎴愬姛鍚庡埛鏂板伐绋嬪彿涓嬫媺鍒楄〃锛屽苟閫変腑鏈�鏂板伐绋嬪彿
+      try {
+        await fetchEngineeringList()
+        if (engineerId) {
+          selectedEngineeringId.value = engineerId
+          // 鍒锋柊骞跺洖濉悗绔繚瀛樼殑 glassId锛堝甫宸ョ▼鍙峰墠缂�锛夛紝閬垮厤浣跨敤鍓嶇鍘熷鍊�
+          await handleEngineeringChange(engineerId)
+        }
+      } catch (refreshErr) {
+        console.error('鍒锋柊宸ョ▼鍙峰垪琛ㄥけ璐�:', refreshErr)
       }
     } else {
       // MES 鎺ュ彛杩斿洖澶辫触

--
Gitblit v1.8.0