zck 10 tháng trước cách đây
mục cha
commit
ee1bcc9cde
1 tập tin đã thay đổi với 30 bổ sung13 xóa
  1. 30 13
      src/view/yunyin/shengchanguanli/baogongshuju.vue

+ 30 - 13
src/view/yunyin/shengchanguanli/baogongshuju.vue

@@ -307,9 +307,9 @@ DataListdata();
 const tableData = reactive([]);
 const _Machine = ref('');
 const _Machine_riqi = ref('');
-let parentGroup = '';
+let firstLayerValue  = null;
 
-//左侧树形节点点击事件
+// 左侧树形节点点击事件
 const handleNodeClick = async (node) => {
   // 重置所有节点颜色
   document.querySelectorAll('.treecolor .el-tree-node').forEach(node => {
@@ -325,26 +325,43 @@ const handleNodeClick = async (node) => {
   // 清空表格数据
   tableData.splice(0, tableData.length);
 
-  // // 判断点击节点的层级并设置相应值
-//日期不是固定的
-if (!node.children || node.children.length === 0) {
+  // 判断点击节点的层级并设置相应值
+  let firstLayerValue = null; // 用于存储当前分支的第一层值
+
+  // 递归查找第一层值
+  const findFirstLayerValue = (currentNode) => {
+    if (!currentNode.parent) {
+      // 如果当前节点没有父节点,说明它是第一层节点
+      firstLayerValue = currentNode.label;
+    } else {
+      // 递归查找父节点
+      findFirstLayerValue(currentNode.parent);
+    }
+  };
+
+  // 调用递归函数,查找当前分支的第一层值
+  findFirstLayerValue(node);
+
+  if (!node.children || node.children.length === 0) {
     // 第4层(日期节点)
     _Machine_riqi.value = node.label; // 日期为当前节点的值
     const parentNode = node.parent; // 获取父节点(如 CQ03--裁剪03组)
     if (parentNode) {
-        _Machine.value = parentNode.label.split('--')[0]; // 从父节点中提取机台名(CQ03)
+      _Machine.value = parentNode.label.split('--')[0]; // 从父节点中提取机台名(CQ03)
     }
-} else {
+  } else {
     // 非第4层节点
-    _Machine_riqi.value = "2024-12"; // 日期固定为年份
+    _Machine_riqi.value = firstLayerValue; // 使用当前分支的第一层值作为日期
+
     if (node.label.includes('--')) {
-        // 第3层(机台节点)
-        _Machine.value = node.label.split('--')[0]; // 提取机台名(CQ03)
+      // 第3层(机台节点)
+      _Machine.value = node.label.split('--')[0]; // 提取机台名(CQ03)
     } else {
-        // 第1层或第2层节点
-        _Machine.value = node.label; // 直接取节点名作为机台(如“裁剪”)
+      // 第1层或第2层节点
+      _Machine.value = node.label; // 直接取节点名作为机台(如“裁剪”)
     }
-}
+  }
+
   // 调用获取员工列表的函数
   _getStaffList();
 };