ah_sz_gqj/src/main/resources/static/js/tools/toolsMge.js

369 lines
12 KiB
JavaScript
Raw Normal View History

2024-07-20 22:28:17 +08:00
let form, layer, table, tableIns;
2024-07-20 15:11:12 +08:00
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为10
let orgData,selectOrgId;
2024-07-25 10:23:47 +08:00
var modal = $('#myModal');
var span = $('.close');
var printButton = $('#PrintButton');
2024-07-20 15:11:12 +08:00
2024-07-20 22:28:17 +08:00
layui.use(['form', 'layer', 'table', 'laydate'], function () {
2024-07-20 15:11:12 +08:00
form = layui.form;
layer = layui.layer;
table = layui.table;
layui.form.render();
pages(1, 10, 1);
2024-07-20 22:28:17 +08:00
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})
2024-07-20 15:11:12 +08:00
}
2024-07-20 22:28:17 +08:00
}, function (xhr) {
error(xhr)
2024-07-20 15:11:12 +08:00
});
2024-07-20 22:28:17 +08:00
}
2024-07-20 15:11:12 +08:00
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
2024-07-20 22:28:17 +08:00
let url = dataUrl + "/tools/getList"
2024-07-20 15:11:12 +08:00
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: [
[
2024-07-25 11:02:55 +08:00
{type: "checkbox", width: 50, unresize: true, align: "center"},
2024-07-20 15:11:12 +08:00
//表头
2024-07-27 21:59:26 +08:00
{title: "序号", width: 70, unresize: true, align: "center",
2024-07-20 15:11:12 +08:00
templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
2024-07-27 21:59:26 +08:00
{field: "sampleTools", width:155,title: "设备类型", unresize: true, align: "center"},
{field: "devCode", width:150,title: "设备编号", unresize: true, align: "center"},
{field: "customerCode", width:150,title: "设备编码", unresize: true, align: "center"},
{field: "devModule", width:150,title: "设备规格", unresize: true, align: "center"},
{field: "customName", width:175,title: "送样单位", unresize: true, align: "center"},
{field: "sampleDepartment", width:170,title: "送样部门", unresize: true, align: "center"},
{field: "manufactureDate", width:150,title: "生产日期", unresize: true, align: "center"},
{field: "experTime", width:150,title: "试验日期", unresize: true, align: "center"},
{field: "experConclu", width:120,title: "试验结果", unresize: true, align: "center"},
2024-07-22 09:12:12 +08:00
{
2024-07-27 21:59:26 +08:00
field: "certificate", title: "合格证",width:90, unresize: true, align: "center", templet: function (d) {
2024-07-22 09:12:12 +08:00
console.log("d",d.id);
2024-07-25 09:12:44 +08:00
return '<a href="#" style="color: blue;" onclick="handleClick1(\'' + d.submitLocation + '\',\'' + d.sampleTools + '\',\'' + d.devModule + '\',\'' + d.devCode + '\',\'' + d.experTime + '\',\'' + d.nextExperTime + '\',\'' + d.experUser + '\',\'' + d.experConclu + '\',\'' + d.customName + '\')">查看</a>';
2024-07-20 15:11:12 +08:00
}
},
2024-07-22 09:12:12 +08:00
{
2024-07-27 21:59:26 +08:00
field: "qrCode", title: "二维码", width: 90, unresize: true, align: "center", templet: function (d) {
2024-07-25 10:23:47 +08:00
return '<a href="#" style="color: blue;" onclick="handleClick2(\'' + d.submitLocation + '\',\'' + d.sampleTools + '\',\'' + d.devModule + '\',\'' + d.devCode + '\',\'' + d.experTime + '\',\'' + d.nextExperTime + '\',\'' + d.experUser + '\',\'' + d.experConclu + '\',\'' + d.customName + '\')">打印</a>';
2024-07-22 09:12:12 +08:00
}
},
2024-07-20 15:11:12 +08:00
],
],
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");
},
});
}
2024-07-25 09:12:44 +08:00
function handleClick1(submitLocation,sampleTools,devModule,devCode,experTime,nextExperTime,experUser,experConclu,customName) {
2024-07-22 09:12:12 +08:00
title = '合格证';
let param = {
2024-07-25 09:12:44 +08:00
'submitLocation' : submitLocation,
2024-07-22 09:12:12 +08:00
'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);
}
2024-07-25 10:23:47 +08:00
/**
* 打印二维码
*/
function handleClick2(submitLocation,sampleTools,devModule,devCode,experTime,nextExperTime,experUser,experConclu,customName) {
2024-07-25 09:12:44 +08:00
// 准备二维码内容
const qrCodeData = {
2024-07-25 10:23:47 +08:00
"样品名称": sampleTools,
"规格型号": devModule,
"样品编号": devCode,
"检验日期": experTime,
"下次检验日期": nextExperTime,
"试验人员": experUser,
"试验结果": experConclu,
"送检单位": customName
2024-07-25 09:12:44 +08:00
};
// 将对象转换为字符串
2024-07-25 10:23:47 +08:00
const qrCodeString = JSON.stringify(qrCodeData, null, 2);
2024-07-25 09:12:44 +08:00
// 清空二维码容器
$('#Qrcode').empty();
// 生成二维码
$('#Qrcode').qrcode(utf16to8(qrCodeString));
2024-07-25 10:23:47 +08:00
// 显示模态对话框
modal.show();
// // 打印二维码
// printQRCode();
window.print();
2024-07-22 09:12:12 +08:00
}
2024-07-25 10:23:47 +08:00
// 点击模态对话框外部区域也可以关闭模态对话框
$(window).click(function(event) {
if ($(event.target).is(modal)) {
modal.hide();
}
});
2024-07-25 11:02:55 +08:00
/**
* 批量下载
*/
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();
});
}
2024-07-25 10:23:47 +08:00
2024-07-25 09:12:44 +08:00
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;
}
2024-07-20 15:11:12 +08:00
// 获取参数
function getReqParams(page, limit, type) {
2024-07-20 22:28:17 +08:00
var selectedValue =$('#sampleTools').val()
// 2. 查找对应的选项文本
var selectedText = $('#sampleTools option[value="' + selectedValue + '"]').text();
2024-07-22 09:12:12 +08:00
if (selectedText=='请选择设备类型'){
2024-07-20 22:28:17 +08:00
selectedText=''
}
2024-07-20 15:11:12 +08:00
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
2024-07-20 22:28:17 +08:00
sampleTools: selectedText,
2024-07-22 09:12:12 +08:00
keyWord:$('#keyWord').val()
2024-07-20 15:11:12 +08:00
};
} else {
obj = {
page: '1',
limit: '10',
2024-07-22 09:12:12 +08:00
sampleTools: '',
keyWord: ''
2024-07-20 15:11:12 +08:00
};
}
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) {
2024-07-20 22:28:17 +08:00
title = '工器具个体管理/详情';
2024-07-20 15:11:12 +08:00
}
let param = {
'id': id
}
2024-07-20 22:28:17 +08:00
openIframe2("addOrEditUser", title, "child/toolsForm.html", '100%', '100%', param);
2024-07-20 15:11:12 +08:00
}
// 启用/停用/解除锁定
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) {
2024-07-20 22:28:17 +08:00
console.log("list",list)
2024-07-22 09:12:12 +08:00
let html = '<option value="" selected>请选择设备类型</option>';
2024-07-20 15:11:12 +08:00
$.each(list, function (index, item) {
html += '<option value="' + item.id + '">' + item.name + '</option>';
})
$('#' + selectName).empty().append(html);
layui.form.render();
}