LIJU 2 月之前
父节点
当前提交
7dbc91186e

+ 76 - 5
src/main/resources/static/js/mz/west_pharmacy_send.js

@@ -2235,6 +2235,59 @@ function matchingDrugCodg(patientId, times, receiptNo, orderNo, realNo){
         },
     });
     $("#tyModal").modal();
+    
+    // 弹窗打开后自动聚焦到扫码输入框
+    $("#tyModal").on('shown.bs.modal', function () {
+        setTimeout(function() {
+            $("#smMatchTy").focus();
+        }, 100);
+    });
+    
+    // 防抖定时器
+    let matchDebounceTimer = null;
+    
+    // 支持回车键触发匹配
+    $("#smMatchTy").on('keypress', function(e) {
+        if (e.which === 13) { // 回车键
+            e.preventDefault();
+            // 清除防抖定时器
+            if (matchDebounceTimer) {
+                clearTimeout(matchDebounceTimer);
+            }
+            matchDrugCodg();
+        }
+    });
+    
+    // 输入防抖处理
+    $("#smMatchTy").on('input', function() {
+        let code = $(this).val().trim();
+        
+        // 清除之前的定时器
+        if (matchDebounceTimer) {
+            clearTimeout(matchDebounceTimer);
+        }
+        
+        // 如果输入框有值,设置0.5秒防抖
+        if (code && code !== '') {
+            matchDebounceTimer = setTimeout(function() {
+                matchDrugCodg();
+            }, 500);
+        }
+    });
+    
+    // 防止onchange和防抖冲突
+    $("#smMatchTy").on('change', function() {
+        // 清除防抖定时器,避免重复执行
+        if (matchDebounceTimer) {
+            clearTimeout(matchDebounceTimer);
+            matchDebounceTimer = null;
+        }
+    });
+    
+    // 扫码输入框获得焦点时全选文本
+    $("#smMatchTy").on('focus', function() {
+        $(this).select();
+    });
 }
 
 // 匹配扫码
@@ -2243,11 +2296,23 @@ function matchDrugCodg(){
         isTyOk = false;
     }
     let code = $("#smMatchTy").val().trim().replace(/[\r\n]/g,"");
+    
+    // 检查输入是否为空
+    if (!code) {
+        errorMesageSimaple("请输入或扫描药品追溯码!");
+        $("#smMatchTy").focus();
+        return false;
+    }
+    
     let tyTable = $('#ty_table_detail').bootstrapTable("getData");
+    let matched = false;
+    
     for (let i = 0; i < tyTable.length; i++) {
         if(tyTable[i].drugTracCodg === code){
             if(!isEmpty(tyTable[i].matchOk)){
                 warningMesageSimaple("已匹配,请勿重复扫码!");
+                // 重复匹配时清空输入框,准备扫描下一个
+                $("#smMatchTy").val("").focus();
                 return false;
             }
             $('#ty_table_detail').bootstrapTable('updateCell', {
@@ -2260,13 +2325,19 @@ function matchDrugCodg(){
                 field: "matchOk",
                 value: '<span style="color: green">已匹配</span>'
             });
-            break
-        }
-        if(i === tyTable.length - 1){
-            errorMesageSimaple("在退药列表未找到条码对应的药品,请核对!")
+            successMesageSimaple("药品追溯码匹配成功!");
+            matched = true;
+            // 匹配成功后清空输入框,准备扫描下一个
+            $("#smMatchTy").val("").focus();
+            break;
         }
     }
-    $("#smMatchTy").val("")
+    
+    if (!matched) {
+        errorMesageSimaple("在退药列表未找到条码对应的药品,请核对!");
+        // 匹配失败时清空输入框
+        $("#smMatchTy").val("").focus();
+    }
 }
 
 // 确认匹配之后可以退药了

+ 2 - 1
src/main/resources/templates/mz/west_pharmacy_send.html

@@ -1067,7 +1067,8 @@
                                 </label>
                                 <div class="col-md-3 col-sm-3 col-xs-12">
                                     <input id="smMatchTy" class="form-control optional" type="text"
-                                           style="border-style: none;box-shadow: 0 0 0 0;" onchange="matchDrugCodg()">
+                                           style="border: 2px solid #337ab7; background-color: #f9f9f9; font-weight: bold; color: #333;"
+                                           placeholder="请扫描药品追溯码..." onchange="matchDrugCodg()">
                                 </div>
                             </div>
                         </form>