自动化立体仓库 - WMS系统
cl
2026-03-26 dfafaeba878012f8cecb2cf620ca3183e7d23c0b
src/main/webapp/views/erpMaterialwwout/materialwwout.html
@@ -50,12 +50,18 @@
            <el-form-item label="供应商">
                <el-select v-model="tableSearchParam.venId" placeholder="选择供应商" style="width: 150px" >
                <el-select
                    v-model="tableSearchParam.venId"
                    filterable
                    clearable
                    placeholder="请选择或输入供应商名称筛选"
                    style="width: 220px"
                >
                    <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
@@ -73,6 +79,9 @@
               <el-button type="primary" @click="fnPrint('是')">打印</el-button>
            </el-form-item>
            <el-form-item label="">
               <el-button type="success" @click="exportExcel">Excel导出</el-button>
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="fnTongBu()">生成委外出库单</el-button>
            </el-form-item>
            <el-form-item label="">
@@ -81,7 +90,9 @@
            <el-form-item label="">
                <el-button type="primary" @click="dialogVisible = true">数据查询</el-button>
            </el-form-item>
            <el-form-item label="">
               <el-button type="success" @click="manualSync()">手动同步</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" row-key="id" @selection-change="handleSelectionChange" max-height="650">
            <el-table-column type="selection" >
