This commit is contained in:
cwchen 2024-11-15 09:32:44 +08:00
parent 757fa3958f
commit f6c7878b47
2 changed files with 47 additions and 47 deletions

View File

@ -320,8 +320,8 @@ function setTableData(results) {
if (results && results.length > 0) { if (results && results.length > 0) {
for (var i = 0; i < results.length; i++) { for (var i = 0; i < results.length; i++) {
var l = results[i]; var l = results[i];
html += "<tr id='" + l.id + "'>"; html += "<tr id='" + l.partId + "'>";
html += '<td><input onclick="sel(this.checked,this,' + l.id + ')" name="check" type="checkbox"></td>'; html += '<td><input onclick="sel(this.checked,this,' + l.partId + ')" name="check" type="checkbox"></td>';
html += "<td style='vertical-align:middle;' class='center hidden-480'>" html += "<td style='vertical-align:middle;' class='center hidden-480'>"
+ (i + 1) + "</td>"; + (i + 1) + "</td>";
html += "<td>" + l.partType + "</td>"; html += "<td>" + l.partType + "</td>";

View File

@ -1,4 +1,4 @@
let objParam, userId; let objParam, userpartId;
let form, table, tableIns, layer, util; let form, table, tableIns, layer, util;
let pageNum = 1; let pageNum = 1;
let quanju = new Array();//全局 let quanju = new Array();//全局
@ -7,7 +7,7 @@ let huancunObj = new Array();//缓存2
let jjDetailArr = []; // 退料配件类型数据 let jjDetailArr = []; // 退料配件类型数据
function setParams(obj) { function setParams(obj) {
objParam = JSON.parse(obj); objParam = JSON.parse(obj);
userId = objParam.userId; userpartId = objParam.userpartId;
console.log(objParam); console.log(objParam);
layui.use(["form", "table", 'layer', 'util'], function () { layui.use(["form", "table", 'layer', 'util'], function () {
form = layui.form; form = layui.form;
@ -33,7 +33,7 @@ function queryTable(type) {
// 重载表格 // 重载表格
function reloadTable(pageNum) { function reloadTable(pageNum) {
table.reload("currentTableId", { table.reload("currentTablepartId", {
page: { page: {
curr: pageNum ? pageNum : 1, curr: pageNum ? pageNum : 1,
}, },
@ -42,7 +42,7 @@ function reloadTable(pageNum) {
'partType': $('#partType').val(), 'partType': $('#partType').val(),
'partName': $('#partName').val(), 'partName': $('#partName').val(),
'partModel': $('#partModel').val(), 'partModel': $('#partModel').val(),
'userId': userId 'userpartId': userpartId
}), }),
}, },
}, },
@ -53,8 +53,8 @@ function reloadTable(pageNum) {
// 表格数据 // 表格数据
function initTable() { function initTable() {
tableIns = table.render({ tableIns = table.render({
elem: "#currentTableId", elem: "#currentTablepartId",
id: 'currentTableId', partId: 'currentTablepartId',
height: "full-200", height: "full-200",
headers: { headers: {
authorization: sessionStorage.getItem("gz-token"), authorization: sessionStorage.getItem("gz-token"),
@ -65,7 +65,7 @@ function initTable() {
'partType': $('#partType').val(), 'partType': $('#partType').val(),
'partName': $('#partName').val(), 'partName': $('#partName').val(),
'partModel': $('#partModel').val(), 'partModel': $('#partModel').val(),
'userId': userId 'userpartId': userpartId
}), }),
}, },
request: { request: {
@ -76,7 +76,7 @@ function initTable() {
if (jjDetailArr && res.list) { if (jjDetailArr && res.list) {
$.each(res.list, function (index, item) { $.each(res.list, function (index, item) {
$.each(jjDetailArr, function (index2, item2) { $.each(jjDetailArr, function (index2, item2) {
if (item.id === item2.id) { if (item.partId === item2.partId) {
item.ghNum = item2.ghNum; item.ghNum = item2.ghNum;
item.remark = item2.remark; item.remark = item2.remark;
} }
@ -92,9 +92,9 @@ function initTable() {
}, },
cols: [ cols: [
[ [
{ type: 'checkbox', width: '5%' }, { type: 'checkbox', wpartIdth: '5%' },
{ {
width: '9.9%', wpartIdth: '9.9%',
title: "序号", title: "序号",
align: "center", align: "center",
templet: function (d) { templet: function (d) {
@ -103,21 +103,21 @@ function initTable() {
}, },
{ {
field: "partType", field: "partType",
width: '10%', wpartIdth: '10%',
title: "配件类型", title: "配件类型",
unresize: true, unresize: true,
align: "center", align: "center",
}, },
{ {
field: "partName", field: "partName",
width: '15%', wpartIdth: '15%',
title: "配件名称", title: "配件名称",
unresize: true, unresize: true,
align: "center", align: "center",
}, },
{ {
field: "partModel", field: "partModel",
width: '10%', wpartIdth: '10%',
title: "规格型号", title: "规格型号",
unresize: true, unresize: true,
align: "center", align: "center",
@ -125,34 +125,34 @@ function initTable() {
{ {
field: "partUnit", field: "partUnit",
title: "单位", title: "单位",
width: '10%', wpartIdth: '10%',
unresize: true, unresize: true,
align: "center", align: "center",
}, },
{ {
field: "lyNum", field: "lyNum",
width: '10%', wpartIdth: '10%',
title: "累计领料数量", title: "累计领料数量",
unresize: true, unresize: true,
align: "center", align: "center",
}, },
{ {
field: "ghNum", field: "ghNum",
width: '10%', wpartIdth: '10%',
title: "<span style='color:red'> * </span>本次退回量", title: "<span style='color:red'> * </span>本次退回量",
unresize: true, unresize: true,
align: "center", align: "center",
edit: 'text', edit: 'text',
style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' style: 'outline: 1px solpartId #e6e6e6;outline-offset: -5px;'
}, },
{ {
field: "remark", field: "remark",
width: '20%', wpartIdth: '20%',
title: "备注", title: "备注",
unresize: true, unresize: true,
align: "center", align: "center",
edit: 'textarea', edit: 'textarea',
style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' style: 'outline: 1px solpartId #e6e6e6;outline-offset: -5px;'
}, },
], ],
@ -161,14 +161,14 @@ function initTable() {
limit: 10, limit: 10,
page: true, page: true,
done: function (res, curr, count) { done: function (res, curr, count) {
table.resize("currentTableId"); table.resize("currentTablepartId");
pageNum = tableIns.config.page.curr; pageNum = tableIns.config.page.curr;
//设置全部数据到全局变量 //设置全部数据到全局变量
quanju = res.data; quanju = res.data;
for (var i = 0; i < res.data.length; i++) { for (var i = 0; i < res.data.length; i++) {
for (var j = 0; j < huancun.length; j++) { for (var j = 0; j < huancun.length; j++) {
//数据id和要勾选的id相同时checkbox选中 //数据partId和要勾选的partId相同时checkbox选中
if (res.data[i].id === huancun[j]) { if (res.data[i].partId === huancun[j]) {
//这里才是真正的有效勾选 //这里才是真正的有效勾选
res.data[i]["LAY_CHECKED"] = 'true'; res.data[i]["LAY_CHECKED"] = 'true';
//找到对应数据改变勾选样式,呈现出选中效果 //找到对应数据改变勾选样式,呈现出选中效果
@ -179,7 +179,7 @@ function initTable() {
} }
} }
//设置全选checkbox的选中状态只有改变LAY_CHECKED的值 table.checkStatus才能抓取到选中的状态 //设置全选checkbox的选中状态只有改变LAY_CHECKED的值 table.checkStatus才能抓取到选中的状态
let checkStatus = table.checkStatus('currentTableId');//这里的lightTable是指分页中的id let checkStatus = table.checkStatus('currentTablepartId');//这里的lightTable是指分页中的partId
if (checkStatus.isAll) {//是否全选 if (checkStatus.isAll) {//是否全选
//layTableAllChoose //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"]').prop('checked', true);//data-field值默认为0如果在分页部分自定义了属性名则需要改成对应的属性名
@ -187,7 +187,7 @@ function initTable() {
} }
}, },
}); });
table.on('edit(currentTableId2)', function (obj) { table.on('edit(currentTablepartId2)', function (obj) {
var field = obj.field; // 得到修改的字段 var field = obj.field; // 得到修改的字段
var value = obj.value // 得到修改后的值 var value = obj.value // 得到修改后的值
if (field === 'ghNum') { // 本次退回量 if (field === 'ghNum') { // 本次退回量
@ -212,20 +212,20 @@ function initTable() {
} }
} }
// 显示 - 仅用于演示 // 显示 - 仅用于演示
// layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改值为:' + util.escape(value)); // layer.msg('[partId: ' + data.partId + '] ' + field + ' 字段更改值为:' + util.escape(value));
let id = obj.data.id; let partId = obj.data.partId;
updateOrAddObject(id, obj.data); updateOrAddObject(partId, obj.data);
}); });
//复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组 //复选框选中监听,将选中的partId 设置到缓存数组,或者删除缓存数组
table.on('checkbox(currentTableId2)', function (obj) { table.on('checkbox(currentTablepartId2)', function (obj) {
if (obj.checked === true) { if (obj.checked === true) {
if (obj.type === 'one' && huancun.indexOf(obj.data.id) === -1) { if (obj.type === 'one' && huancun.indexOf(obj.data.partId) === -1) {
huancun.push(obj.data.id); huancun.push(obj.data.partId);
huancunObj.push(obj.data); huancunObj.push(obj.data);
} else { } else {
for (let i = 0; i < quanju.length; i++) { for (let i = 0; i < quanju.length; i++) {
if (huancun.indexOf(quanju[i].id) === -1) { if (huancun.indexOf(quanju[i].partId) === -1) {
huancun.push(quanju[i].id); huancun.push(quanju[i].partId);
huancunObj.push(quanju[i]); huancunObj.push(quanju[i]);
} }
} }
@ -233,7 +233,7 @@ function initTable() {
} else { } else {
if (obj.type === 'one') { if (obj.type === 'one') {
for (let i = 0; i < huancun.length; i++) { for (let i = 0; i < huancun.length; i++) {
if (huancun[i] === obj.data.id) { if (huancun[i] === obj.data.partId) {
removeByValue(huancun, huancun[i]);//调用自定义的根据值移除函数 removeByValue(huancun, huancun[i]);//调用自定义的根据值移除函数
removeByValue(huancunObj, huancunObj[i]);//调用自定义的根据值移除函数 removeByValue(huancunObj, huancunObj[i]);//调用自定义的根据值移除函数
} }
@ -241,7 +241,7 @@ function initTable() {
} else { } else {
for (let i = 0; i < quanju.length; i++) { for (let i = 0; i < quanju.length; i++) {
for (let j = 0; j < huancun.length; j++) { for (let j = 0; j < huancun.length; j++) {
if (huancun[j] === quanju[i].id) { if (huancun[j] === quanju[i].partId) {
removeByValue(huancun, +huancun[j]);//调用自定义的根据值移除函数 removeByValue(huancun, +huancun[j]);//调用自定义的根据值移除函数
removeByValue(huancunObj, +huancunObj[j]);//调用自定义的根据值移除函数 removeByValue(huancunObj, +huancunObj[j]);//调用自定义的根据值移除函数
} }
@ -252,9 +252,9 @@ function initTable() {
}); });
} }
// 根据id 判断对象数组的对象是否存在 如果存在则替换,不存在则添加 // 根据partId 判断对象数组的对象是否存在 如果存在则替换,不存在则添加
function updateOrAddObject(id, newObject) { function updateOrAddObject(partId, newObject) {
const index = jjDetailArr.findIndex(obj => obj.id === id); const index = jjDetailArr.findIndex(obj => obj.partId === partId);
if (index !== -1) { if (index !== -1) {
// 如果对象存在,则替换它 // 如果对象存在,则替换它
jjDetailArr[index] = newObject; jjDetailArr[index] = newObject;
@ -274,7 +274,7 @@ function removeByValue(arr, val) {
} }
} }
for (let i = 0; i < huancunObj.length; i++) { for (let i = 0; i < huancunObj.length; i++) {
if (huancunObj[i].id == val) { if (huancunObj[i].partId == val) {
huancunObj.splice(i, 1); huancunObj.splice(i, 1);
break; break;
} }
@ -291,11 +291,11 @@ function saveData2(params) {
dataArr.push(item); dataArr.push(item);
}) })
for (let i = 0; i < huancun.length; i++) { for (let i = 0; i < huancun.length; i++) {
const id = huancun[i]; const partId = huancun[i];
for (let j = 0; j < jjDetailArr.length; j++) { for (let j = 0; j < jjDetailArr.length; j++) {
const obj = jjDetailArr[j]; const obj = jjDetailArr[j];
if (id === obj.id) { if (partId === obj.partId) {
updateOrAddObject2(id, obj); updateOrAddObject2(partId, obj);
} }
} }
} }
@ -306,8 +306,8 @@ function saveData2(params) {
closePage(1, JSON.stringify(dataArr)); closePage(1, JSON.stringify(dataArr));
}); });
// 替换对象 // 替换对象
function updateOrAddObject2(id, newObject) { function updateOrAddObject2(partId, newObject) {
const index = dataArr.findIndex(obj => obj.id === id); const index = dataArr.findIndex(obj => obj.partId === partId);
if (index !== -1) { if (index !== -1) {
// 如果对象存在,则替换它 // 如果对象存在,则替换它
dataArr[index] = newObject; dataArr[index] = newObject;
@ -328,7 +328,7 @@ function closePage(type, params) {
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
parent.layer.close(index); // 再执行关闭 parent.layer.close(index); // 再执行关闭
if (type == 1) { if (type == 1) {
window.parent.addFitDatas(params, userId); window.parent.addFitDatas(params, userpartId);
} }
} }