|
|
@ -414,6 +414,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//批量插入选择的物料 |
|
|
|
function doSubmit(index, layero, uniqueId) { |
|
|
|
console.log(uniqueId); |
|
|
|
var iframeWin = window[layero.find('iframe')[0]['name']]; |
|
|
@ -425,28 +426,28 @@ |
|
|
|
} |
|
|
|
|
|
|
|
var existingData = $("#bootstrap-sub-table-quoteChild").bootstrapTable('getData'); |
|
|
|
var promises = []; |
|
|
|
var materialCodesSet = new Set(); // 使用Set来存储物料号 |
|
|
|
|
|
|
|
// 存储要插入的新行 |
|
|
|
var newRows = []; |
|
|
|
// 存储所有现有的物料号 |
|
|
|
existingData.forEach(function (row) { |
|
|
|
materialCodesSet.add(row.materialCode); |
|
|
|
}); |
|
|
|
|
|
|
|
// 遍历选中的每一行物料信息 |
|
|
|
for (var i = 0; i < selectedRows.length; i++) { |
|
|
|
var rowData = selectedRows[i]; |
|
|
|
// 存储所有即将插入的物料号 |
|
|
|
var newMaterialCodesSet = new Set(); |
|
|
|
|
|
|
|
var promises = selectedRows.map(rowData => { |
|
|
|
// 检查是否已经存在相同的物料 |
|
|
|
var isDuplicate = false; |
|
|
|
for (var j = 0; j < existingData.length; j++) { |
|
|
|
if (existingData[j].materialCode === rowData.materialNo) { |
|
|
|
isDuplicate = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
if (materialCodesSet.has(rowData.materialNo) || newMaterialCodesSet.has(rowData.materialNo)) { |
|
|
|
$.modal.alertError("不能选择已添加过的相同料号:" + rowData.materialNo); |
|
|
|
return Promise.reject("Duplicate material number: " + rowData.materialNo); |
|
|
|
} |
|
|
|
|
|
|
|
if (!isDuplicate) { |
|
|
|
// 如果不存在,则准备插入新行,并发起查询请求 |
|
|
|
promises.push(queryRecentQuotation(rowData.materialNo).then(function (quotationData) { |
|
|
|
// 将查询结果赋值给 newRows 中的相应字段 |
|
|
|
// 标记即将插入的物料号 |
|
|
|
newMaterialCodesSet.add(rowData.materialNo); |
|
|
|
|
|
|
|
return queryRecentQuotation(rowData.materialNo) |
|
|
|
.then(function (quotationData) { |
|
|
|
return { |
|
|
|
materialId: rowData.id, |
|
|
|
materialCode: rowData.materialNo, |
|
|
@ -477,55 +478,20 @@ |
|
|
|
updateTime: "", |
|
|
|
remark: "", |
|
|
|
}; |
|
|
|
}).catch(function (error) { |
|
|
|
// 返回一个默认对象以保证数据结构一致 |
|
|
|
return { |
|
|
|
materialId: rowData.id, |
|
|
|
materialCode: rowData.materialNo, |
|
|
|
materialName: rowData.materialName, |
|
|
|
materialType: rowData.materialType, |
|
|
|
describe: rowData.describe, |
|
|
|
brand: rowData.brand, |
|
|
|
unit: rowData.unit, |
|
|
|
processMethod: rowData.processMethod, |
|
|
|
photoUrl: rowData.photoUrl, |
|
|
|
countTax: '', |
|
|
|
usdTax: '', |
|
|
|
materialNum: "", |
|
|
|
materialSole: "", |
|
|
|
recentQuotationRMB: '', |
|
|
|
recentQuotationUSD: '', |
|
|
|
materialRmb: "", |
|
|
|
materialNoRmb: "", |
|
|
|
materialNoUsd: "", |
|
|
|
materialUsd: "", |
|
|
|
materialUsdSum: "", |
|
|
|
materialNoUsdSum: "", |
|
|
|
materialNoRmbSum: "", |
|
|
|
materialRmbSum: "", |
|
|
|
createBy: "", |
|
|
|
createTime: "", |
|
|
|
updateBy: "", |
|
|
|
updateTime: "", |
|
|
|
remark: "", |
|
|
|
}; |
|
|
|
})); |
|
|
|
} else { |
|
|
|
$.modal.alertError("不能选择已添加过的相同料号"); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// 使用Promise.all等待所有查询完成 |
|
|
|
Promise.all(promises).then(function (rows) { |
|
|
|
newRows = rows.filter(row => !!row); // 清除可能的null或undefined |
|
|
|
if (newRows.length > 0) { |
|
|
|
// 使用Promise.all等待所有查询完成,并将结果直接存入 newRows |
|
|
|
Promise.all(promises) |
|
|
|
.then(function (newRows) { |
|
|
|
// 批量插入新行 |
|
|
|
for (var k = 0; k < newRows.length; k++) { |
|
|
|
$("#bootstrap-sub-table-quoteChild").bootstrapTable('insertRow', { index: 1, row: newRows[k] }); |
|
|
|
} |
|
|
|
} |
|
|
|
newRows.forEach(function (row) { |
|
|
|
$("#bootstrap-sub-table-quoteChild").bootstrapTable('insertRow', { index: 1, row: row }); |
|
|
|
}); |
|
|
|
|
|
|
|
layer.close(index); |
|
|
|
}).catch(function (error) { |
|
|
|
}) |
|
|
|
.catch(function (error) { |
|
|
|
console.error('Some requests failed:', error); |
|
|
|
layer.close(index); |
|
|
|
}); |
|
|
@ -548,6 +514,9 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function insertRow() { |
|
|
|
var url = ctx + "erp/material/select"; |
|
|
|
var options = { |
|
|
|