From e8f8d89a4248cd4d0a7138cc2e5a36ea9b136699 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 11 Feb 2025 17:03:01 +0800
Subject: [PATCH] feat(mall): 添加订单一键发货和取消发货功能
---
src/main/resources/templates/febs/views/modules/order/orderList.html | 202 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 199 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/templates/febs/views/modules/order/orderList.html b/src/main/resources/templates/febs/views/modules/order/orderList.html
index b19b257..ee8d91e 100644
--- a/src/main/resources/templates/febs/views/modules/order/orderList.html
+++ b/src/main/resources/templates/febs/views/modules/order/orderList.html
@@ -356,6 +356,16 @@
cancelOrder(data.id);
});
}
+ if (layEvent === 'deliverPdfGoods') {
+ febs.modal.confirm('一键发货', '确认一键发货?', function () {
+ deliverPdfGoods(data.id);
+ });
+ }
+ if (layEvent === 'cancelDeliver') {
+ febs.modal.confirm('取消发货', '确认取消发货?', function () {
+ cancelDeliver(data.id);
+ });
+ }
if (layEvent === 'seePayImage') {
var t = $view.find('#seePayImage'+data.id+'');
//页面层
@@ -373,12 +383,195 @@
}
});
+ function cancelDeliver(id) {
+ febs.get(ctx + 'admin/order/cancelDeliver/' + id, null, function (data) {
+ febs.alert.success(data.message);
+ $query.click();
+ });
+ }
+
function cancelOrder(id) {
febs.get(ctx + 'admin/order/cancelOrder/' + id, null, function () {
febs.alert.success('操作成功');
$query.click();
});
}
+
+ function deliverPdfGoods(id) {
+ febs.get(ctx + 'admin/order/deliverPdfGoods/' + id, null, function (e) {
+ if (e.code == 200) {
+ // 创建弹层容器
+ const content = `
+ <div style="position:relative;min-height:500px">
+ <div id="pdfContainer" style="margin:20px auto;max-width:800px"></div>
+ <div class="layui-form" style="text-align:center;margin-top:20px">
+ <button class="layui-btn layui-btn-normal" onclick="printPdf()">打印</button>
+ </div>
+ </div>
+ `;
+
+ // 显示弹层
+ const index = layer.open({
+ type: 1,
+ title: "电子面单",
+ content: content,
+ area: ['90%', '90%'],
+ success: function() {
+ // 渲染PDF
+ renderPdf(e.data.pdfStream);
+ }
+ });
+ // 存储当前PDF数据
+ window.currentPDF = e.data.pdfStream;
+ } else {
+ febs.alert.warn(e.message);
+ }
+ });
+ $query.click();
+ }
+
+ // PDF渲染函数
+ function renderPdf(base64Data) {
+ // 清理容器
+ const container = document.getElementById('pdfContainer');
+ container.innerHTML = '';
+
+ // Base64转Blob
+ const byteCharacters = atob(base64Data);
+ const byteNumbers = new Array(byteCharacters.length);
+ for (let i = 0; i < byteCharacters.length; i++) {
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
+ }
+ const byteArray = new Uint8Array(byteNumbers);
+ const blob = new Blob([byteArray], {type: 'application/pdf'});
+
+ // 生成临时URL
+ const url = URL.createObjectURL(blob);
+
+ // 使用PDF.js渲染
+ pdfjsLib.getDocument(url).promise.then(pdf => {
+ // 循环渲染所有页面
+ for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
+ pdf.getPage(pageNum).then(page => {
+ const scale = 1.5;
+ const viewport = page.getViewport({scale: scale});
+ const canvas = document.createElement('canvas');
+ const context = canvas.getContext('2d');
+ canvas.height = viewport.height;
+ canvas.width = viewport.width;
+
+ // 创建页面容器
+ const pageDiv = document.createElement('div');
+ pageDiv.className = 'pdf-page';
+ pageDiv.style.margin = '10px 0';
+ container.appendChild(pageDiv);
+
+ // 渲染到Canvas
+ page.render({
+ canvasContext: context,
+ viewport: viewport
+ }).promise.then(() => {
+ pageDiv.appendChild(canvas);
+ });
+ });
+ }
+ });
+ }
+
+ // 打印函数
+ window.printPdf = function() {
+ let base64Image = window.currentPDF;
+ const printWindow = window.open('', '_blank');
+ printWindow.document.write(`
+ <html>
+ <head>
+ <title>电子面单打印</title>
+ <style>
+ body { margin: 0; padding: 20px }
+ canvas {
+ width: 100%!important;
+ height: auto!important;
+ page-break-after: always;
+ }
+ </style>
+ </head>
+ <body>
+ <iframe src="data:application/pdf;base64,`+base64Image+`" width="100%" height="100%"></iframe>
+ </body>
+ </html>
+ `);
+ printWindow.document.close();
+ printWindow.onload = function() {
+ printWindow.print();
+ printWindow.close();
+ }
+ }
+
+ // function deliverPdfGoods(id) {
+ // febs.get(ctx + 'admin/order/deliverPdfGoods/' + id, null, function (e) {
+ // if(e.code == 200){
+ // console.info(e.data);
+ // console.info(e.data.pdfStream);
+ // console.info(e.data.result);
+ // layer.open({
+ // type: 1,
+ // title: "电子面单",
+ // skin: 'layui-layer-rim', //加上边框
+ // area: ['100%', '100%'], //宽高
+ // shadeClose: true, //开启遮罩关闭
+ // end: function (index, layero) {
+ // return false;
+ // },
+ // content: '<div class="layui-card-body" id="pdfViewer"></div>'
+ // });
+ // if(e.data.pdfStream === null){
+ //
+ // renderPdf(e.data.pdfStreamList);
+ // }
+ // renderPdf(e.data.pdfStream);
+ // }else{
+ // febs.alert.warn(e.message);
+ // }
+ // $query.click();
+ // });
+ // }
+
+ // 渲染 PDF 到页面
+ // function renderPdf(base64Data) {
+ // // Base64 转 Blob
+ // const byteCharacters = atob(base64Data);
+ // const byteNumbers = new Array(byteCharacters.length);
+ // for (let i = 0; i < byteCharacters.length; i++) {
+ // byteNumbers[i] = byteCharacters.charCodeAt(i);
+ // }
+ // const byteArray = new Uint8Array(byteNumbers);
+ // const blob = new Blob([byteArray], {type: 'application/pdf'});
+ //
+ // // 生成临时 URL
+ // const url = URL.createObjectURL(blob);
+ //
+ // // 使用 PDF.js 渲染
+ // pdfjsLib.getDocument(url).promise.then(function(pdf) {
+ // pdf.getPage(1).then(function(page) {
+ // const scale = 1.5;
+ // const viewport = page.getViewport({scale: scale});
+ // const canvas = document.createElement('canvas');
+ // const context = canvas.getContext('2d');
+ // canvas.height = viewport.height;
+ // canvas.width = viewport.width;
+ //
+ // // 将 PDF 页面渲染到 Canvas
+ // page.render({
+ // canvasContext: context,
+ // viewport: viewport
+ // }).promise.then(function() {
+ // $('#pdfViewer').html(canvas);
+ // });
+ // });
+ // }).catch(function(error) {
+ // layer.msg('PDF渲染失败: ' + error.message, {icon: 2});
+ // });
+ // }
// 查询按钮
$query.on('click', function () {
@@ -411,6 +604,7 @@
{field: 'orderNo', title: '订单编号', minWidth: 200,align:'left' ,totalRowText:"合计"},
{field: 'memberName', title: '购买人', minWidth: 100,align:'left'},
{field: 'memberPhone', title: '联系方式', minWidth: 120,align:'left'},
+ {field: 'refererName', title: '推荐人', minWidth: 100,align:'left'},
{field: 'goodsName', title: '商品', minWidth: 160,align:'left'},
{field: 'remark', title: '备注', minWidth: 160,align:'left'},
{field: 'goodsAmount', title: '价格', minWidth: 80,align:'left', totalRow:true},
@@ -455,11 +649,13 @@
{title: '操作',
templet: function (d) {
if(d.status === 2){
- return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="seeOrder" shiro:hasPermission="user:update">详情</button>'
- +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="deliverGoods" shiro:hasPermission="user:update">发货</button>'
+ return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="deliverPdfGoods" shiro:hasPermission="user:update">一键发货</button>'
+ +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="seeOrder" shiro:hasPermission="user:update">详情</button>'
+ // +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="deliverGoods" shiro:hasPermission="user:update">发货</button>'
}else if(d.status === 3){
return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="seeOrder" shiro:hasPermission="user:update">详情</button>'
- +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateDeliver" shiro:hasPermission="user:update">修改物流信息</button>'
+ +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="cancelDeliver" shiro:hasPermission="user:update">取消发货</button>'
+ // +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateDeliver" shiro:hasPermission="user:update">修改物流信息</button>'
}else{
return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="seeOrder" shiro:hasPermission="user:update">详情</button>'
}
--
Gitblit v1.9.1