|  | @@ -1437,11 +1437,34 @@ function prescriptionDetail(realNo, orderNo, receiptNo, times, patientId, confir
 | 
	
		
			
				|  |  |              if (field === 'drugTracCodg') {
 | 
	
		
			
				|  |  |                  $element.attr('contenteditable', true);
 | 
	
		
			
				|  |  |                  $element.focus();
 | 
	
		
			
				|  |  | -                $element.blur(function () {
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                // 添加扫码输入监听(新增功能,不影响原有逻辑)
 | 
	
		
			
				|  |  | +                let inputTimer = null;
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                $element.off('input.tracCodg').on('input.tracCodg', function(e) {
 | 
	
		
			
				|  |  | +                    let inputValue = e.target.textContent || e.target.innerText;
 | 
	
		
			
				|  |  | +                    
 | 
	
		
			
				|  |  | +                    // 清除之前的定时器
 | 
	
		
			
				|  |  | +                    if (inputTimer) {
 | 
	
		
			
				|  |  | +                        clearTimeout(inputTimer);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    
 | 
	
		
			
				|  |  | +                    // 设置防抖定时器,0.5秒后触发验证
 | 
	
		
			
				|  |  | +                    inputTimer = setTimeout(function() {
 | 
	
		
			
				|  |  | +                        if (inputValue && inputValue.trim().length > 0) {
 | 
	
		
			
				|  |  | +                            // 保存当前内容,用于验证失败时恢复
 | 
	
		
			
				|  |  | +                            let originalContent = $element.html();
 | 
	
		
			
				|  |  | +                            validateAndAddTracCodg(inputValue.trim(), row, $element, originalContent);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }, 500);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                // 保持原有的失去焦点保存逻辑
 | 
	
		
			
				|  |  | +                $element.off('blur.tracCodg').blur(function () {
 | 
	
		
			
				|  |  |                      let index = $element.parent().data('index');
 | 
	
		
			
				|  |  |                      let tdValue = $element.html();
 | 
	
		
			
				|  |  |                      saveCellData($('#tb_table_right'), index, field, tdValue);
 | 
	
		
			
				|  |  | -                })
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          },
 | 
	
		
			
				|  |  |          responseHandler: function (res) {
 | 
	
	
		
			
				|  | @@ -2828,4 +2851,104 @@ $(document).ready(function () {
 | 
	
		
			
				|  |  |      isTyOk = false;
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      initTbTable();
 | 
	
		
			
				|  |  | -});
 | 
	
		
			
				|  |  | +});
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 验证并添加追溯码
 | 
	
		
			
				|  |  | + * @param tracCodg 追溯码
 | 
	
		
			
				|  |  | + * @param rowData 行数据
 | 
	
		
			
				|  |  | + * @param $element 单元格元素
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function validateAndAddTracCodg(tracCodg, rowData, $element, originalContent) {
 | 
	
		
			
				|  |  | +    // 构建验证数据,只包含可以从rowData中获取的字段
 | 
	
		
			
				|  |  | +    let validateData = {
 | 
	
		
			
				|  |  | +        drugTracCodg: tracCodg,  // 这是用户扫码输入的追溯码
 | 
	
		
			
				|  |  | +        patientId: rowData.patientId,
 | 
	
		
			
				|  |  | +        times: rowData.times,
 | 
	
		
			
				|  |  | +        receiptNo: rowData.receiptNo,
 | 
	
		
			
				|  |  | +        orderNo: rowData.orderNo,
 | 
	
		
			
				|  |  | +        itemNo: rowData.itemNo,
 | 
	
		
			
				|  |  | +        chargeItemCode: rowData.chargeItemCode,
 | 
	
		
			
				|  |  | +        drugName: rowData.drugname,
 | 
	
		
			
				|  |  | +        specification: rowData.specification
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    // 添加调试日志
 | 
	
		
			
				|  |  | +    console.log('验证追溯码参数:', validateData);
 | 
	
		
			
				|  |  | +    console.log('行数据:', rowData);
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    $.ajax({
 | 
	
		
			
				|  |  | +        type: "POST",
 | 
	
		
			
				|  |  | +        url: '/thmz/validateDrugTracCodgForDispensing',
 | 
	
		
			
				|  |  | +        contentType: "application/json;charset=UTF-8",
 | 
	
		
			
				|  |  | +        dataType: "json",
 | 
	
		
			
				|  |  | +        headers: {
 | 
	
		
			
				|  |  | +            'Accept': 'application/json',
 | 
	
		
			
				|  |  | +            'Authorization': 'Bearer ' + localStorage.getItem("token")
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        data: JSON.stringify(validateData),
 | 
	
		
			
				|  |  | +        success: function (res) {
 | 
	
		
			
				|  |  | +            console.log('验证响应:', res);
 | 
	
		
			
				|  |  | +            if (res.code == 0 && res.data && res.data.isValid) {
 | 
	
		
			
				|  |  | +                // 验证成功,添加到追溯码集合
 | 
	
		
			
				|  |  | +                addTracCodgToCell(tracCodg, $element);
 | 
	
		
			
				|  |  | +                successMesage(res);
 | 
	
		
			
				|  |  | +                // 验证成功后,保持单元格可编辑状态,用户可以继续扫码
 | 
	
		
			
				|  |  | +                $element.focus();
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                // 验证失败
 | 
	
		
			
				|  |  | +                errorMesage(res);
 | 
	
		
			
				|  |  | +                // 验证失败时,恢复原始内容
 | 
	
		
			
				|  |  | +                if (originalContent !== undefined) {
 | 
	
		
			
				|  |  | +                    $element.html(originalContent);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                // 保持焦点,让用户继续扫码
 | 
	
		
			
				|  |  | +                $element.focus();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        error: function (xhr, status, error) {
 | 
	
		
			
				|  |  | +            console.error('验证请求失败:', error);
 | 
	
		
			
				|  |  | +            errorMesageSimaple("验证请求失败");
 | 
	
		
			
				|  |  | +            // 错误时也恢复原始内容
 | 
	
		
			
				|  |  | +            if (originalContent !== undefined) {
 | 
	
		
			
				|  |  | +                $element.html(originalContent);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $element.focus();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 添加追溯码到单元格
 | 
	
		
			
				|  |  | + * @param tracCodg 追溯码
 | 
	
		
			
				|  |  | + * @param $element 单元格元素
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +function addTracCodgToCell(tracCodg, $element) {
 | 
	
		
			
				|  |  | +    let currentValue = $element.html();
 | 
	
		
			
				|  |  | +    let newValue = '';
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    if (isEmpty(currentValue)) {
 | 
	
		
			
				|  |  | +        newValue = tracCodg;
 | 
	
		
			
				|  |  | +    } else {
 | 
	
		
			
				|  |  | +        // 检查是否已存在该追溯码
 | 
	
		
			
				|  |  | +        let existingCodes = currentValue.split('<br>');
 | 
	
		
			
				|  |  | +        if (!existingCodes.includes(tracCodg)) {
 | 
	
		
			
				|  |  | +            newValue = currentValue + '<br>' + tracCodg;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            // 追溯码已存在,显示提示但不显示错误样式
 | 
	
		
			
				|  |  | +            console.log('追溯码已存在:', tracCodg);
 | 
	
		
			
				|  |  | +            // 使用简单的提示,而不是错误消息
 | 
	
		
			
				|  |  | +            if (typeof PNotify !== 'undefined') {
 | 
	
		
			
				|  |  | +                new PNotify({
 | 
	
		
			
				|  |  | +                    title: '提示',
 | 
	
		
			
				|  |  | +                    text: '该追溯码已添加',
 | 
	
		
			
				|  |  | +                    type: 'info',
 | 
	
		
			
				|  |  | +                    delay: 2000
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    $element.html(newValue);
 | 
	
		
			
				|  |  | +}
 |