2024-07-25 11:03:20 +08:00
|
|
|
|
let form, layer, table, tableIns;
|
|
|
|
|
|
let pageNum = 1, limitSize = 10; // 默认第一页,分页数量为10
|
|
|
|
|
|
let selectedIds = []; // 存储选中项的ID
|
2024-07-29 08:58:02 +08:00
|
|
|
|
let temp_table_list = []; // 临时保存每页的所有数据
|
|
|
|
|
|
let temp_all_list = []; // 临时保存所有选中的数据
|
2024-07-25 11:03:20 +08:00
|
|
|
|
layui.use(['form', 'layer', 'table', 'laydate'], function () {
|
|
|
|
|
|
form = layui.form;
|
|
|
|
|
|
layer = layui.layer;
|
|
|
|
|
|
table = layui.table;
|
|
|
|
|
|
var laydate = layui.laydate;
|
|
|
|
|
|
// 渲染
|
|
|
|
|
|
laydate.render({
|
|
|
|
|
|
elem: '#ID-laydate-rangeLinked',
|
|
|
|
|
|
range: ['#startTime', '#endTime'],
|
|
|
|
|
|
rangeLinked: true // 开启日期范围选择时的区间联动标注模式 --- 2.8+ 新增
|
|
|
|
|
|
});
|
|
|
|
|
|
layui.form.render();
|
|
|
|
|
|
getDevSelected();
|
|
|
|
|
|
pages(1, 10, 1);
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
function pages(pageNum, pageSize, typeNum) {
|
|
|
|
|
|
let params = getReqParams(pageNum, pageSize, typeNum);
|
|
|
|
|
|
let url = dataUrl + "/primaryDatas/getList"
|
|
|
|
|
|
ajaxRequest(url, "POST", params, true, function () {
|
|
|
|
|
|
}, function (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",
|
2024-07-29 08:58:02 +08:00
|
|
|
|
id: 'testData',
|
2024-07-25 11:03:20 +08:00
|
|
|
|
data: dataList,
|
|
|
|
|
|
limit: limit,
|
|
|
|
|
|
cols: [
|
|
|
|
|
|
[
|
2024-07-29 08:58:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
type: 'checkbox'
|
|
|
|
|
|
},
|
2024-07-25 11:03:20 +08:00
|
|
|
|
//表头
|
2024-07-29 08:58:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: "序号", width: 80, unresize: true, align: "center",
|
2024-07-25 11:03:20 +08:00
|
|
|
|
templet: function (d) {
|
2024-07-26 18:49:55 +08:00
|
|
|
|
return (page - 1) * limit + d.LAY_NUM;
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{field: "customName", title: "送样单位", unresize: true, align: "center"},
|
|
|
|
|
|
{field: "sampleTime", title: "送样时间", unresize: true, align: "center"},
|
2024-09-28 20:20:33 +08:00
|
|
|
|
{field: "sampleDev", title: "送样样品", unresize: true, align: "center"},
|
2024-07-25 11:03:20 +08:00
|
|
|
|
{field: "customNum", title: "送样数量", unresize: true, align: "center"},
|
|
|
|
|
|
{field: "sampleDate", title: "收样时间", unresize: true, align: "center"},
|
|
|
|
|
|
{field: "sampleUserName", title: "收样人", unresize: true, align: "center"},
|
2024-07-29 08:58:02 +08:00
|
|
|
|
// {field: "experTime", title: "试验时间", unresize: true, align: "center"},
|
2024-07-25 11:03:20 +08:00
|
|
|
|
{field: "teamName", title: "试验班组", unresize: true, align: "center"},
|
2024-07-29 08:58:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: "操作", unresize: true, width: 300, align: "center",
|
2024-07-25 11:03:20 +08:00
|
|
|
|
templet: function (d) {
|
2024-07-29 08:58:02 +08:00
|
|
|
|
return '<a href="#" style="color: blue;" onclick="testClick(\'' + d.id + '\',\'' + d.customNum + '\')">查看</a>';
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
],
|
|
|
|
|
|
done: function (res, curr, count) {
|
|
|
|
|
|
layer.close(loadingMsg);
|
2024-07-29 08:58:02 +08:00
|
|
|
|
table.resize("testData");
|
2024-07-25 11:03:20 +08:00
|
|
|
|
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-29 08:58:02 +08:00
|
|
|
|
temp_table_list = res.data;
|
|
|
|
|
|
temp_table_list.forEach(function (o, i) {
|
|
|
|
|
|
for (let j = 0; j < temp_all_list.length; j++) {
|
|
|
|
|
|
if (temp_all_list[j].id === o.id) {
|
|
|
|
|
|
// 这里才是真正的有效勾选
|
|
|
|
|
|
o["LAY_CHECKED"] = 'true';
|
|
|
|
|
|
// 找到对应数据改变勾选样式,呈现出选中效果
|
|
|
|
|
|
let index = o['LAY_INDEX'];
|
|
|
|
|
|
$('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
|
|
|
|
|
|
$('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
|
|
|
|
|
|
}
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
})
|
|
|
|
|
|
// 设置全选checkbox的选中状态,只有改变LAY_CHECKED的值, table.checkStatus才能抓取到选中的状态
|
|
|
|
|
|
let checkStatus = table.checkStatus('testData');
|
|
|
|
|
|
if (checkStatus.isAll) {// 是否全选
|
|
|
|
|
|
// layTableAllChoose
|
|
|
|
|
|
$('.layui-table th[data-field="0"] input[type="checkbox"]').prop('checked', true);//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名
|
|
|
|
|
|
$('.layui-table th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名
|
|
|
|
|
|
}
|
2024-07-25 11:03:20 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-07-29 08:58:02 +08:00
|
|
|
|
// 选中行监听(临时存储复选数据,用于列表复选框回显上一页)
|
|
|
|
|
|
table.on('checkbox(testData)', function (obj) {
|
|
|
|
|
|
if (obj.checked == true) {
|
|
|
|
|
|
if (obj.type == 'one') {
|
|
|
|
|
|
let index = checkAllList(temp_all_list, obj.data);
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
|
temp_all_list.push(obj.data);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
temp_table_list.forEach(function (o, i) {
|
|
|
|
|
|
let index = checkAllList(temp_all_list, o);
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
|
temp_all_list.push(o);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-07-25 11:03:20 +08:00
|
|
|
|
} else {
|
2024-07-29 08:58:02 +08:00
|
|
|
|
let all_list = []; // 使用临时数组,防止删除临时选中所有的数组错乱
|
|
|
|
|
|
if (obj.type == 'one') {
|
|
|
|
|
|
temp_all_list.forEach(function (o, i) {
|
|
|
|
|
|
if (o.id != obj.data.id) {
|
|
|
|
|
|
all_list.push(o);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
temp_all_list.forEach(function (o, i) {
|
|
|
|
|
|
let index = checkAllList(temp_table_list, o);
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
|
all_list.push(o);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
temp_all_list = all_list;
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-07-29 08:58:02 +08:00
|
|
|
|
}
|
2024-07-25 11:03:20 +08:00
|
|
|
|
|
2024-07-29 08:58:02 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 判断数组重复
|
|
|
|
|
|
*/
|
|
|
|
|
|
function checkAllList(list, obj) {
|
|
|
|
|
|
for (let j = 0; j < list.length; j++) {
|
|
|
|
|
|
if (list[j].id == obj.id) {
|
|
|
|
|
|
return j;
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
return -1;
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取参数
|
|
|
|
|
|
function getReqParams(page, limit, type) {
|
|
|
|
|
|
let obj = {};
|
|
|
|
|
|
if (!type) {
|
|
|
|
|
|
obj = {
|
|
|
|
|
|
page: page + "",
|
|
|
|
|
|
limit: limit + "",
|
|
|
|
|
|
devTypeCode: $('#devId').val(),
|
|
|
|
|
|
keyWord: $('#keyWord').val(),
|
|
|
|
|
|
sampleUserName: $('#sampleUserName').val(),
|
|
|
|
|
|
startTime: $('#startTime').val(),
|
|
|
|
|
|
endTime: $('#endTime').val(),
|
|
|
|
|
|
};
|
|
|
|
|
|
} else {
|
|
|
|
|
|
obj = {
|
|
|
|
|
|
page: '1',
|
|
|
|
|
|
limit: '10',
|
|
|
|
|
|
devTypeCode: '',
|
|
|
|
|
|
keyWord: '',
|
|
|
|
|
|
sampleUserName: '',
|
|
|
|
|
|
startTime: '',
|
2024-07-29 08:58:02 +08:00
|
|
|
|
endTime: ''
|
2024-07-25 11:03:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
obj = {
|
|
|
|
|
|
encryptedData: encryptCBC(JSON.stringify(obj))
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询/重置
|
|
|
|
|
|
function query() {
|
|
|
|
|
|
pageNum = 1;
|
|
|
|
|
|
pages(1, limitSize);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function reloadData() {
|
|
|
|
|
|
pages(pageNum, limitSize);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-29 08:58:02 +08:00
|
|
|
|
// 原始记录管理-查看
|
|
|
|
|
|
function testClick(id, customNum) {
|
|
|
|
|
|
let title = '查看'
|
2024-07-25 11:03:20 +08:00
|
|
|
|
let param = {
|
|
|
|
|
|
'id': id,
|
2024-07-29 08:58:02 +08:00
|
|
|
|
'customNum': customNum
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
openIframe3("primaryDataList", title, "child/primaryDataList.html", '1500px', '750px', param);
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getDevSelected() {
|
|
|
|
|
|
let url = dataUrl + '/sys/select/getDicts';
|
|
|
|
|
|
let obj = {
|
2024-07-29 08:58:02 +08:00
|
|
|
|
'code': "dev_code"
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
let params = {
|
|
|
|
|
|
encryptedData: encryptCBC(JSON.stringify(obj))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ajaxRequest(url, "POST", params, true, function () {
|
|
|
|
|
|
}, function (result) {
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
|
|
|
setSelectValue(result.data, 'devId');
|
|
|
|
|
|
// return result.data
|
|
|
|
|
|
} else {
|
|
|
|
|
|
layer.alert(result.msg, {icon: 2})
|
|
|
|
|
|
}
|
|
|
|
|
|
}, function (xhr) {
|
|
|
|
|
|
error(xhr)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*下拉选表单赋值*/
|
|
|
|
|
|
function setSelectValue(list, selectName) {
|
2024-09-28 20:20:33 +08:00
|
|
|
|
let html = '<option value="" selected>请选择样品类型</option>';
|
2024-07-25 11:03:20 +08:00
|
|
|
|
$.each(list, function (index, item) {
|
|
|
|
|
|
html += '<option value="' + item.value + '">' + item.name + '</option>';
|
|
|
|
|
|
})
|
|
|
|
|
|
$('#' + selectName).empty().append(html);
|
|
|
|
|
|
layui.form.render();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-29 08:58:02 +08:00
|
|
|
|
/**批量下载excel文件*/
|
|
|
|
|
|
function batchDownLoad() {
|
|
|
|
|
|
const size = temp_all_list.length
|
|
|
|
|
|
if (size === 0) {
|
|
|
|
|
|
return layer.msg('未选择数据', {icon: 7});
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
let idArr = [];
|
|
|
|
|
|
$.each(temp_all_list, function (index, item) {
|
|
|
|
|
|
idArr.push(item.id)
|
|
|
|
|
|
})
|
|
|
|
|
|
let obj = {
|
|
|
|
|
|
'ids': idArr
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
console.log(idArr)
|
|
|
|
|
|
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
|
|
|
|
|
let url = dataUrl + "/download/downLoadZips?token=" + tokens + "&encryptedData=" + encodeURIComponent(encryptCBC(JSON.stringify(obj)));
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
|
xhr.open("post", url, true);
|
|
|
|
|
|
xhr.responseType = "blob"; // 转换流
|
|
|
|
|
|
xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8')
|
|
|
|
|
|
xhr.onload = function () {
|
|
|
|
|
|
layer.close(loadingMsg);
|
|
|
|
|
|
if (this.status === 200) {
|
|
|
|
|
|
let blob = this.response;
|
|
|
|
|
|
var a = document.createElement("a");
|
|
|
|
|
|
var url = window.URL.createObjectURL(blob);
|
|
|
|
|
|
a.href = url;
|
|
|
|
|
|
a.download = "原始记录" + ".zip"; // 文件名
|
2024-07-25 11:03:20 +08:00
|
|
|
|
} else {
|
2024-07-29 08:58:02 +08:00
|
|
|
|
layer.msg("数据导出发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|
2024-07-29 08:58:02 +08:00
|
|
|
|
a.click();
|
|
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
|
|
};
|
|
|
|
|
|
// xhr.send(params);
|
|
|
|
|
|
xhr.send();
|
2024-09-04 13:14:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**批量下载基础数据excel文件*/
|
|
|
|
|
|
function batchDownLoadTwo() {
|
|
|
|
|
|
const size = temp_all_list.length
|
|
|
|
|
|
if (size === 0) {
|
|
|
|
|
|
return layer.msg('未选择数据', {icon: 7});
|
|
|
|
|
|
}
|
|
|
|
|
|
let idArr = [];
|
|
|
|
|
|
$.each(temp_all_list, function (index, item) {
|
|
|
|
|
|
idArr.push(item.id)
|
|
|
|
|
|
})
|
|
|
|
|
|
let obj = {
|
|
|
|
|
|
'ids': idArr
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log(idArr)
|
|
|
|
|
|
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
2024-09-05 10:55:46 +08:00
|
|
|
|
let url = dataUrl + "/downloadTwo/downLoadZipsTwo?token=" + tokens + "&encryptedData=" + encodeURIComponent(encryptCBC(JSON.stringify(obj)));
|
2024-09-04 13:14:51 +08:00
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
|
xhr.open("post", url, true);
|
|
|
|
|
|
xhr.responseType = "blob"; // 转换流
|
|
|
|
|
|
xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8')
|
|
|
|
|
|
xhr.onload = function () {
|
|
|
|
|
|
layer.close(loadingMsg);
|
|
|
|
|
|
if (this.status === 200) {
|
|
|
|
|
|
let blob = this.response;
|
|
|
|
|
|
var a = document.createElement("a");
|
|
|
|
|
|
var url = window.URL.createObjectURL(blob);
|
|
|
|
|
|
a.href = url;
|
|
|
|
|
|
a.download = "基础数据记录" + ".zip"; // 文件名
|
|
|
|
|
|
} else {
|
|
|
|
|
|
layer.msg("数据导出发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
|
|
|
|
|
|
}
|
|
|
|
|
|
a.click();
|
|
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
|
|
};
|
|
|
|
|
|
// xhr.send(params);
|
|
|
|
|
|
xhr.send();
|
2024-07-25 11:03:20 +08:00
|
|
|
|
}
|