|  | @@ -3275,8 +3275,8 @@ function callYbSaleGoodsItem(realNo, orderNo, receiptNo, times, patientId, name,
 | 
	
		
			
				|  |  |   * @param name 病人姓名
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  function callYbReturnGoodsItem(realNo, orderNo, receiptNo, times, patientId, name) {
 | 
	
		
			
				|  |  | -    // 获取退药明细数据
 | 
	
		
			
				|  |  | -    let tableData = $("#tb_table").bootstrapTable('getData');
 | 
	
		
			
				|  |  | +    // 获取退药明细数据 - 使用全局变量中保存的退药数据
 | 
	
		
			
				|  |  | +    let tableData = window.currentRefundData || $table.bootstrapTable('getData');
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      if (!tableData || tableData.length === 0) {
 | 
	
		
			
				|  |  |          console.log('没有退药明细数据,跳过医保接口调用');
 | 
	
	
		
			
				|  | @@ -3297,11 +3297,22 @@ function callYbReturnGoodsItem(realNo, orderNo, receiptNo, times, patientId, nam
 | 
	
		
			
				|  |  |                       String(currentTime.getSeconds()).padStart(2, '0');
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      // 为每个退药药品调用一次医保接口
 | 
	
		
			
				|  |  | +    console.log('开始处理退药数据,总数:', tableData.length);
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |      for (let i = 0; i < tableData.length; i++) {
 | 
	
		
			
				|  |  |          let item = tableData[i];
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | +        console.log('处理第', i + 1, '条退药记录:', {
 | 
	
		
			
				|  |  | +            'drugname': item.drugname,
 | 
	
		
			
				|  |  | +            'dec_amount': item.dec_amount,
 | 
	
		
			
				|  |  | +            'charge_item_code': item.charge_item_code,
 | 
	
		
			
				|  |  | +            'serial': item.serial,
 | 
	
		
			
				|  |  | +            'item_no': item.item_no
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          // 只处理有退药数量的药品
 | 
	
		
			
				|  |  |          if (item.dec_amount == 0) {
 | 
	
		
			
				|  |  | +            console.log('跳过数量为0的药品:', item.drugname);
 | 
	
		
			
				|  |  |              continue;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
	
		
			
				|  | @@ -3352,10 +3363,25 @@ function callYbReturnGoodsItem(realNo, orderNo, receiptNo, times, patientId, nam
 | 
	
		
			
				|  |  |              // 查找对应的追溯码
 | 
	
		
			
				|  |  |              for (let j = 0; j < tyTable.length; j++) {
 | 
	
		
			
				|  |  |                  let tyItem = tyTable[j];
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                // 调试日志
 | 
	
		
			
				|  |  | +                console.log('追溯码匹配检查:', {
 | 
	
		
			
				|  |  | +                    'tyItem.chargeItemCode': tyItem.chargeItemCode,
 | 
	
		
			
				|  |  | +                    'item.charge_item_code': item.charge_item_code,
 | 
	
		
			
				|  |  | +                    'tyItem.serial': tyItem.serial,
 | 
	
		
			
				|  |  | +                    'item.serial': item.serial,
 | 
	
		
			
				|  |  | +                    'tyItem.itemNo': tyItem.itemNo,
 | 
	
		
			
				|  |  | +                    'item.item_no': item.item_no,
 | 
	
		
			
				|  |  | +                    'tyItem.drugTracCodg': tyItem.drugTracCodg
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                // 匹配条件:收费项目编码、流水号、项目序号
 | 
	
		
			
				|  |  |                  if (tyItem.chargeItemCode === item.charge_item_code && 
 | 
	
		
			
				|  |  |                      tyItem.serial === item.serial && 
 | 
	
		
			
				|  |  |                      tyItem.itemNo === item.item_no) {
 | 
	
		
			
				|  |  |                      
 | 
	
		
			
				|  |  | +                    console.log('追溯码匹配成功:', tyItem.drugTracCodg);
 | 
	
		
			
				|  |  | +                    
 | 
	
		
			
				|  |  |                      if (tyItem.drugTracCodg && tyItem.drugTracCodg.trim() !== '') {
 | 
	
		
			
				|  |  |                          // 提取追溯码(去除HTML标签)
 | 
	
		
			
				|  |  |                          let tracCode = tyItem.drugTracCodg.replace(/<[^>]*>/g, '').trim();
 | 
	
	
		
			
				|  | @@ -3363,11 +3389,14 @@ function callYbReturnGoodsItem(realNo, orderNo, receiptNo, times, patientId, nam
 | 
	
		
			
				|  |  |                              ybData.drugtracinfo.push({
 | 
	
		
			
				|  |  |                                  drugTracCodg: tracCode
 | 
	
		
			
				|  |  |                              });
 | 
	
		
			
				|  |  | +                            console.log('添加追溯码到医保参数:', tracCode);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                      break;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            console.log('退药匹配表格为空,无法获取追溯码');
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          // 如果没有追溯码,添加空数组(保持数据结构一致)
 |