let form, layer, table, tableIns; let pageNum = 1, limitSize = 10; // 默认第一页,分页数量为10 let orgData,selectOrgId; var modal = $('#myModal'); var span = $('.close'); var printButton = $('#PrintButton'); layui.use(['form', 'layer', 'table', 'laydate'], function () { form = layui.form; layer = layui.layer; table = layui.table; layui.form.render(); pages(1, 10, 1); getToolsSelected(); }) function getToolsSelected() { let url = dataUrl + '/tools/all'; ajaxRequest(url, "POST", null, true, function () { }, function (result) { if (result.code === 200) { setSelectValue(result.data, 'sampleTools'); // return result.data } else { layer.alert(result.msg, {icon: 2}) } }, function (xhr) { error(xhr) }); } function pages(pageNum, pageSize, typeNum) { let params = getReqParams(pageNum, pageSize, typeNum); let url = dataUrl + "/tools/getList" ajaxRequest(url, "POST", params, true, function () { }, function (result) { console.log(result); if (result.code === 200) { if (result.data) { initTable(result.data, result.limit, result.curr) laypages(result.count, result.curr, result.limit) } } else if (result.code === 500) { layer.alert(result.msg, {icon: 2}) } }, function (xhr) { error(xhr) }); } function laypages(total, page, limit) { layui.use(['laypage'], function () { let laypage = layui.laypage; laypage.render({ elem: 'voi-page', count: total, curr: page, limit: limit, limits: [10, 20, 50, 100, 200, 500], layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], groups: 5, jump: function (obj, first) { if (!first) { pageNum = obj.curr, limitSize = obj.limit; pages(obj.curr, obj.limit, null); } } }); }) } /*初始化表格*/ function initTable(dataList, limit, page) { let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0}); tableIns = table.render({ elem: "#table_data", height: "full-130", data: dataList, limit: limit, cols: [ [ {type: "checkbox", width: 50, unresize: true, align: "center"}, //表头 {title: "序号", width: 70, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "sampleTools", width: 155, title: "设备类型", unresize: true, align: "center", templet: function (d) { return `
${d.sampleTools}
`; } }, { field: "devCode", width: 150, title: "设备编号", unresize: true, align: "center", templet: function (d) { return `
${d.devCode}
`; } }, { field: "customerCode", width: 150, title: "设备编码", unresize: true, align: "center", templet: function (d) { return `
${d.customerCode}
`; } }, { field: "devModule", width: 150, title: "设备规格", unresize: true, align: "center", templet: function (d) { return `
${d.devModule}
`; } }, { field: "customName", width: 175, title: "送样单位", unresize: true, align: "center", templet: function (d) { return `
${d.customName}
`; } }, { field: "sampleDepartment", width: 170, title: "送样部门", unresize: true, align: "center", templet: function (d) { return `
${d.sampleDepartment}
`; } }, { field: "manufactureDate", width: 150, title: "生产日期", unresize: true, align: "center", templet: function (d) { return `
${d.manufactureDate}
`; } }, { field: "experTime", width: 150, title: "试验日期", unresize: true, align: "center", templet: function (d) { return `
${d.experTime}
`; } }, { field: "experConclu", width: 120, title: "试验结果", unresize: true, align: "center", templet: function (d) { return `
${d.experConclu}
`; } }, { field: "certificate", title: "合格证", width: 90, unresize: true, align: "center", templet: function (d) { return `查看`; } }, { field: "qrCode", title: "二维码", width: 90, unresize: true, align: "center", templet: function (d) { return `打印`; } }, ], ], done: function (res, curr, count) { layer.close(loadingMsg); table.resize("table_data"); count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block"); count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto"); }, }); } function handleClick1(submitLocation,sampleTools,devModule,devCode,experTime,nextExperTime,experUser,experConclu,customName) { title = '合格证'; let param = { 'submitLocation' : submitLocation, 'sampleTools' : sampleTools, 'devModule' : devModule, 'devCode' : devCode, 'experTime' : experTime, 'nextExperTime' : nextExperTime, 'experUser': experUser, 'experConclu': experConclu, 'customName': customName } openIframe2("addOrEditUser", title, "child/certificateView.html", '30%', '70%', param); } /** * 打印二维码 */ function handleClick2(submitLocation,sampleTools,devModule,devCode,experTime,nextExperTime,experUser,experConclu,customName) { // 准备二维码内容 const qrCodeData = { "样品名称": sampleTools, "规格型号": devModule, "样品编号": devCode, "检验日期": experTime, "下次检验日期": nextExperTime, "试验人员": experUser, "试验结果": experConclu, "送检单位": customName }; // 将对象转换为字符串 const qrCodeString = JSON.stringify(qrCodeData, null, 2); // 清空二维码容器 $('#Qrcode').empty(); // 生成二维码 $('#Qrcode').qrcode(utf16to8(qrCodeString)); // 显示模态对话框 modal.show(); // // 打印二维码 // printQRCode(); window.print(); } // 点击模态对话框外部区域也可以关闭模态对话框 $(window).click(function(event) { if ($(event.target).is(modal)) { modal.hide(); } }); /** * 批量下载 */ function batchDownload() { var selectedRows = table.checkStatus("table_data").data; if (selectedRows.length == 0) { return layer.msg('请选择要下载的数据', {icon: 7}) } // 创建一个临时 canvas 用于绘制带白边的二维码 var qrWidth = 300; // 二维码的标准宽度 var whiteBorder = 20; // 白边的宽度 var totalWidth = qrWidth + 2 * whiteBorder; // 总宽度 var canvas = document.createElement('canvas'); canvas.width = totalWidth; canvas.height = totalWidth; // 保持正方形 var ctx = canvas.getContext('2d'); selectedRows.forEach(function (row, index) { // 准备二维码内容 const qrCodeData = { "样品名称": row.sampleTools, "规格型号": row.devModule, "样品编号": row.devCode, "检验日期": row.experTime, "下次检验日期": row.nextExperTime, "试验人员": row.experUser, "试验结果": row.experConclu, "送检单位": row.customName }; // 创建二维码并填充白色背景 $('#qr-canvas').empty(); $('#qr-canvas').qrcode(utf16to8(JSON.stringify(qrCodeData, null, 2))); // 获取 qr-canvas 中的二维码元素 var qrCanvas = document.querySelector('#qr-canvas canvas'); var qrSize = qrCanvas.width; // 绘制白边 ctx.fillStyle = "#FFFFFF"; // 设置白色 ctx.fillRect(0, 0, totalWidth, totalWidth); // 填充整个画布 // 计算二维码的位置以确保居中 var xOffset = (totalWidth - qrSize) / 2; var yOffset = (totalWidth - qrSize) / 2; // 将二维码绘制到白边画布中,居中对齐 ctx.drawImage(qrCanvas, xOffset, yOffset, qrSize, qrSize); var dataURL = canvas.toDataURL('image/png'); // 创建下载链接并自动点击 var link = document.createElement('a'); link.href = dataURL; link.download = `QRCode_${index + 1}.png`; link.click(); }); } function utf16to8(str) { var out, i, len, c; out = ""; len = str.length; for (i = 0; i < len; i++) { c = str.charCodeAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += str.charAt(i); } else if (c > 0x07FF) { out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } else { out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } } return out; } // 获取参数 function getReqParams(page, limit, type) { var selectedValue =$('#sampleTools').val() // 2. 查找对应的选项文本 var selectedText = $('#sampleTools option[value="' + selectedValue + '"]').text(); if (selectedText=='请选择设备类型'){ selectedText='' } let obj = {}; if (!type) { obj = { page: page + "", limit: limit + "", sampleTools: selectedText, keyWord:$('#keyWord').val() }; } else { obj = { page: '1', limit: '10', sampleTools: '', keyWord: '' }; } console.log(obj) obj={ encryptedData:encryptCBC(JSON.stringify(obj)) } return obj; } // 查询/重置 function query() { let pattern = new RegExp("[%_<>]"); if (pattern.test($("#loginName").val())) { $("#loginName").val(''); return layer.msg('用户名查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } if (pattern.test($("#phone").val())) { $("#phone").val(''); return layer.msg('手机号查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } pageNum = 1; pages(1, limitSize); } //重置 function reset() { pages(1, limitSize, 1) } function reloadData() { pages(pageNum, limitSize); } // 新增/修改平台用户 function addData(id) { if (id) { title = '工器具个体管理/详情'; } let param = { 'id': id } openIframe2("addOrEditUser", title, "child/toolsForm.html", '100%', '100%', param); } // 启用/停用/解除锁定 function editUserAccountStatus(id, status, type) { let url = dataUrl + "/sys/user/editUserAccountStatus?token=" + token; let params = { 'id': id, 'accountStatus': status, 'type': type } ajaxRequest(url, "POST", params, true, function () { }, function (result) { if (result.code === 200) { if(type){ reloadData(); } parent.layer.msg(result.msg, {icon: 1}) } else if (result.code === 500) { layer.alert(result.msg, {icon: 2}) } }, function (xhr) { error(xhr) }); } // 管理员修改密码 function resetPwd(id) { let param = { 'id': id, 'type': '1' } openIframe2("addOrEditUnifyUser", '修改密码', "password.html", '770px', '400px', param); } /*下拉选表单赋值*/ function setSelectValue(list, selectName) { console.log("list",list) let html = ''; $.each(list, function (index, item) { html += ''; }) $('#' + selectName).empty().append(html); layui.form.render(); }