框架合同测试问题修复
This commit is contained in:
parent
b17e2b03eb
commit
6c247e18d8
|
|
@ -398,9 +398,80 @@ $(document).on("click", ".file-iteme .handle", function (event) {
|
|||
});
|
||||
|
||||
function saveData2() {
|
||||
renderAllCjTables();
|
||||
$('#formSubmit').trigger('click')
|
||||
}
|
||||
|
||||
function renderAllCjTables() {
|
||||
// 如果已经在厂家信息tab,直接返回(表格已渲染)
|
||||
let currentTab = $('.layui-tab-title .layui-this').attr('value');
|
||||
if (currentTab === '2') return;
|
||||
|
||||
// 收集所有选中的厂家
|
||||
checkedSupplierList.splice(0, checkedSupplierList.length);
|
||||
$('select[name="supplier"]').each(function (index, item) {
|
||||
let id = $(this).find('option:checked').val();
|
||||
let name = $(this).find('option:checked').text();
|
||||
if (id && name) {
|
||||
let obj = { id: id, name: name };
|
||||
checkedSupplierList.push(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// 如果有选中的厂家,渲染表格到隐藏容器中
|
||||
if (checkedSupplierList.length > 0) {
|
||||
let cent = '';
|
||||
$.each(checkedSupplierList, function (index, item) {
|
||||
cent += '<div class="layui-tab-item" cjId="' + item.id + '">' +
|
||||
addCjTableData(item.id, 1) + '</div>';
|
||||
});
|
||||
|
||||
// 渲染到隐藏的临时容器中
|
||||
let $tempContainer = $('#layui-tab-content');
|
||||
if ($tempContainer.length === 0) {
|
||||
$tempContainer = $('<div id="layui-tab-content-temp" style="display:none;"></div>');
|
||||
$('body').append($tempContainer);
|
||||
}
|
||||
$tempContainer.html(cent);
|
||||
|
||||
// 同步数据到cjDataArr
|
||||
syncCjDataFromTemp();
|
||||
}
|
||||
}
|
||||
|
||||
function syncCjDataFromTemp() {
|
||||
cjDataArr.splice(0, cjDataArr.length);
|
||||
$('#layui-tab-content-temp .layui-tab-item').each(function() {
|
||||
let cjId = $(this).attr('cjId');
|
||||
let obj = {}, list = [];
|
||||
obj.cjId = cjId;
|
||||
|
||||
$(this).find('.cjTable tbody tr').each(function() {
|
||||
let id = $(this).attr('id');
|
||||
let dataId = $(this).attr('dataId');
|
||||
let num = $(this).find('input[name="num"]').val();
|
||||
let price = $(this).find('input[name="price"]').val();
|
||||
let remarks = $(this).find('input[name="remarks"]').val();
|
||||
|
||||
if (id) {
|
||||
let obj2 = {
|
||||
id: id,
|
||||
dataId: dataId,
|
||||
num: num || 0,
|
||||
price: price || 0,
|
||||
remarks: remarks || ''
|
||||
};
|
||||
list.push(obj2);
|
||||
}
|
||||
});
|
||||
|
||||
if (list.length > 0) {
|
||||
obj.list = list;
|
||||
cjDataArr.push(obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 提交
|
||||
function submitApply(data) {
|
||||
console.log(data.field);
|
||||
|
|
@ -938,48 +1009,62 @@ function addCjTableData(cjId, isUse) {
|
|||
function setCjTableData() {
|
||||
let list = cjDataArr.filter(item => {
|
||||
return item.cjId === cjId;
|
||||
})
|
||||
});
|
||||
let list2 = cjDataArr2.filter(item => {
|
||||
return item.cjId === cjId;
|
||||
})
|
||||
});
|
||||
let html = '';
|
||||
if (jjDataArr && jjDataArr.length > 0) {
|
||||
for (var i = 0; i < jjDataArr.length; i++) {
|
||||
var l = jjDataArr[i];
|
||||
if (list.length === 0 || isUse) {
|
||||
l.num = 0, l.price = 0, l.remarks = '', l.dataId = '-1';
|
||||
} else {
|
||||
|
||||
// 修复:优先从已有数据中获取,而不是重置
|
||||
let existingData = null;
|
||||
|
||||
// 1. 先从cjDataArr中查找已有数据
|
||||
if (list.length > 0) {
|
||||
let dataList = list[0].list;
|
||||
if (dataList.length > 0) {
|
||||
$.each(dataList, function (index, item) {
|
||||
if (item.id === l.id) {
|
||||
l.num = item.num, l.price = item.price, l.remarks = item.remarks, l.dataId = item.dataId ? item.dataId : '-1';
|
||||
return false;
|
||||
existingData = item;
|
||||
return false; // 找到数据就退出循环
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
let supDataId = null;
|
||||
$('select[name="supplier"]').each(function(){
|
||||
if($(this).val() === cjId){
|
||||
supDataId = $(this).attr('dataId');
|
||||
}
|
||||
})
|
||||
// 二次赋值
|
||||
if(list2.length > 0 && supDataId && supDataId!=='undefined'){
|
||||
|
||||
// 2. 如果cjDataArr中没有,再从cjDataArr2中查找(用于编辑时的数据)
|
||||
if (!existingData && list2.length > 0) {
|
||||
let dataList = list2[0].list;
|
||||
if (dataList.length > 0) {
|
||||
$.each(dataList, function (index, item) {
|
||||
if (item.id === l.id) {
|
||||
l.dataId = item.dataId ? item.dataId : '-1';
|
||||
existingData = item;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 根据现有数据设置值
|
||||
if (existingData) {
|
||||
l.num = existingData.num;
|
||||
l.price = existingData.price;
|
||||
l.remarks = existingData.remarks;
|
||||
l.dataId = existingData.dataId ? existingData.dataId : '-1';
|
||||
} else if (list.length === 0 || isUse) {
|
||||
// 4. 只有完全没数据时才使用默认值
|
||||
l.num = 0;
|
||||
l.price = 0;
|
||||
l.remarks = '';
|
||||
l.dataId = '-1';
|
||||
}
|
||||
|
||||
if (!l.dataId) {
|
||||
l.dataId = '-1';
|
||||
}
|
||||
|
||||
html += "<tr id='" + l.id + "' type='" + l.type + "' dataId='" + l.dataId + "'>";
|
||||
html += "<td style='vertical-align:middle;' class='center hidden-480'>"
|
||||
+ (i + 1) + "</td>";
|
||||
|
|
|
|||
Loading…
Reference in New Issue