2024-11-09 13:09:28 +08:00
|
|
|
|
let form, layer, idParam, objParam;
|
|
|
|
|
|
let moduleList = [];
|
2024-11-08 16:53:56 +08:00
|
|
|
|
function setParams(params) {
|
2024-11-08 20:14:10 +08:00
|
|
|
|
objParam = JSON.parse(params);
|
|
|
|
|
|
idParam = objParam.proId;
|
2024-11-08 16:53:56 +08:00
|
|
|
|
layui.use(["form", "layer"], function () {
|
|
|
|
|
|
form = layui.form;
|
|
|
|
|
|
layer = layui.layer;
|
2024-11-09 13:09:28 +08:00
|
|
|
|
// 机具名称下拉选监听事件
|
|
|
|
|
|
form.on('select(name)', function (data) {
|
|
|
|
|
|
getProDevSelected(data.value, 2);
|
|
|
|
|
|
});
|
|
|
|
|
|
// 规格下拉选监听事件
|
|
|
|
|
|
form.on('select(module)', function (data) {
|
|
|
|
|
|
let obj = findObjById(data.value);
|
|
|
|
|
|
$('.classTable tbody tr').find('td').eq(2).html(obj.unit);
|
|
|
|
|
|
$('.classTable tbody tr').find('td').eq(3).html(obj.num);
|
|
|
|
|
|
$('.classTable tbody tr').attr('name', obj.pname)
|
|
|
|
|
|
$('.classTable tbody tr').attr('type', obj.ppName)
|
|
|
|
|
|
$('.classTable tbody tr').attr('module', obj.name)
|
2024-11-08 20:14:10 +08:00
|
|
|
|
});
|
2024-11-08 16:53:56 +08:00
|
|
|
|
});
|
2024-11-09 13:09:28 +08:00
|
|
|
|
getProDevSelected('', 1);
|
|
|
|
|
|
if (objParam.jjDataArrStr) {
|
2024-11-08 16:53:56 +08:00
|
|
|
|
// 表格数据回显
|
2024-11-09 13:09:28 +08:00
|
|
|
|
let dataArr = JSON.parse(objParam.jjDataArrStr);
|
|
|
|
|
|
$.each(dataArr, function (index, item) {
|
2024-11-08 16:53:56 +08:00
|
|
|
|
let html =
|
2024-11-09 13:09:28 +08:00
|
|
|
|
"<tr class='pa' pId='" + item.pId + "' id='" + item.id + "' name='" + item.name + "' type='" + item.type + "' module='" + item.module + "'>" +
|
|
|
|
|
|
"<td>" + item.name + "</td>" +
|
|
|
|
|
|
"<td>" + item.module + "</td>" +
|
|
|
|
|
|
"<td>" + item.unit + "</td>" +
|
|
|
|
|
|
"<td>" + item.num + "</td>" +
|
|
|
|
|
|
"<td>" + item.fhNum + "</td>" +
|
|
|
|
|
|
"<td>" + item.remark + "</td>" +
|
|
|
|
|
|
"<td><a style='color:#4491d3;cursor: pointer;' onclick='delPartData(this)'>删除</a></td>" +
|
|
|
|
|
|
"</tr>";
|
|
|
|
|
|
$(".classTable2 tbody").append(html);
|
2024-11-08 16:53:56 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-09 13:09:28 +08:00
|
|
|
|
// 根据ID查找对象
|
|
|
|
|
|
function findObjById(id) {
|
|
|
|
|
|
return moduleList.find(obj => obj.id === id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-08 19:43:23 +08:00
|
|
|
|
// 获取需求计划外机具
|
2024-11-09 13:09:28 +08:00
|
|
|
|
function getProDevSelected(id, type) {
|
2024-11-08 19:43:23 +08:00
|
|
|
|
let encryptedData = {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
'pId': id,
|
|
|
|
|
|
'proId': idParam
|
2024-11-08 19:43:23 +08:00
|
|
|
|
};
|
|
|
|
|
|
let url = dataUrl + 'backstage/planOut/getProDevSelected?encryptedData=' + encodeURIComponent(JSON.stringify(encryptedData));
|
|
|
|
|
|
ajaxRequest(url, "GET", null, true, function () {
|
|
|
|
|
|
}, function (result) {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
if (result.code === 200) {
|
|
|
|
|
|
if (type === 1) {
|
|
|
|
|
|
setSelectData(result.data);
|
|
|
|
|
|
} else if (type === 2) {
|
|
|
|
|
|
moduleList = [];
|
|
|
|
|
|
moduleList = result.data;
|
|
|
|
|
|
setSelectData2(result.data);
|
2024-11-08 19:43:23 +08:00
|
|
|
|
}
|
2024-11-09 13:09:28 +08:00
|
|
|
|
}
|
2024-11-08 19:43:23 +08:00
|
|
|
|
}, function (xhr, status, error) {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
errorFn(xhr, status, error)
|
2024-11-08 19:43:23 +08:00
|
|
|
|
}, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-08 20:14:10 +08:00
|
|
|
|
// 机具下拉选赋值
|
|
|
|
|
|
function setSelectData(list) {
|
|
|
|
|
|
let html = '<option value="">请选择</option>';
|
2024-11-09 13:09:28 +08:00
|
|
|
|
if (list && list.length > 0) {
|
2024-11-08 20:14:10 +08:00
|
|
|
|
$.each(list, function (index, item) {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
html += '<option value="' + item.id + '">' + item.name + '</option>';
|
|
|
|
|
|
})
|
2024-11-08 20:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
$('#name').empty().append(html);
|
2024-11-09 13:09:28 +08:00
|
|
|
|
layui.form.render();
|
2024-11-08 20:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-09 13:09:28 +08:00
|
|
|
|
// 规格下拉选
|
2024-11-08 20:14:10 +08:00
|
|
|
|
function setSelectData2(list) {
|
|
|
|
|
|
let html = '<option value="">请选择</option>';
|
2024-11-09 13:09:28 +08:00
|
|
|
|
if (list && list.length > 0) {
|
2024-11-08 20:14:10 +08:00
|
|
|
|
$.each(list, function (index, item) {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
html += '<option value="' + item.id + '" item="' + JSON.stringify(item) + '">' + item.name + '</option>';
|
|
|
|
|
|
})
|
2024-11-08 20:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
$('#module').empty().append(html);
|
2024-11-09 13:09:28 +08:00
|
|
|
|
layui.form.render();
|
2024-11-08 20:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-08 16:53:56 +08:00
|
|
|
|
// 保存并继续添加
|
|
|
|
|
|
function addTableData() {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
// 校验添加的数据
|
|
|
|
|
|
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();
|
2024-11-08 16:53:56 +08:00
|
|
|
|
let remark = $('#remark').val();
|
2024-11-09 13:09:28 +08:00
|
|
|
|
let layerIndex = layer.confirm('<h5 style="color:red">该配件名称和规格已存在,若继续添加,则会覆盖!</h5>', { title: '操作提示' }, function () {
|
|
|
|
|
|
$(".classTable2 tbody tr").eq(trIndex).find('td').eq(4).html(fhNum);
|
2024-11-08 16:53:56 +08:00
|
|
|
|
$(".classTable2 tbody tr").eq(trIndex).find('td').eq(5).html(remark);
|
|
|
|
|
|
layer.close(layerIndex);
|
|
|
|
|
|
});
|
2024-11-09 13:09:28 +08:00
|
|
|
|
} else {
|
2024-11-08 16:53:56 +08:00
|
|
|
|
addTrData();
|
|
|
|
|
|
}
|
2024-11-09 13:09:28 +08:00
|
|
|
|
}
|
2024-11-08 16:53:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
|
|
function saveData() {
|
|
|
|
|
|
let dataArr = [];
|
|
|
|
|
|
let size = $(".pa").length;
|
2024-11-09 13:09:28 +08:00
|
|
|
|
if (size === 0) {
|
|
|
|
|
|
return layer.msg('未添加数据', { icon: 7 });
|
2024-11-08 16:53:56 +08:00
|
|
|
|
}
|
2024-11-09 13:09:28 +08:00
|
|
|
|
$(".pa").each(function (index, item) {
|
2024-11-08 16:53:56 +08:00
|
|
|
|
let obj = {};
|
2024-11-09 13:09:28 +08:00
|
|
|
|
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');
|
2024-11-08 16:53:56 +08:00
|
|
|
|
let unit = $(this).find('td').eq(2).html();
|
2024-11-09 13:09:28 +08:00
|
|
|
|
let num = $(this).find('td').eq(3).html();
|
|
|
|
|
|
let fhNum = $(this).find('td').eq(4).html();
|
2024-11-08 16:53:56 +08:00
|
|
|
|
let remark = $(this).find('td').eq(5).html();
|
2024-11-09 13:09:28 +08:00
|
|
|
|
obj.pId = pId;
|
|
|
|
|
|
obj.id = id;
|
|
|
|
|
|
obj.moduleId = id;
|
|
|
|
|
|
obj.type = type;
|
|
|
|
|
|
obj.name = name;
|
|
|
|
|
|
obj.module = module;
|
2024-11-08 16:53:56 +08:00
|
|
|
|
obj.unit = unit;
|
2024-11-09 13:09:28 +08:00
|
|
|
|
obj.num = num;
|
|
|
|
|
|
obj.fhNum = fhNum;
|
2024-11-08 16:53:56 +08:00
|
|
|
|
obj.remark = remark;
|
|
|
|
|
|
dataArr.push(obj);
|
|
|
|
|
|
})
|
2024-11-09 13:09:28 +08:00
|
|
|
|
let layerIndex = layer.confirm('<h5 style="color:red">数据即将被添加,请仔细检查数据是否有错误!</h5>', { title: '操作提示' }, function () {
|
2024-11-08 16:53:56 +08:00
|
|
|
|
layer.close(layerIndex);
|
2024-11-09 13:09:28 +08:00
|
|
|
|
closePage(1, JSON.stringify(dataArr));
|
2024-11-08 16:53:56 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addTrData() {
|
2024-11-09 13:09:28 +08:00
|
|
|
|
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 = "<tr class='pa' pId='" + pId + "' id='" + id + "' name='" + name + "' type='" + type + "' module='" + module + "'>" +
|
|
|
|
|
|
"<td>" + name + "</td>" +
|
|
|
|
|
|
"<td>" + module + "</td>" +
|
|
|
|
|
|
"<td>" + unit + "</td>" +
|
|
|
|
|
|
"<td>" + num + "</td>" +
|
|
|
|
|
|
"<td>" + fhNum + "</td>" +
|
|
|
|
|
|
"<td>" + remark + "</td>" +
|
|
|
|
|
|
"<td><a style='color:#4491d3;cursor: pointer;' onclick='delPartData(this)'>删除</a></td>" +
|
|
|
|
|
|
"</tr>";
|
|
|
|
|
|
$(".classTable2 tbody").append(html);
|
2024-11-08 16:53:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-09 13:09:28 +08:00
|
|
|
|
function delPartData(that) {
|
|
|
|
|
|
var indexMsg = layer.confirm("<h5 style='color:red'>您确定删除此条数据吗?</h5>", { btn: ['确定', '取消'] }, function () {
|
|
|
|
|
|
layer.close(indexMsg);
|
|
|
|
|
|
$(that).parent().parent().remove();
|
|
|
|
|
|
});
|
2024-11-08 16:53:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理数字
|
2024-11-09 13:09:28 +08:00
|
|
|
|
function handleNum(that, value) {
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const regex = /^(1|[1-9]\d{0,6})$/;
|
|
|
|
|
|
if (!regex.test(value)) {
|
|
|
|
|
|
layer.msg('格式不正确,最小为1,最大输入6位数,且为正整数!', { icon: 7 })
|
|
|
|
|
|
$(that).val(1);
|
|
|
|
|
|
}
|
2024-11-08 16:53:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-09 13:09:28 +08:00
|
|
|
|
function closePage(type, params) {
|
|
|
|
|
|
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
|
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
|
window.parent.addJjDatas(params);
|
|
|
|
|
|
}
|
2024-11-16 14:39:44 +08:00
|
|
|
|
parent.layer.close(index); // 再执行关闭
|
2024-11-08 16:53:56 +08:00
|
|
|
|
}
|