liuhairui 1 year ago
parent
commit
18e5cb99bd
1 changed files with 327 additions and 210 deletions
  1. 327 210
      src/view/performance/09-workOrderVerification/index.vue

+ 327 - 210
src/view/performance/09-workOrderVerification/index.vue

@@ -144,12 +144,12 @@
 									</el-table-column>
 									<el-table-column label="数量" width="100">
 										<template #default="{ row, $index }">
-											<el-input v-model="row.fp_sl" @keydown="ent1($event,$index,row,'数量')"/>
+											<el-input v-model="row.fp_sl" @keydown="ent1($event,$index,row,'数量')" @input="countEnter($index, row)"/>
 										</template>
 									</el-table-column>
 									<el-table-column label="工序及责任机长" >
-										<template #default="{ row }">
-											<el-input v-model="row.fp_gxmc" @keydown="ent1($event,$index,row,'')" readonly/>
+										<template #default="{ row, $index }">
+											<el-input v-model="row.fp_gxmc" @keydown="ent1($event,$index,row,'工序及责任机长')"/>
 										</template>
 									</el-table-column>
 									<el-table-column label="" width="100">
@@ -194,7 +194,7 @@
 					</el-dialog>
 
 					<!-- 弹出选项框 数量 -->
-					<el-dialog v-model="dialogSelectVisible2" title="数量选择" destroy-on-close width="800px" style="margin-top: 3%;" @keydown="selectSL($event)">
+					<el-dialog v-model="dialogSelectVisible2" title="数量选择" destroy-on-close width="830px" style="margin-top: 3%;" @keydown="selectSL($event)">
 					    <el-table tooltip-effect="dark" :data="selectData" row-key="ID" highlight-current-row border style="width:100%" @row-dblclick="handleSelectClick" ref="table2">
 					        <el-table-column v-for="column in selectColumns" :key="column.prop" :prop="column.prop" :label="column.label" :width="column.width" />
 					    </el-table>
