From 335954f4c8b452daf543f463ed05c0d5bafbfea6 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期一, 08 六月 2020 13:25:39 +0800 Subject: [PATCH] # --- src/main/webapp/views/matCode/matCode.html | 30 +++++++++++++- src/main/webapp/static/js/matCode/matCode.js | 80 ++++++++++++++++------------------------ 2 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/main/webapp/static/js/matCode/matCode.js b/src/main/webapp/static/js/matCode/matCode.js index 98223c5..d443f0d 100644 --- a/src/main/webapp/static/js/matCode/matCode.js +++ b/src/main/webapp/static/js/matCode/matCode.js @@ -1,4 +1,5 @@ var pageCurr; +var printMatCodeNos = []; layui.use(['table','laydate', 'form','upload'], function(){ var table = layui.table; var $ = layui.jquery; @@ -196,18 +197,26 @@ break; // 鎵归噺鎵撳嵃 case "btnPrintBatch": - layer.open({ - type: 1, - title: '鎵归噺鎵撳嵃', - area: ['500px'], - shadeClose: true, - content: $('#printDataDiv'), - success: function(layero, index){ - - }, - end: function () { - } - }); + printMatCodeNos = []; + var data = checkStatus.data; + if (data.length === 0){ + layer.msg('璇烽�夋嫨鎵撳嵃鏁版嵁'); + } else { + layer.open({ + type: 1, + title: '鎵归噺鎵撳嵃', + area: ['500px'], + shadeClose: true, + content: $('#printDataDiv'), + success: function(layero, index){ + for (var i = 0; i<data.length;i++) { + printMatCodeNos.push(data[i].matNo); + } + }, + end: function () { + } + }); + } break; } }); @@ -299,7 +308,7 @@ break; // 鎵撳嵃 case "btnPrint": - console.log(data); + printMatCodeNos = []; layer.open({ type: 1, title: '鎵撳嵃', @@ -308,6 +317,7 @@ content: $('#printDataDiv'), success: function(layero, index){ layer.iframeAuto(index); + printMatCodeNos.push(data.matNo); }, end: function () { } @@ -316,48 +326,23 @@ } }); - function startPrint(template, data) { - let param = []; - param.push("1902980-11/12"); - console.log(param) - $.ajax({ - url: baseUrl+"/macCode/print/auth", - headers: {'token': localStorage.getItem('token')}, - data: {param: param}, - method: 'POST', - async: false, - success: function (res) { - if (res.code === 200){ - console.log(res.data); - - - } else if (res.code === 403){ - top.location.href = baseUrl; - }else { - layer.msg(res.msg) - } - } - }) - console.log(data.field); - // $('#template-preview-1').print(); - } - // 寮�濮嬫墦鍗� form.on('submit(doPrint)', function (data) { - let param = []; - param.push("1902980-11/12"); - console.log(param) + var templateNo = data.field.selectTemplate; $.ajax({ url: baseUrl+"/macCode/print/auth", headers: {'token': localStorage.getItem('token')}, - data: {param: param}, + data: {param: printMatCodeNos}, method: 'POST', async: false, success: function (res) { if (res.code === 200){ - console.log(res.data); - - + var tpl = $("#templatePreview"+templateNo).html(); + var template = Handlebars.compile(tpl); + var html = template(res); + $("#box").html(html); + $("#box").print(); + // $('#template-preview-'+templateNo).print(); } else if (res.code === 403){ top.location.href = baseUrl; }else { @@ -365,8 +350,7 @@ } } }) - console.log(data.field); - // $('#template-preview-1').print(); + }) // 鏁版嵁淇濆瓨鍔ㄤ綔 diff --git a/src/main/webapp/views/matCode/matCode.html b/src/main/webapp/views/matCode/matCode.html index 5bac4a5..cb32b79 100644 --- a/src/main/webapp/views/matCode/matCode.html +++ b/src/main/webapp/views/matCode/matCode.html @@ -132,9 +132,9 @@ <hr> <!--鍗曢�夋--> <div class="layui-form-item" style="display: inline-block; margin-bottom: 10px"> - <input type="radio" name="sex" value="鐢�" title="妯℃澘涓�" checked=""> - <input type="radio" name="sex" value="濂�" title="妯℃澘浜�"> - <input type="radio" name="sex" value="绂�" title="妯℃澘涓�"> + <input type="radio" name="selectTemplate" value="1" title="妯℃澘涓�" checked=""> + <input type="radio" name="selectTemplate" value="2" title="妯℃澘浜�"> + <input type="radio" name="selectTemplate" value="3" title="妯℃澘涓�"> </div> <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;text-align: left;"> <legend>鎵撳嵃棰勮</legend> @@ -204,9 +204,33 @@ </div> </div> +<div id="box" style="display: block"> + <!-- 妯℃澘寮曟搸 --> <!-- 妯℃澘1 --> <script type="text/template" id="templatePreview1"> + {{#each data}} + <table class="contain" height="217" width="317" style="overflow: hidden;font-size: xx-small"> + <tr> + <td colspan="1" align="right" scope="col">鏉$爜</td> + <td class="barcode"colspan="3" align="left" scope="col"> + <img class="qrcode" src="/macCode/barcode/auth?param={{this.barcode}}" width="80%"> + </td> + </tr> + <tr> + <td align="right" width="25%">鐗╂枡缂栫爜</td> + <td align="right" width="25%">{{this.matNo}}</td> + <td align="right" width="25%">鐗╂枡鍚嶇О</td> + <td align="right" width="25%">{{this.matName}}</td> + </tr> + <tr> + <td align="right" width="25%">鐗╂枡鍗曚綅</td> + <td align="right" width="25%">{{this.str1}}</td> + <td align="right" width="25%">鐗╂枡瑙勬牸</td> + <td align="right" width="25%">{{this.str2}}</td> + </tr> + </table> + {{/each}} </script> <!-- 妯℃澘2 --> <script type="text/template" id="templatePreview2"> -- Gitblit v1.9.1