配件排序、批量审核、页码保持不跳转

This commit is contained in:
syruan 2025-07-15 20:23:35 +08:00
parent 4a8c7a3071
commit 52a9e4775e
5 changed files with 280 additions and 4 deletions

View File

@ -1,6 +1,8 @@
let form, table, laydate;
let tableIns;
let pageNum = 1; // 定义分页
let selectedData = []; // 存储选中的数据
layui.use(["form", "table", 'laydate'], function () {
form = layui.form;
table = layui.table;
@ -10,6 +12,16 @@ layui.use(["form", "table", 'laydate'], function () {
range: ['#startDay', '#endDay'],
rangeLinked: true
});
// 监听复选框选择
table.on('checkbox(currentTableId2)', function(obj){
let checkStatus = table.checkStatus('currentTableId');
selectedData = checkStatus.data;
// 根据选中状态显示/隐藏批量审核按钮
updateBatchAuditButton();
});
initTable();
});
@ -44,6 +56,8 @@ function reloadData() {
// 重载表格
function reloadTable(pageNum) {
selectedData = []; // 清空选中数据
$('#batchAuditBtn').hide(); // 隐藏批量审核按钮
table.reload("currentTableId", {
page: {
curr: pageNum ? pageNum : 1,
@ -95,6 +109,11 @@ function initTable() {
},
cols: [
[
{
type: 'checkbox',
width: '4%',
fixed: 'left'
},
{
width: '4%',
title: "序号",
@ -253,3 +272,117 @@ function accessoryOutBoundDetail(obj, type) {
// 1.工器具 0.设备
openIframeByParamObj("accessory_out_bound_detail", "配件出库记录", "../accessory/child/accessory_out_bound_detail.html", "92%", "95%", obj);
}
// 更新批量审核按钮状态
function updateBatchAuditButton() {
let pendingAuditData = selectedData.filter(item => item.status === '1'); // 只有待审核状态的才能批量审核
if (pendingAuditData.length > 0) {
$('#batchAuditBtn').show();
} else {
$('#batchAuditBtn').hide();
}
}
// 批量审核
function batchAudit() {
let pendingAuditData = selectedData.filter(item => item.status === '1');
if (pendingAuditData.length === 0) {
return layer.msg('请选择待审核状态的数据', {icon: 2});
}
layer.open({
type: 1,
title: '批量审核 (' + pendingAuditData.length + '条)',
area: ['500px', '300px'],
content: getBatchAuditFormHtml(),
btn: ['确定', '取消'],
success: function(layero) {
// 重新渲染表单
form.render();
// 监听审核结果变化
form.on('radio(batchAuditResult)', function(data) {
if (data.value === '2') { // 通过
$('textarea[name="batchAuditRemarks"]').val('批量审核通过');
} else if (data.value === '3') { // 不通过
$('textarea[name="batchAuditRemarks"]').val('');
}
});
},
yes: function(index) {
submitBatchAudit(pendingAuditData, index);
}
});
}
// 获取批量审核表单HTML
function getBatchAuditFormHtml() {
return `
<div style="padding: 20px;">
<form class="layui-form">
<div class="layui-form-item">
<label class="layui-form-label" style="width: 80px;">审核结果</label>
<div class="layui-input-block" style="margin-left: 110px;">
<input type="radio" name="batchAuditStatus" value="2" title="通过" lay-filter="batchAuditResult" checked>
<input type="radio" name="batchAuditStatus" value="3" title="不通过" lay-filter="batchAuditResult">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label" style="width: 80px;">审核意见</label>
<div class="layui-input-block" style="margin-left: 110px;">
<textarea placeholder="不通过必须填写审核意见" name="batchAuditRemarks" class="layui-textarea" maxLength="200" style="height: 80px;">批量审核通过</textarea>
</div>
</div>
</form>
</div>
`;
}
// 提交批量审核
function submitBatchAudit(dataList, layerIndex) {
let auditStatus = $('input[name="batchAuditStatus"]:checked').val();
let auditRemarks = $('textarea[name="batchAuditRemarks"]').val();
if (auditStatus === '3' && (!auditRemarks || auditRemarks.trim() === '')) {
return layer.msg('驳回时必须填写审核意见', {icon: 2});
}
let loadingMsg = layer.msg('正在批量审核,请稍等...', {
icon: 16,
shade: 0.3,
time: 0
});
let idList = dataList.map(item => item.id);
let params = {
encryptedData: JSON.stringify({
idList: idList,
status: auditStatus,
remark: auditRemarks.trim()
})
};
ajaxRequest(dataUrl + "backstage/partApply/batchAudit", "POST", params, true,
function() {
// 请求前处理
},
function(result) {
layer.close(loadingMsg);
if (result.code === 200) {
layer.close(layerIndex);
layer.msg('批量审核成功', {icon: 1});
selectedData = [];
$('#batchAuditBtn').hide();
reloadData();
} else {
layer.msg(result.msg || '批量审核失败', {icon: 2});
}
},
function(xhr, status, error) {
layer.close(loadingMsg);
layer.msg('服务异常,请稍后重试', {icon: 2});
errorFn(xhr, status, error);
}
);
}

View File

@ -400,7 +400,8 @@ function checkValue(that, type) {
function closePage(type) {
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
if (type == 1) {
window.parent.reloadData();
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
parent.layer.close(index); // 再执行关闭window.parent.closePage();
}
parent.layer.close(index); // 再执行关闭

View File

@ -499,7 +499,8 @@ function checkValue(that, type) {
function closePage(type) {
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
if (type == 1) {
window.parent.reloadData();
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
parent.layer.close(index); // 再执行关闭
}
parent.layer.close(index); // 再执行关闭
}

View File

@ -95,7 +95,9 @@ function getDTreeData() {
}, function (result) {
if (result.code === 200) {
if (result.data && result.data.length > 0) {
$.each(result.data, function (index, item) {
// 对数据进行排序处理
var sortedData = sortDataByChildName(result.data);
$.each(sortedData, function (index, item) {
item.title = item.name;
list.push(item);
})
@ -107,6 +109,143 @@ function getDTreeData() {
return list;
}
/**
* 对数据进行排序2级level层级根据其子层3级的name编号排序
* @param {Array} data 原始数据数组
* @returns {Array} 排序后的数据数组
*/
function sortDataByChildName(data) {
try {
// 如果数据为空或无效,直接返回
if (!data || data.length === 0) {
return data;
}
// 按level分组
var level0Items = [];
var level1Items = [];
var level2Items = [];
var level3Items = [];
var otherItems = [];
for (var i = 0; i < data.length; i++) {
var item = data[i];
if (!item || typeof item.level === 'undefined') {
continue;
}
if (item.level === 0) {
level0Items.push(item);
} else if (item.level === 1) {
level1Items.push(item);
} else if (item.level === 2) {
level2Items.push(item);
} else if (item.level === 3) {
level3Items.push(item);
} else if (item.level > 3) {
otherItems.push(item);
}
}
// 如果没有2级或3级数据直接返回原始数据
if (level2Items.length === 0) {
return data;
}
// 为每个2级项目找到其最小的3级子项name编号
var level2WithMinChildName = [];
for (var j = 0; j < level2Items.length; j++) {
var level2Item = level2Items[j];
// 找到属于这个2级项目的所有3级子项
var childItems = [];
for (var k = 0; k < level3Items.length; k++) {
if (level3Items[k].parentId === level2Item.id) {
childItems.push(level3Items[k]);
}
}
// 如果有子项找到最小的name编号
var minChildName = null;
if (childItems.length > 0) {
var childNames = [];
for (var l = 0; l < childItems.length; l++) {
var childName = childItems[l].name;
if (childName) {
var match = childName.match(/\d+/);
var num = match ? parseInt(match[0]) : 999999; // 如果没有数字,给一个很大的数
childNames.push(num);
}
}
if (childNames.length > 0) {
minChildName = Math.min.apply(Math, childNames);
}
}
// 创建新对象包含排序信息
var itemWithSort = {};
for (var prop in level2Item) {
if (level2Item.hasOwnProperty(prop)) {
itemWithSort[prop] = level2Item[prop];
}
}
itemWithSort.minChildName = minChildName;
itemWithSort.childCount = childItems.length;
level2WithMinChildName.push(itemWithSort);
}
// 对2级项目按最小子项name编号排序
level2WithMinChildName.sort(function(a, b) {
// 如果都有子项编号,按编号排序
if (a.minChildName !== null && b.minChildName !== null) {
return a.minChildName - b.minChildName;
}
// 如果只有一个有子项编号,有编号的排在前面
if (a.minChildName !== null && b.minChildName === null) {
return -1;
}
if (a.minChildName === null && b.minChildName !== null) {
return 1;
}
// 如果都没有子项编号按原始name排序
if (a.name && b.name) {
return a.name.localeCompare ? a.name.localeCompare(b.name) : (a.name > b.name ? 1 : -1);
}
return 0;
});
// 移除临时添加的属性
var sortedLevel2Items = [];
for (var m = 0; m < level2WithMinChildName.length; m++) {
var originalItem = {};
for (var prop in level2WithMinChildName[m]) {
if (level2WithMinChildName[m].hasOwnProperty(prop) &&
prop !== 'minChildName' && prop !== 'childCount') {
originalItem[prop] = level2WithMinChildName[m][prop];
}
}
sortedLevel2Items.push(originalItem);
}
// 重新组合所有数据保持其他level的原始顺序
var result = [];
result = result.concat(level0Items);
result = result.concat(level1Items);
result = result.concat(sortedLevel2Items);
result = result.concat(level3Items);
result = result.concat(otherItems);
return result;
} catch (error) {
console.error("排序函数出错:", error);
// 如果排序失败,返回原始数据
return data;
}
}
// 查询、重置
function queryDtree(type) {
if (type === 1) {

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>领料出库</title>
<title>领料配件出库</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
@ -58,6 +58,8 @@
class="layui-icon layui-icon-refresh"></i> 重 置</button>
<button class="layui-btn layui-btn-primary" onclick="exportExcel()"><i
class="layui-icon layui-icon-download-circle"></i> 导 出</button>
<button class="layui-btn layui-bg-orange" id="batchAuditBtn" onclick="batchAudit()" style="display: none;"><i
class="layui-icon layui-icon-ok"></i> 批量审核</button>
</div>
</div>
</form>