LIJU 2 주 전
부모
커밋
a12d423ab7
1개의 변경된 파일73개의 추가작업 그리고 29개의 파일을 삭제
  1. 73 29
      src/main/resources/static/js/mz/west_pharmacy_send.js

+ 73 - 29
src/main/resources/static/js/mz/west_pharmacy_send.js

@@ -3411,48 +3411,92 @@ function callYbReturnGoodsItem(realNo, orderNo, receiptNo, times, patientId, nam
             drugtracinfo: []
         };
         
-        // 直接从退药表格获取追溯码(与发药接口保持一致)
-        if (item.drugTracCodg && item.drugTracCodg.trim() !== '') {
-            let tracCodes = item.drugTracCodg.split('<br>').filter(code => code.trim() !== '');
-            for (let j = 0; j < tracCodes.length; j++) {
-                ybData.drugtracinfo.push({
-                    drugTracCodg: tracCodes[j].trim()
-                });
-            }
-            console.log('从退药表格获取追溯码:', tracCodes);
-        } else {
-            console.log('退药表格中没有追溯码信息');
-        }
-        
-        // 如果没有追溯码,添加空数组(保持数据结构一致)
-        if (ybData.drugtracinfo.length === 0) {
-            ybData.drugtracinfo = [];
-        }
-        
-        console.log('调用医保退药接口,药品:', item.drugname, '参数:', ybData);
+        // 主动获取追溯码信息(因为退药表格不包含追溯码)
+        let tracCodgParams = {
+            patientId: patientId,
+            times: times,
+            receiptNo: receiptNo,
+            orderNo: orderNo,
+            chargeItemCode: item.charge_item_code,
+            serial: item.serial,
+            itemNo: item.item_no,
+            groupNo: item.group_no || groupNo
+        };
         
-        // 调用医保接口
+        // 调用追溯码查询接口(异步方式)
         $.ajax({
             type: "POST",
-            url: '/thmz/Yb/returnGoodsItem',
+            url: '/thmz/getMzDrugTracCodgData',
             contentType: "application/json;charset=UTF-8",
             dataType: "json",
             headers: {
                 'Accept': 'application/json',
                 'Authorization': 'Bearer ' + localStorage.getItem("token")
             },
-            data: JSON.stringify(ybData),
-            success: function (res) {
-                console.log('医保退药接口调用成功:', res);
-                if (res.code !== 0) {
-                    console.error('医保退药接口调用失败:', res.message);
-                    // 医保接口失败不影响退药流程,只记录日志
+            data: JSON.stringify(tracCodgParams),
+            success: function (tracRes) {
+                console.log('追溯码查询结果:', tracRes);
+                if (tracRes.code === 0 && tracRes.data && tracRes.data.length > 0) {
+                    // 将追溯码添加到医保接口参数中
+                    for (let k = 0; k < tracRes.data.length; k++) {
+                        let tracItem = tracRes.data[k];
+                        if (tracItem.drugTracCodg && tracItem.drugTracCodg.trim() !== '') {
+                            ybData.drugtracinfo.push({
+                                drugTracCodg: tracItem.drugTracCodg.trim()
+                            });
+                        }
+                    }
+                    console.log('成功获取追溯码:', ybData.drugtracinfo);
+                } else {
+                    console.log('未找到追溯码信息');
                 }
+                
+                // 追溯码查询完成后,调用医保接口
+                callYbReturnGoodsItemWithData(ybData, item);
             },
             error: function (xhr, status, error) {
-                console.error('医保退药接口调用失败:', error);
-                // 医保接口失败不影响退药流程,只记录日志
+                console.error('追溯码查询失败:', error);
+                // 即使追溯码查询失败,也要调用医保接口
+                callYbReturnGoodsItemWithData(ybData, item);
             }
         });
     }
+}
+
+/**
+ * 调用医保退药接口(带追溯码数据)
+ * @param ybData 医保接口参数
+ * @param item 退药药品信息
+ */
+function callYbReturnGoodsItemWithData(ybData, item) {
+    // 如果没有追溯码,添加空数组(保持数据结构一致)
+    if (ybData.drugtracinfo.length === 0) {
+        ybData.drugtracinfo = [];
+    }
+    
+    console.log('调用医保退药接口,药品:', item.drugname, '参数:', ybData);
+    
+    // 调用医保接口
+    $.ajax({
+        type: "POST",
+        url: '/thmz/Yb/returnGoodsItem',
+        contentType: "application/json;charset=UTF-8",
+        dataType: "json",
+        headers: {
+            'Accept': 'application/json',
+            'Authorization': 'Bearer ' + localStorage.getItem("token")
+        },
+        data: JSON.stringify(ybData),
+        success: function (res) {
+            console.log('医保退药接口调用成功:', res);
+            if (res.code !== 0) {
+                console.error('医保退药接口调用失败:', res.message);
+                // 医保接口失败不影响退药流程,只记录日志
+            }
+        },
+        error: function (xhr, status, error) {
+            console.error('医保退药接口调用失败:', error);
+            // 医保接口失败不影响退药流程,只记录日志
+        }
+    });
 }