@@ -583,7 +583,7 @@ const gd_lcdCancel = async () => {
 	const selectColumns = [{
 			label: '',
 			prop: 'sczl_gxmc',
-			width: '500'
+			width: '600'
 		},
 		{
 			label: '',
@@ -598,7 +598,7 @@ const gd_lcdCancel = async () => {
 		{
 			label: '',
 			prop: 'name',
-			width: '100'
+			width: '130'
 		},
 	]
 	// 行为控制标记(弹窗内部需要增还是改)
@@ -788,70 +788,72 @@ const gd_lcdCancel = async () => {
 	};
 
 
+	const countEnter = async (index, row) => {
+		// 计算总数
+		let total = 0;
+		detailData.table.forEach((item) => {
+		    if (item.fp_sl != 0 && item.fp_sl != '') {
+		        total += parseInt(item.fp_sl);
+		    }
+		});
+		detailData.qczl_fp = total;
+	}
+	
 	// 数量回车事件
 	let selectData = []; // 初始化为数组
-	const handleFpslEnter = async (event, index, row, title) => {
-	    // 保存当前行索引
-	    selectIndex.value = index;
-	
-	    // 如果数量为 0,则清空对应字段并直接返回
-	    if (row.fp_sl === 0 || row.fp_sl === '0' || row.fp_sl === '') {
-	        detailData.table[index].fp_gxmc = '';
-	        detailData.table[index].fp_bz = '';
-	        detailData.table[index].fp_bh = '';
-	        detailData.table[index].fp_name = '';
-	        return;
-	    }
+	// const handleFpslEnter = async (event, index, row, title) => {
+	//     // 保存当前行索引
+	//     selectIndex.value = index;
 	
-	    // 计算总数
-	    let total = 0;
-	    detailData.table.forEach((item) => {
-	        if (item.fp_sl != 0 && item.fp_sl != '') {
-	            total += parseInt(item.fp_sl);
-	        }
-	    });
-	    detailData.qczl_fp = total;
+	//     // 如果数量为 0,则清空对应字段并直接返回
+	//     if (row.fp_sl === 0 || row.fp_sl === '0' || row.fp_sl === '') {
+	//         detailData.table[index].fp_gxmc = '';
+	//         detailData.table[index].fp_bz = '';
+	//         detailData.table[index].fp_bh = '';
+	//         detailData.table[index].fp_name = '';
+	//         return;
+	//     }
 	
-	    // 调用接口获取数据
-	    const params = {
-	        type: row.fp_lb,
-	        order: detailData.qczl_gdbh,
-	        yjno: detailData.qczl_yjno,
-	    };
+	//     // 调用接口获取数据
+	//     const params = {
+	//         type: row.fp_lb,
+	//         order: detailData.qczl_gdbh,
+	//         yjno: detailData.qczl_yjno,
+	//     };
 	
-	    let res;
-	    try {
-	        res = await getGxAndLeader(params);
-	        console.log("接口返回结果", res);
-	        if (res.code !== 0) {
-	            return;
-	        }
-	    } catch (e) {
-	        console.log(e);
-	        return;
-	    }
+	//     let res;
+	//     try {
+	//         res = await getGxAndLeader(params);
+	//         console.log("接口返回结果", res);
+	//         if (res.code !== 0) {
+	//             return;
+	//         }
+	//     } catch (e) {
+	//         console.log(e);
+	//         return;
+	//     }
 	
-	    // 解析返回的数据
-	    const decodedData = res.data.map(item => ({
-	        sczl_gxmc: decodeEntities(item.sczl_gxmc),
-	        sczl_bzdh: item.sczl_bzdh,
-	        sczl_jtbbh: item.sczl_jtbh,
-	        sczl_bh1: item.sczl_bh1,
-	        name: item.name.trim(),
-	    }));
+	//     // 解析返回的数据
+	//     const decodedData = res.data.map(item => ({
+	//         sczl_gxmc: decodeEntities(item.sczl_gxmc),
+	//         sczl_bzdh: item.sczl_bzdh,
+	//         sczl_jtbbh: item.sczl_jtbh,
+	//         sczl_bh1: item.sczl_bh1,
+	//         name: item.name.trim(),
+	//     }));
 	
-	    // 如果数据为空,直接返回
-	    if (decodedData.length === 0) {
-	        console.log("接口返回数据为空");
-	        return;
-	    }
+	//     // 如果数据为空,直接返回
+	//     if (decodedData.length === 0) {
+	//         console.log("接口返回数据为空");
+	//         return;
+	//     }
 	
-	    // 初始化选中数据
-	    selectData = decodedData;
-	    SLIndex.value = 0; // 初始化索引为第一个
-	    setCurrent(selectData[0]); // 设置当前选中为第一个
-	    dialogSelectVisible2.value = true; // 显示弹窗
-	};
+	//     // 初始化选中数据
+	//     selectData = decodedData;
+	//     SLIndex.value = 0; // 初始化索引为第一个
+	//     setCurrent(selectData[0]); // 设置当前选中为第一个
+	//     dialogSelectVisible2.value = true; // 显示弹窗
+	// };
 	
 	// 选择逻辑
 	const SLIndex = ref(0); // 初始化索引为 0
@@ -889,7 +891,7 @@ const gd_lcdCancel = async () => {
 	        }
 	
 	        console.log("关闭弹窗,选中数据为:", selectedRow);
-	
+			console.log("selectIndex.value:", selectIndex.value);
 	        // 确保 selectIndex.value 是有效的当前行索引
 	        if (selectIndex.value !== null) {
 	            detailData.table[selectIndex.value].fp_gxmc = selectedRow.sczl_gxmc;
@@ -962,15 +964,15 @@ const gd_lcdCancel = async () => {
 		console.log(res)
 
 		if (res.code === 0) {
-			ElMessage({
-				type: 'success',
-				message: '新增成功',
-			})
+			ElMessage({type: 'success',message: '新增成功',})
 			//刷新
 			if (params.date != '') {
 				getTableData()
 			}
 			getSideData()
+			detailData.table.forEach((item, index) => {
+				item.fp_sl = 0;
+			});
 			// dialogFormVisible.value = false
 		}
 	};
@@ -1287,98 +1289,109 @@ const gd_lcdCancel = async () => {
 	  return result; // 确保返回的总是数组
 	};
 
-	//废品类别分类点击事件
-	const handleFplbClick = (node) => {
-	  const tree = table_fplb.value; // 获取树实例
-	  if (!tree) {
-		console.error("树实例未加载");
-		return;
-	  }
-	  // 清除上一次的选中状态
-	  clearPreviousSelection(tree);
-	  // 遍历所有节点,收起除了当前节点的其他节点
-	  Object.keys(tree.store.nodesMap).forEach((key) => {
-		if (key !== node.id.toString()) {
-		  tree.store.nodesMap[key].expanded = false; // 收起其他节点
-		}
-	  });
-	};
-
+	// 废品类别分类点击事件
+	const handleFplbClick = (node) => {
+	  const tree = table_fplb.value; // 获取树实例
+	  if (!tree) {
+	    console.error("树实例未加载");
+	    return;
+	  }
+	  // 清除上一次的选中状态
+	  clearPreviousSelection(tree);
+	  // 遍历所有节点,收起所有节点
+	  Object.keys(tree.store.nodesMap).forEach((key) => {
+	    tree.store.nodesMap[key].expanded = false; // 收起所有节点
+	  });
+	};
 	
 	// 废品类别分类键盘事件
-	const handleTreeKeydown = (event) => {
-	  if (event.keyCode === 13) { // 判断是否是回车键
-		const tree = table_fplb.value; // 获取树实例
-		if (!tree) {
-		  console.error("树组件未加载");
-		  return;
-		}
-
-		const focusedElement = document.activeElement;
-		const focusedNodeId = focusedElement?.getAttribute("data-key"); // 获取 DOM 的 data-key 属性
-
-		if (focusedNodeId) {
-		  tree.setCurrentKey(focusedNodeId); // 设置当前节点为选中
-		  tree.$nextTick(() => {
-			const currentNode = tree.getCurrentNode(); // 获取当前选中的节点
-			if (!currentNode) {
-			  console.warn("没有选中的节点");
-			  return;
-			}
-
-			// **收起所有其他节点**
-			Object.keys(tree.store.nodesMap).forEach((key) => {
-			  if (key !== currentNode.id.toString()) {
-				tree.store.nodesMap[key].expanded = false; // 收起非当前节点
-			  }
-			});
-
-			// **展开当前节点**
-			tree.store.nodesMap[currentNode.id].expanded = true;
-
-			// 如果当前节点有子节点,选中第一个子节点
-			if (currentNode.children && currentNode.children.length > 0) {
-			  const firstChild = currentNode.children[0];
-			  if (firstChild) {
-				const firstChildKey = firstChild.id.toString();
-				tree.setCurrentKey(firstChildKey); // 设置第一个子节点为选中
-				setTimeout(() => {
-				  const firstChildDom = tree.$el.querySelector(`[data-key="${firstChildKey}"]`);
-				  if (firstChildDom) {
-					firstChildDom.focus();
-					firstChildDom.scrollIntoView({ block: "nearest" });
-				  }
-				});
-			  }
-			} else {
-			  console.log("当前子节点:", currentNode.label);
-			  detailData.table[selectIndex.value].fp_lb = currentNode.label; // 更新数据
-			  dialogSelectVisible1.value = false; // 关闭对话框
-			}
-		  });
-		}
-	  }
+	const handleTreeKeydown = (event) => {
+	  const tree = table_fplb.value; // 获取树实例
+	  if (!tree) {
+	    console.error("树组件未加载");
+	    return;
+	  }
+	
+	  const focusedElement = document.activeElement;
+	  const focusedNodeId = focusedElement?.getAttribute("data-key"); // 获取 DOM 的 data-key 属性
+	
+	  if (event.keyCode === 13 && focusedNodeId) { // 判断是否是回车键
+	    tree.setCurrentKey(focusedNodeId); // 设置当前节点为选中
+	    tree.$nextTick(() => {
+	      const currentNode = tree.getCurrentNode(); // 获取当前选中的节点
+	      if (!currentNode) {
+	        console.warn("没有选中的节点");
+	        return;
+	      }
+		// 清除上一次的选中状态
+		clearPreviousSelection(tree);
+	      // 收起所有其他节点
+	      Object.keys(tree.store.nodesMap).forEach((key) => {
+	        tree.store.nodesMap[key].expanded = false; // 收起所有节点
+	      });
+	
+	      // 展开当前节点
+	      tree.store.nodesMap[currentNode.id].expanded = true;
+	
+	      // 如果当前节点有子节点,选中第一个子节点
+	      if (currentNode.children && currentNode.children.length > 0) {
+	        const firstChild = currentNode.children[0];
+	        if (firstChild) {
+	          const firstChildKey = firstChild.id.toString();
+	          tree.setCurrentKey(firstChildKey); // 设置第一个子节点为选中
+	          setTimeout(() => {
+	            const firstChildDom = tree.$el.querySelector(`[data-key="${firstChildKey}"]`);
+	            if (firstChildDom) {
+	              firstChildDom.focus();
+	              firstChildDom.scrollIntoView({ block: "nearest" });
+	            }
+	          });
+	        }
+	      } else {
+	        console.log("当前子节点:", currentNode.label);
+	        detailData.table[selectIndex.value].fp_lb = currentNode.label; // 更新数据
+	        dialogSelectVisible1.value = false; // 关闭对话框
+	      }
+	    });
+	  } else if (event.keyCode === 38 || event.keyCode === 40) { // 上下箭头键
+	    const currentNode = tree.getCurrentNode();
+	    if (currentNode) {
+	      const currentNodeDom = tree.$el.querySelector(`[data-key="${currentNode.id}"]`);
+	      if (currentNodeDom) {
+	        currentNodeDom.focus();
+	      }
+	    }
+	  }
 	};
 	
-	//工序弹出框键盘事件
-	const ent = (event) => {
-	  if (document.activeElement.id === "tableFplb") {
-		if (table_fplb.value) {
-		  const tree = table_fplb.value?.$el;
-		  console.log(111, tree);
-		  if (tree) {
-			const node = tree.querySelector("[data-key]");
-			console.log(222, node);
-			if (event.keyCode === 13) {
-			  dialogSelectVisible1.value = false;
-			}
-			if (node) {
-			  node.scrollIntoView({ block: "nearest" }); // 确保节点可见
-			  node.focus(); // 确保焦点正确
-			}
-		  }
-		}
-	  }
+	// 工序弹出框键盘事件
+	const ent = (event) => {
+	  if (document.activeElement.id === "tableFplb") {
+	    if (table_fplb.value) {
+	      const tree = table_fplb.value?.$el;
+	      console.log(111, tree);
+	      if (tree) {
+	        const node = tree.querySelector("[data-key]");
+	        console.log(222, node);
+	        if (event.keyCode === 13) {
+	          dialogSelectVisible1.value = false;
+	        }
+	        if (node) {
+	          node.scrollIntoView({ block: "nearest" }); // 确保节点可见
+	          node.focus(); // 确保焦点正确
+	        }
+	      }
+	    }
+	  }
+	};
+	
+	// 清除之前的选中状态
+	const clearPreviousSelection = (tree) => {
+	  const selectedNodes = tree.getCheckedNodes();
+	  selectedNodes.forEach(node => {
+	    tree.setChecked(node, false);
+	  });
+	  tree.setCurrentKey(null);
 	};
 	
 	
@@ -1533,71 +1546,175 @@ const gd_lcdCancel = async () => {
 				   nextIndex++;
 			   }
 	   }else if (event.keyCode === 13 && title === '数量') {
-		if (isProcessing) {
-		  console.log("当前正在处理回车事件,忽略重复触发");
-		  return; // 如果正在处理,直接返回
-		}
-
-		isProcessing = true; // 标志正在处理
-		event.preventDefault(); // 阻止默认行为
+		  // 去掉数量前导的0
+		  if (typeof row.fp_sl === 'string') {
+			row.fp_sl = row.fp_sl.replace(/^0+(?=\d)/, '');
+		  }
 
-		// 去掉数量前导的0
-		if (typeof row.fp_sl === 'string') {
-		  row.fp_sl = row.fp_sl.replace(/^0+(?=\d)/, '');
-		}
+		  // 判断数量是否为 0 或为空
+		  if (row.fp_sl === '0' || row.fp_sl === '' || row.fp_sl === 0) {
+			console.log("数量为 0,清空对应字段");
+			['fp_gxmc', 'fp_bz', 'fp_bh', 'fp_name'].forEach(field => {
+			  detailData.table[index][field] = '';
+			});
+		  } 
 
-		// 判断数量是否为 0 或为空
-		if (row.fp_sl === '0' || row.fp_sl === '' || row.fp_sl === 0) {
-		  console.log("数量为 0,清空对应字段");
-		  ['fp_gxmc', 'fp_bz', 'fp_bh', 'fp_name'].forEach(field => {
-			detailData.table[index][field] = '';
-		  });
-		} else {
-		  // 检查数量是否与上一次相同
-		  if (row.fp_sl !== lastFpSl) {
-			// 异步调用 handleFpslEnter
-			await handleFpslEnter(event, index, row, title);
-			lastFpSl = row.fp_sl; // 更新记录的数量
+		  // 焦点跳转逻辑
+		  let nextIndex = currentIndex + 1;
+		  let foundNext = false;
 
-			if (!detailData.table[index].fp_gxmc) {
-			  console.log("字段 fp_gxmc 为空,不能跳转到下一个输入框");
-			  isProcessing = false; // 重置标志
-			  return; // 阻止跳转
+		  while (nextIndex < inputs.length) {
+			const nextInput = inputs[nextIndex];
+			if (!nextInput.disabled && !nextInput.readOnly) {
+			  nextInput.focus();
+			  nextInput.select();
+			  foundNext = true;
+			  console.log(`焦点已跳转到输入框索引: ${nextIndex}`);
+			  break;
 			}
-		  } else {
-			console.log("数量未变化,跳过 handleFpslEnter 调用");
-		  }
-		}
-
-		// 焦点跳转逻辑
-		let nextIndex = currentIndex + 1;
-		let foundNext = false;
-
-		while (nextIndex < inputs.length) {
-		  const nextInput = inputs[nextIndex];
-		  if (!nextInput.disabled && !nextInput.readOnly) {
-			nextInput.focus();
-			nextInput.select();
-			foundNext = true;
-			console.log(`焦点已跳转到输入框索引: ${nextIndex}`);
-			break;
+			nextIndex++;
 		  }
-		  nextIndex++;
-		}
 
-		if (!foundNext) {
-		  console.log("未找到下一个可用的输入框");
+		  if (!foundNext) {
+			console.log("未找到下一个可用的输入框");
 
-		  enterCount++; // 增加回车键按下的次数
+			enterCount++; // 增加回车键按下的次数
 
-		  if (enterCount === 2) {
-			dialogbutton.value = true; // 第二次按下回车键时弹出弹窗
-			enterCount = 0; // 重置计数器
+			if (enterCount === 2) {
+			  dialogbutton.value = true; // 第二次按下回车键时弹出弹窗
+			  enterCount = 0; // 重置计数器
+			}
 		  }
-		}
 
-		isProcessing = false; // 标志位重置,允许下一次回车处理
-	  }else if (event.keyCode === 13 || event.keyCode === 40 && title === '') {
+		  isProcessing = false; // 标志位重置,允许下一次回车处理
+		}else 
+	if (event.keyCode === 13 && title === '工序及责任机长') {
+	    console.log('工序及责任机长');
+	    console.log('row', row['fp_gxmc']);
+	
+	    // 判断工序字段是否为空
+	    if (!row.fp_gxmc || row.fp_gxmc.trim() === '') {
+	        console.log('工序及责任机长为空,跳转到下一个输入框');
+	        let nextIndex = currentIndex + 1;
+	        let foundNext = false;
+	
+	        // 找下一个可用输入框
+	        while (nextIndex < inputs.length) {
+	            if (!inputs[nextIndex].disabled && !inputs[nextIndex].readOnly) {
+	                nextTick(() => {
+	                    inputs[nextIndex].focus();
+	                    inputs[nextIndex].select();
+	                });
+	                foundNext = true;
+	                break;
+	            }
+	            nextIndex++;
+	        }
+	
+	        // 如果找不到下一个输入框,触发弹窗逻辑
+	        if (!foundNext) {
+	            console.log('未找到下一个可用的输入框');
+	            dialogbutton.value = true;
+	            handleKeydown();
+	        }
+	        return; // 提前返回
+	    }
+	
+	    // 如果数量为 0,清空字段并返回
+	    if (row.fp_sl === 0 || row.fp_sl === '0' || row.fp_sl === '') {
+	        detailData.table[index].fp_gxmc = '';
+	        detailData.table[index].fp_bz = '';
+	        detailData.table[index].fp_bh = '';
+	        detailData.table[index].fp_name = '';
+	        return;
+	    }
+	
+	    // 保存当前行索引
+	    selectIndex.value = index;
+	
+	    // 调用接口获取数据
+	    const params = {
+	        type: row.fp_lb,
+	        order: detailData.qczl_gdbh,
+	        yjno: detailData.qczl_yjno,
+	    };
+	
+	    let res;
+	    try {
+	        res = await getGxAndLeader(params);
+	        console.log('接口返回结果', res);
+	        if (res.code !== 0) {
+	            return; // 如果接口报错,直接返回
+	        }
+	    } catch (e) {
+	        console.log('接口调用异常:', e);
+	        return;
+	    }
+	
+	    // 解析接口返回数据
+	    const decodedData = res.data.map(item => ({
+	        sczl_gxmc: item.sczl_gxmc,
+	        sczl_bzdh: item.sczl_bzdh,
+	        sczl_jtbbh: item.sczl_jtbh,
+	        sczl_bh1: item.sczl_bh1,
+	        name: item.name ? item.name.trim() : '', // 防止 name 为 null
+	    }));
+	
+	    // 如果接口返回数据为空,直接返回
+	    if (decodedData.length === 0) {
+	        console.log('接口返回数据为空');
+	        return;
+	    }
+	
+	    console.log('row:', row);
+	
+	    // 匹配接口返回数据中的 sczl_gxmc
+	    const matchedItem = decodedData.find(item => {
+	        console.log('正在匹配:', item.sczl_gxmc, '与', row.fp_gxmc);
+	        return item.sczl_gxmc === row.fp_gxmc; // 直接全量匹配 row.fp_gxmc 和接口返回的 sczl_gxmc
+	    });
+	
+	    console.log('匹配到的项:', matchedItem);
+	
+	    if (matchedItem) {
+	        // 如果找到匹配的数据,更新当前行
+	        console.log('匹配成功,数据正确,不需要弹窗');
+	        detailData.table[index].fp_bz = matchedItem.sczl_bzdh;
+	        detailData.table[index].fp_bh = matchedItem.sczl_bh1;
+	        detailData.table[index].fp_name = matchedItem.name;
+	
+	        // 跳转到下一个输入框
+	        let nextIndex = currentIndex + 1;
+	        let foundNext = false;
+	
+	        while (nextIndex < inputs.length) {
+	            if (!inputs[nextIndex].disabled && !inputs[nextIndex].readOnly) {
+	                nextTick(() => {
+	                    inputs[nextIndex].focus();
+	                    inputs[nextIndex].select();
+	                });
+	                foundNext = true;
+	                break;
+	            }
+	            nextIndex++;
+	        }
+	
+	        if (!foundNext) {
+	            console.log('未找到下一个可用的输入框');
+	            dialogbutton.value = true;
+	            handleKeydown();
+	        }
+	    } else {
+	        // 如果未找到匹配的数据,弹窗选择
+	        console.log('匹配失败,需要弹窗');
+	        selectData = decodedData;
+	        SLIndex.value = 0; // 初始化索引为第一个
+	        setCurrent(selectData[0]); // 设置当前选中为第一个
+	        dialogSelectVisible2.value = true; // 显示弹窗
+	    }
+	}
+
+		else if (event.keyCode === 13 || event.keyCode === 40 && title === '') {
 		   console.log('其他')
 		   let nextIndex = currentIndex + 1;
 		   let foundNext = false; // 标记是否找到下一个可用的输入框