";
$(".classTable2 tbody").append(html);
});
}
}
// 根据ID查找对象
function findObjById(id) {
return moduleList.find(obj => obj.id === id);
}
// 获取需求计划外机具
function getProDevSelected(id, type) {
let encryptedData = {
'pId': id,
'proId': idParam
};
let url = dataUrl + 'backstage/planOut/getProDevSelected?encryptedData=' + encodeURIComponent(JSON.stringify(encryptedData));
ajaxRequest(url, "GET", null, true, function () {
}, function (result) {
console.log(result);
if (result.code === 200) {
if (type === 1) {
setSelectData(result.data);
} else if (type === 2) {
moduleList = [];
moduleList = result.data;
setSelectData2(result.data);
}
}
}, function (xhr, status, error) {
errorFn(xhr, status, error)
}, null);
}
// 机具下拉选赋值
function setSelectData(list) {
let html = '';
if (list && list.length > 0) {
$.each(list, function (index, item) {
html += '';
})
}
$('#name').empty().append(html);
layui.form.render();
}
// 规格下拉选
function setSelectData2(list) {
let html = '';
if (list && list.length > 0) {
$.each(list, function (index, item) {
html += '';
})
}
$('#module').empty().append(html);
layui.form.render();
}
// 保存并继续添加
function addTableData() {
// 校验添加的数据
let pId = $('#name').val();
let id = $('#module').val();
let fhNum = $('#fhNum').val();
if (!pId) {
return layer.msg('请选择机具', { icon: 7 });
}
if (!id) {
return layer.msg('请选择规格', { icon: 7 });
}
if (!fhNum) {
return layer.msg('请输入本次发货量', { icon: 7 });
}
let size = $(".pa").length;
if (size === 0) {
addTrData();
} else {
let pId = $('#name').val();
let id = $('#module').val();
let flag = false, trIndex = 0;
$(".classTable2 tbody tr").each(function (index, item) {
let trpId = $(this).attr('pId');
let trId = $(this).attr('id');
if (pId === trpId && id === trId) {
flag = true;
trIndex = index;
}
})
if (flag) {
let fhNum = $('#fhNum').val();
let remark = $('#remark').val();
let layerIndex = layer.confirm('
该配件名称和规格已存在,若继续添加,则会覆盖!
', { title: '操作提示' }, function () {
$(".classTable2 tbody tr").eq(trIndex).find('td').eq(4).html(fhNum);
$(".classTable2 tbody tr").eq(trIndex).find('td').eq(5).html(remark);
layer.close(layerIndex);
});
} else {
addTrData();
}
}
}
// 保存
function saveData() {
let dataArr = [];
let size = $(".pa").length;
if (size === 0) {
return layer.msg('未添加数据', { icon: 7 });
}
$(".pa").each(function (index, item) {
let obj = {};
let pId = $(this).attr('pId');
let id = $(this).attr('id');
let name = $(this).attr('name');
let type = $(this).attr('type');
let module = $(this).attr('module');
let unit = $(this).find('td').eq(2).html();
let num = $(this).find('td').eq(3).html();
let fhNum = $(this).find('td').eq(4).html();
let remark = $(this).find('td').eq(5).html();
obj.pId = pId;
obj.id = id;
obj.moduleId = id;
obj.type = type;
obj.name = name;
obj.module = module;
obj.unit = unit;
obj.num = num;
obj.fhNum = fhNum;
obj.remark = remark;
dataArr.push(obj);
})
let layerIndex = layer.confirm('
数据即将被添加,请仔细检查数据是否有错误!
', { title: '操作提示' }, function () {
layer.close(layerIndex);
closePage(1, JSON.stringify(dataArr));
});
}
function addTrData() {
let name = $('.classTable tbody tr').attr('name');
let type = $('.classTable tbody tr').attr('type');
let module = $('.classTable tbody tr').attr('module');
let pId = $('#name').val();
let id = $('#module').val();
let unit = $('.classTable tbody tr').find('td').eq(2).html();
let num = $('.classTable tbody tr').find('td').eq(3).html();
let fhNum = $('#fhNum').val();
let remark = $('#remark').val();
let html = "