@@ -498,14 +509,18 @@
                        });
                        return ;
                    }
                    ElementPlus.ElMessageBox.confirm('确定打印吗?')
                        .then(() => {
                            print(izPrint,0)
                        })
                        .catch(() => {
                            // catch error
                        })
                    // 打印前确认
                    if (izPrint === '是') {
                        ElementPlus.ElMessageBox.confirm('确定打印吗?')
                            .then(() => {
                                print(izPrint, 0);
                            })
                            .catch(() => {
                                // 取消
                            });
                    } else {
                        print(izPrint, 0);
                    }
                }
                function fnPrintView(izPrint){
@@ -516,120 +531,251 @@
                        });
                        return ;
                    }
                    print(izPrint,0)
                    // 打印预览直接调用打印接口(后端不校验出库完成状态)
                    print(izPrint, 0);
                }
                // 手动同步
                function manualSync() {
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择要同步的数据",
                            type: 'error'
                        });
                        return ;
                    }
                    ElementPlus.ElMessageBox.confirm('确定要同步选中的数据到WMS吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        const loading = ElementPlus.ElLoading.service({
                            lock: true,
                            text: '同步中...',
                            background: 'rgba(0, 0, 0, 0.7)',
                        });
                        // 优先使用选中的数据列表进行同步
                        $.ajax({
                            url: "http://127.0.0.1:8133/api/materialWwOut/sync/manual",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: JSON.stringify({
                                wwRecords: JSON.stringify(selectList.value)
                            }),
                            contentType: 'application/json;charset=UTF-8',
                            method: 'POST',
                            success: function(res) {
                                loading.close();
                                if (res.code == 200) {
                                    ElementPlus.ElMessage({
                                        message: res.data.message || "同步任务已提交",
                                        type: 'success'
                                    });
                                    // 刷新列表
                                    setTimeout(() => {
                                        page();
                                    }, 2000);
                                } else {
                                    ElementPlus.ElMessage({
                                        message: res.msg || "同步失败",
                                        type: 'error'
                                    });
                                }
                            },
                            error: function() {
                                loading.close();
                                ElementPlus.ElMessage({
                                    message: "同步请求失败",
                                    type: 'error'
                                });
                            }
                        });
                    }).catch(() => {
                        // 取消
                    });
                }
                function print(izPrint,izRed){
                    const LODOP = getLodop()
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    let data = JSON.parse(JSON.stringify(tableSearchParam.value))
                    data.curr = currentPage.value
                    data.limit = pageSize.value
                    if (tableSearchParam.value.datetime != null) {
                        data.datetime = null
                        data.create_time = tableSearchParam.value.datetime[0] + " - " + tableSearchParam.value.datetime[1]
                    }
                    $.ajax({
                        url: "http://127.0.0.1:8133/mo/materialwwout/updateprint",
                        url:"http://127.0.0.1:8133/mo/materialwwout/print",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: data,
                        data: JSON.stringify({
                            wwRecords : JSON.stringify(selectList.value),
                            izPrint : izPrint,
                            izRed : izRed
                        }),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'GET',
                        method: 'POST',
                        success: function(res) {
                            loading.close()
                            if (res.code == 200) {
                                ElementPlus.ElMessage({
                                    message: "打印状态更新成功!",
                                    message: "获取数据完成,等待唤起打印",
                                    type: 'success'
                                });
                                page()
                                LODOP.PRINT_INITA(0,0,800,1100,"委外加工出库单");
                                LODOP.SET_PRINT_PAGESIZE(1,0,0,"A4");
                                LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE",1);
                                // 收集二维码供应商:从选中的记录中收集所有供应商,去重后用|连接
                                var venNameSet = new Set();
                                if (selectList.value && selectList.value.length > 0) {
                                    selectList.value.forEach(function(item) {
                                        if (item.venName && item.venName.trim()) {
                                            venNameSet.add(item.venName.trim());
                                        }
                                    });
                                }
                                var venNameStr = Array.from(venNameSet).join('|');
                                // 定义添加二维码的函数
                                function addQrCodeToPrint() {
                                    // 在右上角添加二维码(如果有供应商)
                                    if (venNameStr) {
                                        // 固定二维码尺寸,保持正方形比例,避免挤占打印文本和被拉长
                                        var qrCodeWidth = 130; // 固定宽度130px
                                        var qrCodeHeight = 130; // 固定高度130px,保持正方形比例
                                        var qrCodeUrl = baseUrl + "/file/barcode/qrcode/auth?type=2&param=" + encodeURIComponent(venNameStr) + "&width=" + qrCodeWidth + "&height=" + qrCodeHeight;
                                        // 创建一个临时img元素加载图片,然后转换为base64
                                        var img = new Image();
                                        img.crossOrigin = 'anonymous';
                                        img.onload = function() {
                                            try {
                                                // 创建canvas将图片转换为base64
                                                var canvas = document.createElement('canvas');
                                                canvas.width = img.width;
                                                canvas.height = img.height;
                                                var ctx = canvas.getContext('2d');
                                                ctx.drawImage(img, 0, 0);
                                                var base64Image = canvas.toDataURL('image/png');
                                                // LODOP添加图片,使用base64格式
                                                // ADD_PRINT_IMAGE参数:Top, Left, Width, Height, ImageURL或ImageData
                                                // 二维码位置:右上角,Top: 20, Left: 650 (页面宽度800,右边留50像素边距)
                                                var displayWidth = qrCodeWidth; // 固定宽度130px
                                                var displayHeight = qrCodeHeight; // 固定高度130px,保持正方形
                                                var displayLeft = 800 - displayWidth - 20; // 右对齐,留20px边距
                                                try {
                                                    LODOP.ADD_PRINT_IMAGE(20, displayLeft, displayWidth, displayHeight, base64Image);
                                                } catch(e) {
                                                    // 如果ADD_PRINT_IMAGE失败,使用HTML方式
                                                    var htmlContent = '<img src="' + base64Image + '" style="width:' + displayWidth + 'px;height:' + displayHeight + 'px;" />';
                                                    LODOP.ADD_PRINT_HTM(20, displayLeft, displayWidth, displayHeight, htmlContent);
                                                }
                                                // 图片加载完成后,执行打印
                                                executePrint();
                                            } catch(e) {
                                                console.error("转换图片失败:", e);
                                                // 如果转换失败,只显示文本(供应商名称)
                                                var displayWidth = qrCodeWidth;
                                                var displayHeight = qrCodeHeight;
                                                var displayLeft = 800 - displayWidth - 20;
                                                LODOP.ADD_PRINT_TEXT(20, displayLeft, displayWidth, displayHeight, venNameStr);
                                                LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                                                LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
                                                executePrint();
                                            }
                                        };
                                        img.onerror = function() {
                                            console.error("加载二维码图片失败");
                                            // 如果加载失败,只显示文本(供应商名称)
                                            var displayWidth = qrCodeWidth;
                                            var displayHeight = qrCodeHeight;
                                            var displayLeft = 800 - displayWidth - 20;
                                            LODOP.ADD_PRINT_TEXT(20, displayLeft, displayWidth, displayHeight, venNameStr);
                                            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                                            LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
                                            executePrint();
                                        };
                                        img.src = qrCodeUrl;
                                    } else {
                                        // 没有供应商,直接执行打印
                                        executePrint();
                                    }
                                }
                                // 定义执行打印的函数
                                function executePrint() {
                                    // 计算表格的起始位置:如果有二维码,表格需要向下移动
                                    var tableTop = 96; // 默认表格起始位置
                                    var qrCodeTop = 20; // 二维码顶部位置
                                    var qrCodeHeight = 130; // 二维码高度
                                    var qrCodeBottom = qrCodeTop + qrCodeHeight; // 二维码底部位置:150
                                    var spacing = 10; // 二维码和表格之间的间距
                                    // 如果有二维码,且表格原始位置会被二维码覆盖,则向下移动表格
                                    if (venNameStr && tableTop < qrCodeBottom) {
                                        tableTop = qrCodeBottom + spacing; // 表格从二维码下方开始,留10px间距
                                    }
                                    if(izRed==1)
                                    {
                                        LODOP.ADD_PRINT_TEXT(28,268,331,36,"委外加工出库单(红字)");
                                    }
                                    else{
                                        LODOP.ADD_PRINT_TEXT(28,268,331,36,"委外加工出库单");
                                    }
                                    LODOP.SET_PRINT_STYLEA(0,"FontSize",20);
                                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                                    LODOP.ADD_PRINT_TEXT(69,21,213,25,"供应商:"+depName.value);
                                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                                    LODOP.ADD_PRINT_TEXT(70,268,213,25,"开工日期:"+dateFormat("YYYY-mm-dd", tableSearchParam.value.dateStart)+" 到 "+dateFormat("YYYY-mm-dd", tableSearchParam.value.dateEnd));
                                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                                    LODOP.ADD_PRINT_TABLE(tableTop,16,2000,960,CreateTable(res.data));
                                    LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",1);
                                    LODOP.SET_PRINT_MODE("FULL_WIDTH_FOR_OVERFLOW",true);
                                    // 根据izPrint参数决定是打印还是预览
                                    // izPrint=="是":直接打印,弹出打印对话框(不弹出预览窗口)
                                    // izPrint=="否":打印预览,弹出预览窗口
                                    if(izPrint=="是")
                                    {
                                        LODOP.PRINT();
                                    }
                                    else{
                                        // 打印预览,弹出预览窗口
                                        LODOP.PREVIEW();
                                    }
                                }
                                // 先添加二维码,然后执行打印
                                addQrCodeToPrint();
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                // 后端返回错误信息(校验失败)
                                ElementPlus.ElMessageBox.alert(res.msg || "打印失败", '错误', {
                                    confirmButtonText: '确定',
                                    type: 'error'
                                });
                            }
                        },
                        error: function(xhr, status, error) {
                            loading.close()
                            ElementPlus.ElMessage({
                                message: "打印请求失败,请稍后重试",
                                type: 'error'
                            });
                        }
                    });
                    var gridData = [];
                    var listVen=[];
                    for(var i=0; i<selectList.value.length; i++) {
                        var curRowData = selectList.value[i]
                        var izExist=false;
                        for (var j = 0; j < listVen.length; j++) {
                            if(curRowData.venId === listVen[j].venId)
                            {
                                izExist=true;
                                break;
                            }
                        }
                        if(izExist === false)
                        {
                            var o={};
                            o.venId=curRowData.venId;
                            o.venName=curRowData.venName;
                            listVen.push(o);
                        }
                        gridData.push(curRowData);
                    }
                    LODOP.PRINT_INITA(0,0,800,1100,"委外加工出库单");
//        LODOP.SET_PRINT_PAGESIZE(1,0,0,"A5");
//        LODOP.SET_PRINT_PAGESIZE(1,870,520,"");
//        LODOP.PRINT_INITA(0,0,800,500,"委外加工出库单");
//        LODOP.SET_PRINT_PAGESIZE(1,800,500,"");
                    LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE",1);
                    LODOP.ADD_PRINT_TEXT(28,375,331,36,"委外加工出库单");
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",20);
                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                    LODOP.ADD_PRINT_TEXT(69,128,413,25,"开工日期:"+dateFormat("YYYY-mm-dd", tableSearchParam.value.dateStart)+" 到 "+dateFormat("YYYY-mm-dd", tableSearchParam.value.dateEnd));
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                    LODOP.ADD_PRINT_TEXT(69,451,196,25,"单据日期:"+dateFormat("YYYY-mm-dd", new Date()));
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                    LODOP.ADD_PRINT_TEXT(69,645,176,25,"发料人:");
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                    LODOP.ADD_PRINT_TABLE(96,123,2000,960,CreateTable(gridData));
                    LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",1);
                    LODOP.SET_PRINT_MODE("FULL_WIDTH_FOR_OVERFLOW",true);
                    LODOP.PRINT_DESIGN();
                    //        if(izPrint=="是")
                    //        {
                    //            LODOP.PRINT();
                    //        }
                    //        else{
                    //            LODOP.PREVIEW();
                    //        }
                }
                function dateFormat(fmt, date) {
@@ -653,33 +799,51 @@
                }
                function  CreateTable(result) {
//        var css =" <style> table,td,th {border: 1px solid black;border-style: solid;border-collapse: collapse;font-size: 15px;}</style><table border=1>";
                    var css = "<style> table,td,th {table-layout: fixed;border: 1px black solid;border-collapse: collapse;font-size: 15px;}</style><table>";
                    var css = "<style> table,td,th {table-layout: fixed;border: 1px black solid;border-collapse: collapse;font-size: 13px;}</style><table>";
                    //第一行
                    var th = "<thead><tr style='height:30px'>" +
                    var th = "<thead><tr style='height:20px'>" +
                        "<th  >序号</th>" +
                        "<th  >供应商</th>" +
                        "<th  >物料编码</th>" +
                        "<th  >物料名称</th>" +
                        "<th  >物料规格</th>" +
                        "<th >规格</th>" +
                        "<th  >单位</th>" +
                        "<th  >仓库</th>" +
                        "<th  >应发数量</th>" +
                        "<th  >未发数量</th>" +
                        "<th  >实发数量</th>" +
                        "</tr></thead>";
                    var td="";
                    var row=1;
                    for (var i = 0; i <result.length; i++) {
                        td = td+"<tr style='height:30px'><td style='width:30px;' align='center' >"+(row)+"</td><td style='width:170px;word-wrap:break-word;word-break:break-all;'  align='left'  >" + result[i].venName + "</td><td style='width:90px;'  align='left'  >" + result[i].invCode + "</td><td style='width:110px;word-wrap:break-word;word-break:break-all;'  align='left'  >" + result[i].invName + "</td> <td style='width:60px;'  align='left'  >" + result[i].invStd + "</td>  <td style='width:40px;'  align='left'  >" + result[i].unit + "</td><td style='width:80px;'  align='left'  >" + result[i].whName + "</td> <td style='width:60px;'  align='left'  >" + result[i].fqty + "</td> <td style='width:60px;'  align='left'  >" + result[i].wqty + "</td> <td style='width:60px;'  align='left'  ></td>  </tr>"
                        td = td+"<tr style='height:20px'><td style='width:30px;' align='center' >"+(row)+"</td><td style='width:170px;word-wrap:break-word;word-break:break-all;'  align='left'  >" + (result[i].venName || '') + "</td><td style='width:80px;'  align='left'  >" + (result[i].invCode || '') + "</td><td style='width:250px;word-wrap:break-word;word-break:break-all;'  align='left'  >" + (result[i].invName || '') + "</td>  <td style='width:50px;'  align='left'  >" + (result[i].invStd || '') + "</td> <td style='width:35px;'  align='left'  >" + (result[i].unit || '') + "</td><td style='width:80px;'  align='left'  >" + (result[i].whName || '') + "</td><td style='width:60px;'  align='left'  >" + (result[i].fqty || 0) + "</td><td style='width:60px;'  align='left'  ></td>   </tr>"
                        row++;
                    }
                    var txt = css +th+ td +"</table>";
                    return txt;
                }
                function exportExcel() {
                    if (selectList.value.length === 0) {
                        ElementPlus.ElMessage({
                            message: "请先选择要导出的数据",
                            type: 'error'
                        });
                        return;
                    }
                    var tableHtml = CreateTable(selectList.value);
                    var html = "<html><head><meta charset='utf-8' /></head><body>" + tableHtml + "</body></html>";
                    var blob = new Blob(['\ufeff' + html], { type: 'application/vnd.ms-excel;charset=utf-8;' });
                    var link = document.createElement('a');
                    var url = URL.createObjectURL(blob);
                    link.href = url;
                    link.download = "委外加工出库单_" + dateFormat("YYYYmmddHHMMSS", new Date()) + ".xls";
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    URL.revokeObjectURL(url);
                }
@@ -728,9 +892,11 @@
                    dialogPage,
                    fnPrint,
                    fnPrintView,
                    exportExcel,
                    fnCanelPrint,
                    fnTongBu,
                    fnCanelTongBu,
                    manualSync,
                    handleSizeChange,
                    handleCurrentChange,
                    handleSelectionChange,