ah_sz_gqj/src/main/resources/static/js/primaryData/primary.js

331 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let form, layer, table, tableIns;
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为10
let selectedIds = []; // 存储选中项的ID
let temp_table_list = []; // 临时保存每页的所有数据
let temp_all_list = []; // 临时保存所有选中的数据
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",
id: 'testData',
data: dataList,
limit: limit,
cols: [
[
{
type: 'checkbox'
},
//表头
{
title: "序号", width: 80, unresize: true, align: "center",
templet: function (d) {
return (page - 1) * limit + d.LAY_NUM;
}
},
{field: "customName", title: "送样单位", unresize: true, align: "center"},
{field: "sampleTime", title: "送样时间", unresize: true, align: "center"},
{field: "sampleDev", title: "送样样品", unresize: true, align: "center"},
{field: "customNum", title: "送样数量", unresize: true, align: "center"},
{field: "sampleDate", title: "收样时间", unresize: true, align: "center"},
{field: "sampleUserName", title: "收样人", unresize: true, align: "center"},
// {field: "experTime", title: "试验时间", unresize: true, align: "center"},
{field: "teamName", title: "试验班组", unresize: true, align: "center"},
{
title: "操作", unresize: true, width: 300, align: "center",
templet: function (d) {
return '<a href="#" style="color: blue;" onclick="testClick(\'' + d.id + '\',\'' + d.customNum + '\')">查看</a>';
}
},
],
],
done: function (res, curr, count) {
layer.close(loadingMsg);
table.resize("testData");
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");
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');
}
}
})
// 设置全选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如果在分页部分自定义了属性名则需要改成对应的属性名
}
},
});
// 选中行监听(临时存储复选数据,用于列表复选框回显上一页)
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);
}
})
}
} else {
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);
}
})
}
temp_all_list = all_list;
}
});
}
/**
* 判断数组重复
*/
function checkAllList(list, obj) {
for (let j = 0; j < list.length; j++) {
if (list[j].id == obj.id) {
return j;
}
}
return -1;
}
// 获取参数
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: '',
endTime: ''
};
}
obj = {
encryptedData: encryptCBC(JSON.stringify(obj))
}
return obj;
}
// 查询/重置
function query() {
pageNum = 1;
pages(1, limitSize);
}
function reloadData() {
pages(pageNum, limitSize);
}
// 原始记录管理-查看
function testClick(id, customNum) {
let title = '查看'
let param = {
'id': id,
'customNum': customNum
}
openIframe3("primaryDataList", title, "child/primaryDataList.html", '1500px', '750px', param);
}
function getDevSelected() {
let url = dataUrl + '/sys/select/getDicts';
let obj = {
'code': "dev_code"
}
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) {
let html = '<option value="" selected>请选择样品类型</option>';
$.each(list, function (index, item) {
html += '<option value="' + item.value + '">' + item.name + '</option>';
})
$('#' + selectName).empty().append(html);
layui.form.render();
}
/**批量下载excel文件*/
function batchDownLoad() {
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,});
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"; // 文件名
} else {
layer.msg("数据导出发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
}
a.click();
window.URL.revokeObjectURL(url);
};
// xhr.send(params);
xhr.send();
}
/**批量下载基础数据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,});
let url = dataUrl + "/downloadTwo/downLoadZipsTwo?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"; // 文件名
} else {
layer.msg("数据导出发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
}
a.click();
window.URL.revokeObjectURL(url);
};
// xhr.send(params);
xhr.send();
}