From c1d296c4ed6a669c29b848bdee3f9b8001f58ddc Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 10 七月 2020 09:16:12 +0800
Subject: [PATCH] #

---
 src/main/webapp/views/pdaCe/index.html |  125 +++++++++++++++++++++++++++++++++++------
 1 files changed, 105 insertions(+), 20 deletions(-)

diff --git a/src/main/webapp/views/pdaCe/index.html b/src/main/webapp/views/pdaCe/index.html
index 3c56849..502a1d5 100644
--- a/src/main/webapp/views/pdaCe/index.html
+++ b/src/main/webapp/views/pdaCe/index.html
@@ -116,7 +116,7 @@
 </div>
 <div>
     <span>鐗╂枡</span>
-    <input type="text" id="matnr" onkeyup="find(this)" autocomplete="off">
+    <input type="text" id="matNo" onkeyup="find(this)" autocomplete="off">
 </div>
 
 <div class="mat-msg" id="mat-msg-id">
@@ -134,7 +134,7 @@
 
 <div id="btn-con">
     <button style="margin-right: 20px" onclick="reset()">閲嶇疆</button>
-    <button >缁勬墭</button>
+    <button onclick="comb()">缁勬墭</button>
     <span id="tips"></span>
 </div>
 
@@ -164,7 +164,7 @@
     var matMsgTableBlankRows = 0;   // 绌虹櫧琛屾暟
     var matData = []; // 琛ㄦ牸鏁版嵁
     var code = document.getElementById("code")
-    var matnr = document.getElementById("matnr")
+    var matNo = document.getElementById("matNo")
     var matMsg = document.getElementById("mat-msg-id");
     var matMsgTable = document.getElementById("mat-msg-table");
     var tthead = document.getElementById("tthead");
@@ -177,7 +177,6 @@
     var str1 = document.getElementById("str1");
     var count = document.getElementById("count");
 
-    alert(1);
     matDetail.style.display = 'none';
     var initMatCount = 1;
 
@@ -186,6 +185,7 @@
         httpRequest({
             httpUrl: baseUrl + "/matCode/auth",
             type: 'post',
+            headers: [{token: getCookie('token')}],
             data: {
                 id: el.value
             },
@@ -205,10 +205,47 @@
                     btnCon.style.display = 'block';
                     matDetail.style.display = 'none';
                 }
+            } else if (res.code === 403) {
+                window.location.href = baseUrl + "/pda/ce";
             } else {
-                alert(res.msg);
+                tips(res.msg, true)
             }
+        })
+    }
 
+    // 缁勬墭
+    function comb() {
+        var barcode = code.value;
+        if (isEmpty(barcode)) {
+            tips("鎵樼洏鏉$爜涓虹┖", true);
+            // document.getElementById("code").focus();
+            return;
+        }
+        if (matData.length === 0) {
+            tips("璇锋彁鍙栫墿鏂�", true);
+            return;
+        }
+        console.log(JSON.stringify({
+            barcode: barcode,
+            combMats: matData
+        }))
+        httpRequest({
+            httpUrl: baseUrl+"/mobile/comb/form",
+            type: 'post',
+            headers: [{token: getCookie('token')}],
+            data: {
+                barcode: barcode,
+                combMats: matData
+            },
+        }, function (res) {
+            if (res.code === 200) {
+                reset();
+                tips("缁勬墭鎴愬姛")
+            } else if (res.code === 403) {
+                window.location.href = baseUrl + "/pda/ce";
+            } else {
+                tips(res.msg, true)
+            }
         })
     }
 
@@ -225,7 +262,6 @@
         } else {
             line = row;
         }
-
         var html = "";
         for (var i = 0; i < line; i ++){
             html += " <div>\n" +
@@ -244,30 +280,38 @@
             tips("鎻愬彇澶辫触");
             return;
         }
