|
@@ -0,0 +1,265 @@
|
|
|
|
|
+{Template header}
|
|
|
|
|
+<body>
|
|
|
|
|
+ <div class="warp">
|
|
|
|
|
+ <div class="fixed">
|
|
|
|
|
+
|
|
|
|
|
+ <div class="control zjcz">
|
|
|
|
|
+
|
|
|
|
|
+ <a href="javascript:void(0);" class="lv_print_excel">导入需要打印的文件</a>
|
|
|
|
|
+ <input id="upload-file" name="files" accept="image/xls,image/xlsx" type="file" class="none">
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <script>
|
|
|
|
|
+ $(".lv_print_excel").click(function() {
|
|
|
|
|
+ var me = $(this);
|
|
|
|
|
+ $("#upload-file").click();
|
|
|
|
|
+ $("#upload-file").unbind("change");
|
|
|
|
|
+ $("#upload-file").bind("change",function(){
|
|
|
|
|
+ whlabeldr_two(me);
|
|
|
|
|
+ layx.load('loadId','导入中,请稍后',{shadable:0.6});
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ let excel_data = [];
|
|
|
|
|
+ function whlabeldr_two(dr){
|
|
|
|
|
+ var file = document.getElementById("upload-file").files[0];
|
|
|
|
|
+ if (!file) return;
|
|
|
|
|
+
|
|
|
|
|
+ // 显示加载提示
|
|
|
|
|
+ //layx.load('loadId', '解析 Excel 中,请稍后', { shadable: 0.6 });
|
|
|
|
|
+
|
|
|
|
|
+ // 使用 FileReader 读取文件
|
|
|
|
|
+ var reader = new FileReader();
|
|
|
|
|
+ reader.onload = function(e) {
|
|
|
|
|
+ var data = e.target.result;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 使用 SheetJS 解析 Excel 为 JSON
|
|
|
|
|
+ var workbook = XLSX.read(data, { type: 'array' });
|
|
|
|
|
+ var sheetName = workbook.SheetNames[0]; // 取第一个工作表
|
|
|
|
|
+ var worksheet = workbook.Sheets[sheetName];
|
|
|
|
|
+ var jsonData = XLSX.utils.sheet_to_json(worksheet, { header:1,defval: "" });
|
|
|
|
|
+ jsonData.shift(); // 去掉第一行表头
|
|
|
|
|
+ //console.log(jsonData)
|
|
|
|
|
+ excel_data = jsonData;
|
|
|
|
|
+ // 构建要上传的数据(可以包含文件名、sheet名等)
|
|
|
|
|
+ // var uploadData = {
|
|
|
|
|
+ // fileName: file.name,
|
|
|
|
|
+ // sheetName: sheetName,
|
|
|
|
|
+ // data: jsonData // 解析后的 JSON 数组
|
|
|
|
|
+ // };
|
|
|
|
|
+ // 通过 AJAX 上传 JSON 数据
|
|
|
|
|
+ document.getElementById("upload-file").files[0] = '';
|
|
|
|
|
+ // if(excel_data.length>100){
|
|
|
|
|
+ // layx.destroy('loadId');
|
|
|
|
|
+ // errorc({ success: false, msg: "一次最多只能上传100条数据" });
|
|
|
|
|
+ // return ;
|
|
|
|
|
+ // }
|
|
|
|
|
+ print_label();
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ layx.destroy('loadId');
|
|
|
|
|
+ console.error("解析 Excel 失败:", err);
|
|
|
|
|
+ errorc({ success: false, msg: "解析 Excel 文件失败" });
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ reader.onerror = function() {
|
|
|
|
|
+ layx.destroy('loadId');
|
|
|
|
|
+ errorc({ success: false, msg: "文件读取失败" });
|
|
|
|
|
+ };
|
|
|
|
|
+ reader.readAsArrayBuffer(file); // 以 ArrayBuffer 读取
|
|
|
|
|
+ }
|
|
|
|
|
+ function print_label() {
|
|
|
|
|
+ $.post("/brand/adddo", { data: JSON.stringify(excel_data) }, function(res) {
|
|
|
|
|
+ layx.destroy('loadId');
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ if(res.code == 1){
|
|
|
|
|
+ errora({ success: true, msg: res.msg });
|
|
|
|
|
+ }else{
|
|
|
|
|
+
|
|
|
|
|
+ layx.confirm('错误提示',res.msg,null,{
|
|
|
|
|
+ buttons:[
|
|
|
|
|
+ {
|
|
|
|
|
+ label:'确定',
|
|
|
|
|
+ callback:function(id, button, event){
|
|
|
|
|
+ download_excel(res.error);
|
|
|
|
|
+ layx.destroy(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ],dialogIcon:'warn',shadable:0.6
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ },'json');
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ function download_excel(data){
|
|
|
|
|
+ let sheet = XLSX.utils.json_to_sheet(data)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ sheet['!cols'] = [
|
|
|
|
|
+ //订单号
|
|
|
|
|
+ {
|
|
|
|
|
+ wch:60,
|
|
|
|
|
+ },
|
|
|
|
|
+ //订单编码
|
|
|
|
|
+ {
|
|
|
|
|
+ wch:120,
|
|
|
|
|
+ },
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ let workbook = XLSX.utils.book_new();
|
|
|
|
|
+
|
|
|
|
|
+ XLSX.utils.book_append_sheet(workbook, sheet, "Sheet1");
|
|
|
|
|
+ XLSX.writeFile(workbook, "错误数据.xlsx");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ </script>
|
|
|
|
|
+
|
|
|
|
|
+ <script>
|
|
|
|
|
+ $(".printing_bqpl").click(function() {
|
|
|
|
|
+ var a = "";
|
|
|
|
|
+ $(".datatext input[name='check']:checked").each(function() {
|
|
|
|
|
+ a = a + $(this).val() + ",";
|
|
|
|
|
+ });
|
|
|
|
|
+ if (a) {
|
|
|
|
|
+ if ($("select[name='printer']").children("option:selected").val() == "") {
|
|
|
|
|
+ $(".ts p").html("请选择打印机!");
|
|
|
|
|
+ $(".ts").show();
|
|
|
|
|
+ setTimeout('$(".ts").fadeOut()', 1000);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(".systemwindow div p:eq(0)").text("是否确认批量打印所选内容?");
|
|
|
|
|
+ $(".systemwindow div p:eq(1)").html(
|
|
|
|
|
+ "<p><font id='printingon_bqpl'>确 定</font><font class='esc'>取 消</font></p>");
|
|
|
|
|
+ $(".systemwindow").show();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(".ts p").html("请勾选需要打印的内容");
|
|
|
|
|
+ $(".ts").show();
|
|
|
|
|
+ setTimeout('$(".ts").fadeOut()', 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ /* 批量打印开始 */
|
|
|
|
|
+ $(".systemwindow").on('click', "#printingon_bqpl", function() {
|
|
|
|
|
+ $(".systemwindow").hide();
|
|
|
|
|
+ $(".systemwindow div p:eq(0)").html("<i class='fa fa-2x fa-cog fa-spin'></i> 正在处理打印信息,请稍后...");
|
|
|
|
|
+ $(".systemwindow div p:eq(1)").html("");
|
|
|
|
|
+ $(".systemwindow").show();
|
|
|
|
|
+
|
|
|
|
|
+ var a = "";
|
|
|
|
|
+ var i = 0;
|
|
|
|
|
+ $(".datatext input[name='check']:checked").each(function() {
|
|
|
|
|
+ a = a + $(this).val() + ',';
|
|
|
|
|
+ i++;
|
|
|
|
|
+ });
|
|
|
|
|
+ var tf = $("select[name='print']").children("option:selected").val();
|
|
|
|
|
+ ajax_bqpl(i - 1, a, tf);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ function site_bqpl(num, list, number, data, i) {
|
|
|
|
|
+ var jobsite = $("#site").html();
|
|
|
|
|
+ if (jobsite == '0') {
|
|
|
|
|
+ $("#job").html("");
|
|
|
|
|
+ $("#site").html("");
|
|
|
|
|
+ if (data == '1') {
|
|
|
|
|
+ var tf = $("select[name='print']").children("option:selected").val();
|
|
|
|
|
+ ajax_bqpl(num, list, tf);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else if (data == '2') {
|
|
|
|
|
+ $("#music_print_ok")[0].play();
|
|
|
|
|
+ $(".tyrows").hide();
|
|
|
|
|
+ $(".systemwindow").hide();
|
|
|
|
|
+ $("#music_d")[0].play();
|
|
|
|
|
+ $(".systemwindow div p:eq(0)").html('运单打印完成,请更换为新运单后再次操作出库');
|
|
|
|
|
+ $(".systemwindow div p:eq(1)").html("<font class='wcsj'>确 定</font>");
|
|
|
|
|
+ $(".systemwindow").show();
|
|
|
|
|
+ $("#orderinfo").val("");
|
|
|
|
|
+ $("#orderinfo").focus();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wprinter.sound("打印完成")
|
|
|
|
|
+ $(".systemwindow div p:eq(0)").html("打印完成!");
|
|
|
|
|
+ $(".systemwindow div p:eq(1)").html("<font class='printok'>确 定</font>");
|
|
|
|
|
+ $(".systemwindow").show();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (i < '71') {
|
|
|
|
|
+ if ($("#job").html() != '') {
|
|
|
|
|
+ wprinter.getStatusValue();
|
|
|
|
|
+ }
|
|
|
|
|
+ setTimeout(function() {
|
|
|
|
|
+ site_bqpl(num, list, number, data, i + 1);
|
|
|
|
|
+ }, 1500);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wprinter.sound("打印机异常")
|
|
|
|
|
+ $(".systemwindow div p:eq(0)").html("订单:" + number + " 打印失败!系统已停止打印,请检查打印机!如未出此单,请再次打印");
|
|
|
|
|
+ $(".systemwindow div p:eq(1)").html("<font class='printok'>确 定</font>");
|
|
|
|
|
+ $(".systemwindow").show();
|
|
|
|
|
+ $("#job").html("");
|
|
|
|
|
+ $("#site").html("");
|
|
|
|
|
+ $(".tyrowsout").hide();
|
|
|
|
|
+ $("#orderinfo").val("");
|
|
|
|
|
+ $("#orderinfo").focus();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function ajax_bqpl(num, list, tf) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ url: "/whlabelfz/printing/",
|
|
|
|
|
+ data: "tf=" + tf + "&s=" + list + "&n=" + num,
|
|
|
|
|
+ type: "POST",
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ timeout: 60001,
|
|
|
|
|
+ success: function(c) {
|
|
|
|
|
+ if (c.success) {
|
|
|
|
|
+ wprinter.xbq(c.rows.text)
|
|
|
|
|
+ if (c.rows['n'] > -1) {
|
|
|
|
|
+ //ajax(c.rows['n'],c.rows['data']);
|
|
|
|
|
+ site_bqpl(c.rows['n'], c.rows['data'], c.rows['text']['number'], 1, 0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (c.rows['type'] == 3) {
|
|
|
|
|
+ wprinter.sound("有错误订单")
|
|
|
|
|
+ $(".systemwindow div p:eq(0)").html(c.rows['text']['number'] +
|
|
|
|
|
+ "资料错误未成功打印,已移交给店员处理");
|
|
|
|
|
+ $(".systemwindow div p:eq(1)").html("<font class='printok'>确 定</font>");
|
|
|
|
|
+ $(".systemwindow").show();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ site_bqpl(1, 1, c.rows['text']['number'], 0, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(".systemwindow").hide();
|
|
|
|
|
+ layx.alert('错误', c.msg, function(id, button) {
|
|
|
|
|
+ $(".search span").click();
|
|
|
|
|
+ }, {
|
|
|
|
|
+ dialogIcon: 'error'
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ error: function(textStatus) {
|
|
|
|
|
+ wprinter.sound("错误,请求数据超时!请重试")
|
|
|
|
|
+ $(".systemwindow").hide();
|
|
|
|
|
+ layx.alert('错误', '请求数据超时!请重试', function(id, button) {
|
|
|
|
|
+ $(".search span").click();
|
|
|
|
|
+ }, {
|
|
|
|
|
+ dialogIcon: 'error'
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ </script>
|
|
|
|
|
+ <script type="text/javascript" src="{$theme}js/excel/xlxs.js" ></script>
|
|
|
|
|
+ <script type="text/javascript" src="{$theme}js/laydate.js"></script>
|
|
|
|
|
+ <script type="text/javascript" src="{$theme}js/print.js?v=202505301539"></script>
|
|
|
|
|
+ {Template footer}
|