Browse Source

第一次加载的时候数据小于可展示的数据就清空数据

hurugang 4 years ago
parent
commit
45c17a7298

+ 18 - 16
src/main/java/cn/hnthyy/thmz/controller/YpfydlController.java

@@ -25,6 +25,7 @@ public class YpfydlController {
 
     /**
      * 查询未发药药品
+     *
      * @return
      */
     @UserLoginToken
@@ -40,41 +41,42 @@ public class YpfydlController {
             Date now = new Date();
             Date begin = DateUtil.getFirstSecond(now);
             Date end = DateUtil.getLastSecond(now);
-            YpMzFytj ypMzFytj= ypMzFytjService.querylastItem(groupNo,begin,end);
+            YpMzFytj ypMzFytj = ypMzFytjService.querylastItem(groupNo, begin, end);
             //过号集合
             List<String> pastList = new ArrayList();
             //待取药集合
             List<String> currentList = new ArrayList();
-            List<Map<String, Object>> all=  mzYpFydlService.queryToMedicine(groupNo,begin,end);
-            if(all!=null && all.size()>0){
-                for(Map<String, Object> map:all){
-                    Date priceTime =(Date) map.get("price_time");
-                    String name = (String)map.get("name");
-                    if(ypMzFytj!=null && ypMzFytj.getChargeDate()!=null){
-                        if(priceTime!=null && priceTime.before(ypMzFytj.getChargeDate())){
-                            if(!pastList.contains(name)){
+            List<Map<String, Object>> all = mzYpFydlService.queryToMedicine(groupNo, begin, end);
+            if (all != null && all.size() > 0) {
+                for (Map<String, Object> map : all) {
+                    Date priceTime = (Date) map.get("price_time");
+                    String name = (String) map.get("name");
+                    if (ypMzFytj != null && ypMzFytj.getChargeDate() != null) {
+                        if (priceTime != null && priceTime.before(ypMzFytj.getChargeDate())) {
+                            if (!pastList.contains(name)) {
                                 pastList.add(name);
                             }
                             continue;
                         }
                     }
-                    if(!currentList.contains(name)){
+                    if (!currentList.contains(name)) {
                         currentList.add(name);
                     }
                 }
             }
 //            pastList = Arrays.asList("过号1","过号2","过号3","过号4","过号5","过号6","过号7","过号8");
-//            currentList = Arrays.asList("取药取药","取药2","取药3","取药4","取药5","取药6","取药7","取药8","取药9","取药10","取药11","取药12","取药13","取药14","取药15","取药16","取药17","取药18","取药19","取药20","取药21","取药22","取药23","取药24","取药25","取药26");
+            //          currentList = Arrays.asList("取药取药","取药2","取药3","取药4","取药5","取药6","取药7","取药8","取药9","取药10","取药11","取药12","取药13","取药14","取药15","取药16","取药17","取药18","取药19","取药20","取药21","取药22","取药23","取药24","取药25","取药26");
+            currentList = Arrays.asList("取药取药", "取药2", "取药3", "取药4");
             resultMap.put("code", 0);
             resultMap.put("message", "查询未发药药品成功");
-            resultMap.put("pastList",pastList);
-            resultMap.put("currentList",currentList);
+            resultMap.put("pastList", pastList);
+            resultMap.put("currentList", currentList);
             return resultMap;
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
             resultMap.put("code", -1);
-            resultMap.put("message", "查询未发药药品失败,错误信息:【"+e.getMessage()+"】");
-            log.error("查询未发药药品失败,错误信息:[]",e.getMessage());
+            resultMap.put("message", "查询未发药药品失败,错误信息:【" + e.getMessage() + "】");
+            log.error("查询未发药药品失败,错误信息:[]", e.getMessage());
             return resultMap;
         }
     }

+ 40 - 16
src/main/resources/static/js/to-medicine.js

@@ -11,8 +11,6 @@ var tempPastList = null;
 var currentListHadDone = true;
 //过号名单队列是否已经加载完成
 var pastListHadDone = true;
-//正在取药的用户名
-var rightPerson = null;
 //药房编号
 var groupNo = null;
 $(function () {
@@ -58,6 +56,13 @@ $(function () {
         //设置页面宽度
         setHeightForTable();
     });
+
+    $(document).keyup(function(event){
+        if(event.keyCode ==13){
+            initTable();
+        }
+    });
+
 });
 
 
@@ -211,11 +216,21 @@ function getTableDate() {
                 tempPastList = $.extend(true, [], pastList);
                 tempCurrentList = $.extend(true, [], currentList);
                 if (currentList != null && currentList.length > 0) {
-                    rightPerson = currentList[0];
+                    var rightPerson = currentList[0];
+                    $("#rightPerson").text(rightPerson == null ? "" : rightPerson);
+                    //重置标志
+                    currentListHadDone = false;
+                } else {
+                    //重置标志
+                    currentListHadDone = true;
+                }
+
+                if (pastList == null || pastList.length == 0) {
+                    pastListHadDone = true;
+                } else {
+                    //重置标志
+                    pastListHadDone = false;
                 }
-                //重置标志
-                currentListHadDone = false;
-                pastListHadDone = false;
                 refeshTable();
             } else {
                 errorMesage(result);
@@ -230,11 +245,14 @@ function getTableDate() {
 function refeshTable() {
     //清空表格
     clear();
-    $("#rightPerson").text(rightPerson == null ? "" : rightPerson);
     for (var i = 1; i < 7; i++) {
         if (tempPastList == null || tempPastList.length == 0) {
             break;
         }
+        //当遍历完成而且总长度小于等于6 时,不需要轮询
+        if (pastListHadDone && pastList.length <= 6) {
+            break;
+        }
         //删除并返回数组的第一个元素
         var name = tempPastList.shift();
         $("#past" + i).text(name);
@@ -253,6 +271,10 @@ function refeshTable() {
         if (tempCurrentList == null || tempCurrentList.length == 0) {
             break;
         }
+        //当遍历完成而且总长度小于等于12 时,不需要轮询
+        if (currentListHadDone && currentList.length <= 12) {
+            break;
+        }
         //删除并返回数组的第一个元素
         var name = tempCurrentList.shift();
         $("#current" + i).text(name);
@@ -267,10 +289,6 @@ function refeshTable() {
             }
         }
     }
-    if (currentListHadDone && pastListHadDone) {
-        //都已经加载完成,清空当前取药人,等待下一次读取
-        rightPerson = null;
-    }
 }
 
 
@@ -278,13 +296,19 @@ function refeshTable() {
  * 清空表格
  */
 function clear() {
-    $("#rightPerson").text("");
-    for (var i = 1; i < 7; i++) {
-        $("#past" + i).text("");
+    //重新加载的数据,清空
+    if (pastList.length <= 6 && !pastListHadDone ) {
+        for (var i = 1; i < 7; i++) {
+            $("#past" + i).text("");
+        }
     }
-    for (var i = 1; i < 13; i++) {
-        $("#current" + i).text("");
+    //重新加载的数据,清空
+    if (currentList.length <= 12 && !currentListHadDone) {
+        for (var i = 1; i < 13; i++) {
+            $("#current" + i).text("");
+        }
     }
+
 }
 
 // /**