-        let toPush = true;
+        var toPush = true;
         for (var j=0;j<matData.length;j++){
-            if (matnr.value === matData[j].matnr) {
+            if (data.matNo === matData[j].matNo) {
                 matData[j].count = Number(matData[j].count) + Number(data.count);
                 toPush  = false;
             }
         }
         if (toPush) {
             matData.push(data);
-            var html = " <div>\n" +
-                    "       <span>" + data.matnr + "</span>\n" +
-                    "       <span>" + data.matName + "</span>\n" +
-                    "       <span>" + data.str1 + "</span>\n" +
-                    "       <span>" + data.count + "</span>\n" +
-                    "     </div>\n";
-            ttbody.innerHTML = html;
         }
-        tips("鎻愬彇鎴愬姛");
+        var html = "";
+        for (var i=0;i<matData.length;i++) {
+            html += " <div class='table-data'>\n" +
+                "       <span>" + matData[i].matNo + "</span>\n" +
+                "       <span>" + matData[i].matName + "</span>\n" +
+                "       <span>" + matData[i].str1 + "</span>\n" +
+                "       <span>" + matData[i].count + "</span>\n" +
+                "     </div>\n";
+        }
+
+        ttbody.innerHTML = html;
     }
 
     // 閲嶇疆
     function reset() {
         code.value = "";
-        matnr.value = "";
+        matNo.value = "";
+        cancel();
+        while(ttbody.hasChildNodes()) {
+            ttbody.removeChild(ttbody.firstChild);
+
+        }
     }
 
     /**
@@ -290,22 +334,24 @@
     // 鎻愬彇
     function confirm() {
         addTableData({
-            matnr: matnr.value,
+            matNo: matNo.value,
             matName: matName.value,
             str1: str1.value,
             count: count.value
         })
         cancel();
+        tips("鎻愬彇鎴愬姛");
     }
     // 鍙栨秷
     function cancel() {
-        matnr.value = "";
+        matNo.value = "";
         matName.value = "";
         str1.value = "";
         count.value = initMatCount;
         matMsg.style.display = 'block';
         btnCon.style.display = 'block';
         matDetail.style.display = 'none';
+        tips("");
     }
 
     function add() {
@@ -316,6 +362,21 @@
             return;
         }
         count.value = count.value - 1;
+    }
+
+    //鑾峰彇 cookie
+    function getCookie(objName){//鑾峰彇鎸囧畾鍚嶇О鐨刢ookie鐨勫��
+        //澶氫釜cookie 淇濆瓨鐨勬椂鍊欐槸浠� ;绌烘牸  鍒嗗紑鐨�
+        var arrStr = document.cookie.split("; ");
+        for (var i = 0; i < arrStr.length; i++) {
+            var temp = arrStr[i].split("=");
+            if (temp[0] === objName){
+                return decodeURIComponent(temp[1]);
+            }else{
+                return "";
+            }
+
+        }
     }
 
     function httpRequest(paramObj,fun,errFun) {
@@ -341,6 +402,8 @@
         var httpUrl = paramObj.httpUrl || '';
         /*鏄惁寮傛璇锋眰*/
         var async = paramObj.async || true;
+        /*璇锋眰澶村弬鏁�*/
+        var headerData = paramObj.headers || [];
         /*璇锋眰鍙傛暟--post璇锋眰鍙傛暟鏍煎紡涓猴細foo=bar&lorem=ipsum*/
         var paramData = paramObj.data || [];
         var requestData = '';
@@ -367,9 +430,31 @@
         }else if(httpType === 'POST'){
             xmlhttp.open("POST",httpUrl,async);
             //鍙戦�佸悎閫傜殑璇锋眰澶翠俊鎭�
-            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+            var defaultContentType = true;
+            for (var i=0;i<headerData.length;i++) {
+                for(var key in headerData[i]) {
+                    if (key === "Content-type") {
+                        defaultContentType = false;
+                    }
+                    xmlhttp.setRequestHeader(key, headerData[i][key]);
+                }
+            }
+            if (defaultContentType) {
+                xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+            }
             xmlhttp.send(requestData);
         }
     }
+
+    // todo
+    setTimeout(function () {
+        code.value = "888"
+        addTableData({
+            matNo: "1902980-11/14",
+            matName: "閾濆甫|1100-O|0.33*475|",
+            str1: "浠�",
+            count: 1
+        })
+    }, 200)
 </script>
 </html>
\ No newline at end of file

--
Gitblit v1.9.1