| | |
| | | </script> |
| | | <script type="text/html" id="tableToolBarClothesOrder"> |
| | | <div class="layui-btn-container"> |
| | | <!-- <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="printSelect">打印预览</button>--> |
| | | <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="deliverGoods">发货</button> |
| | | <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="updateDeliver">修改物流信息</button> |
| | | <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="refundOrder">仅退款</button> |
| | |
| | | var layEvent = obj.event; |
| | | var id = obj.config.id; |
| | | var checkStatus = table.checkStatus(id); |
| | | if(layEvent === 'printSelect'){ |
| | | let data = checkStatus.data; |
| | | if (data.length > 1) { |
| | | febs.alert.warn('每次只能操作一个订单'); |
| | | return; |
| | | } |
| | | let ids = ""; |
| | | for(let i = 0;i < data.length;i++){ |
| | | console.log(data[i].status); |
| | | if(data[i].status != 2){ |
| | | febs.alert.warn('请选择待发货的订单'); |
| | | return; |
| | | }else{ |
| | | ids = data[i].id; |
| | | } |
| | | } |
| | | if(ids == null || ids == ""){ |
| | | febs.alert.warn('请选择订单'); |
| | | return; |
| | | } |
| | | printSelectData(ids) |
| | | } |
| | | |
| | | if (layEvent === 'deliverGoods') { |
| | | let data = checkStatus.data; |
| | |
| | | } |
| | | |
| | | }); |
| | | |
| | | |
| | | /* |
| | | * [自定义打印选中行数据] |
| | | * @param {[type]} allData [传入选中行] |
| | | */ |
| | | function printSelectData(allData) { |
| | | let orderId = allData; |
| | | console.log(orderId); |
| | | $.ajax({ |
| | | url: '/admin/clothesType/printOrder/'+orderId, |
| | | type: "get", |
| | | contentType: 'application/json', |
| | | success(res) { |
| | | console.log(res); |
| | | printSelect(res.data); |
| | | }, |
| | | error(xhr, status, error) { |
| | | console.error("AJAX 请求失败:", error); |
| | | alert("请求失败,请重试"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | function printSelect(data) { |
| | | //用于包含内容 |
| | | var v = document.createElement("div"); |
| | | //页面头部,导入css ,media="print"表示打印时使用该样式 |
| | | var f = ["<head>", "<style>", "div{font-size:8px;}", ".main{width:100%;}", |
| | | ".main div{width:100%;display:inline-block;}", "</style>", "</head>" |
| | | ].join(""); |
| | | console.log(data); |
| | | var template = |
| | | "<div class='main'>" + |
| | | "<div style='text-align: center;font-size: 30px;font-weight: bold;margin-bottom: 10px'>订单编号:" + data.orderNo + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>类型:" + data.typeName + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>布料:" + data.clothName + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>编码:" + data.clothCode + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>尺码:" + data.sizeName + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>编码:" + data.sizeCode + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>工艺:" + data.artName + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>编码:" + data.artCode + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>正面图案:" + data.patternName + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>编码:" + data.patternCode + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>文案:" + data.patternText + "</div>" + |
| | | "<div class='print-images' style='font-size: 30px;font-weight: bold;'>图片:" + |
| | | "<img style='width: 200px; height: 200px; max-width: 80%; margin-top: 5px;' src="+ data.patternImage+">" + |
| | | "</div>" + |
| | | |
| | | "<div style='font-size: 30px;font-weight: bold;'>反面图案:" + data.locationName + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>编码:" + data.locationCode + "</div>" + |
| | | "<div style='font-size: 30px;font-weight: bold;'>文案:" + data.locationText + "</div>" + |
| | | "<div class='print-images' style='font-size: 30px;font-weight: bold;'>图片:" + |
| | | "<img style='width: 200px; height: 200px; max-width: 80%; margin-top: 5px;' src="+ data.locationImage+">" + |
| | | "</div>" + |
| | | "<div class='print-images' style='font-size: 30px;font-weight: bold;'>正面:" + |
| | | "<img style='width: 200px; height: 200px; max-width: 80%; margin-top: 5px;' src="+ data.typeFront+">" + |
| | | "</div>" + |
| | | "<div class='print-images' style='font-size: 30px;font-weight: bold;'>反面:" + |
| | | "<img style='width: 200px; height: 200px; max-width: 80%; margin-top: 5px;' src="+ data.typeBack+">" + |
| | | "</div>" + |
| | | "</div>" |
| | | |
| | | v.innerHTML = template; |
| | | //新建窗口 |
| | | var h = window.open("打印窗口", "_blank"); |
| | | //写入拼凑内容 |
| | | h.document.write(f + $(v).prop("outerHTML")); |
| | | h.document.close(); |
| | | //在新窗口的 document 中查找图片 |
| | | ensureImagesLoaded(h.document, '.print-images img') |
| | | .then(() => h.print()) |
| | | .catch(() => layer.msg('部分图片加载失败')); |
| | | //调用打印 |
| | | h.print(); |
| | | //关闭页面 |
| | | h.close(); |
| | | } |
| | | |
| | | function ensureImagesLoaded(doc, selector) { |
| | | var imgs = $(selector, doc); // 👈 在指定文档中查找 |
| | | var promises = []; |
| | | |
| | | imgs.each(function() { |
| | | var img = this; |
| | | var promise = new Promise(function(resolve, reject) { |
| | | if (img.complete && img.naturalWidth !== 0) { |
| | | resolve(); |
| | | } else { |
| | | $(img).on('load', resolve).on('error', reject); |
| | | } |
| | | }); |
| | | promises.push(promise); |
| | | }); |
| | | |
| | | return Promise.all(promises); |
| | | } |
| | | |
| | | |
| | | |
| | | function refundOrder(id) { |