|
|
@ -896,58 +896,118 @@ |
|
|
|
/*业务员列表*/ |
|
|
|
//获取单号 |
|
|
|
$("#form-salesOrder-add").validate({focusCleanup: true}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//批量插入选择的物料 |
|
|
|
function doSubmit(index, layero,uniqueId){ |
|
|
|
var iframeWin = window[layero.find('iframe')[0]['name']]; |
|
|
|
var rowData = iframeWin.$('#bootstrap-select-table').bootstrapTable('getSelections'); |
|
|
|
//判断是否重复 |
|
|
|
var rows = rowData.length; |
|
|
|
var materialData = $("#bootstrap-sub-table-order").bootstrapTable('getData'); |
|
|
|
for(var j=0;j<rows;j++){ |
|
|
|
for (var i = 0;i< materialData.length;i++){ |
|
|
|
if(rowData[j].materialNo == materialData[i].materialCode){ |
|
|
|
//如果是物料料号的相同,则从rowData清除相同的料号物料 |
|
|
|
$.modal.alertError("不能选择已添加过的相同料号" + rowData[j].materialNo); |
|
|
|
rowData.splice(j,1); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var selectedRows = iframeWin.$('#bootstrap-select-table').bootstrapTable('getSelections'); |
|
|
|
|
|
|
|
if (selectedRows.length == 0){ |
|
|
|
$.modal.alertWarning("请选择至少一条物料信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
for(var i=0;i<rowData.length;i++) { |
|
|
|
$("#bootstrap-sub-table-order").bootstrapTable('insertRow', { |
|
|
|
index: 1, |
|
|
|
row: { |
|
|
|
materialId: rowData[i].id, |
|
|
|
materialCode: rowData[i].materialNo, |
|
|
|
materialName: rowData[i].materialName, |
|
|
|
materialType: rowData[i].materialType, |
|
|
|
describe: rowData[i].describe, |
|
|
|
brand: rowData[i].brand, |
|
|
|
unit: rowData[i].unit, |
|
|
|
processMethod: rowData[i].processMethod, |
|
|
|
photoUrl: rowData[i].photoUrl, |
|
|
|
warehouseDept: rowData[i].warehouseDept, |
|
|
|
countTax: $("#taxRate_add").val(), |
|
|
|
usdTax: $("#usdTax_add").val(), |
|
|
|
materialSole: 0, |
|
|
|
materialNum: "", |
|
|
|
materialNoRmb: 0.00, |
|
|
|
materialNoUsd: 0.00, |
|
|
|
materialRmb: 0.00, |
|
|
|
materialNoRmbSum: 0.00, |
|
|
|
materialRmbSum: 0.00, |
|
|
|
materialUsd: 0.00, |
|
|
|
materialUsdSum: 0.00, |
|
|
|
materialNoUsdSum: 0.00, |
|
|
|
createBy: "", |
|
|
|
createTime: "", |
|
|
|
updateBy: "", |
|
|
|
updateTime: "", |
|
|
|
remark: "", |
|
|
|
} |
|
|
|
|
|
|
|
var existingData = $("#bootstrap-sub-table-order").bootstrapTable('getData'); |
|
|
|
var materialCodesSet = new Set(); //使用Set来存储物料号 |
|
|
|
|
|
|
|
|
|
|
|
//存储所有现有的物料号 |
|
|
|
existingData.forEach(function(row){ |
|
|
|
materialCodesSet.add(row.materialCode); |
|
|
|
}); |
|
|
|
|
|
|
|
//存储所有即将插入的料号 |
|
|
|
var newMaterialCodesSet = new Set(); |
|
|
|
|
|
|
|
var promises = selectedRows.map(rowData =>{ |
|
|
|
//检查是否已经存在相同的料号 |
|
|
|
if (materialCodesSet.has(rowData.materialNo) || newMaterialCodesSet.has(rowData.materialNo)){ |
|
|
|
$.modal.alertError("不能选择已添加过的相同料号" + rowData.materialNo); |
|
|
|
return Promise.reject("Duplicate material number: " + rowData.materialNo); |
|
|
|
} |
|
|
|
|
|
|
|
//表记即将插入的物料号 |
|
|
|
newMaterialCodesSet.add(rowData.materialNo); |
|
|
|
|
|
|
|
return queryRecentQuotation(rowData.materialNo) |
|
|
|
.then(function(quotationData){ |
|
|
|
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, |
|
|
|
warehouseDept: rowData.warehouseDept, |
|
|
|
countTax: $("#taxRate_add").val(), |
|
|
|
usdTax: $("#usdTax_add").val(), |
|
|
|
materialSole: 0, |
|
|
|
recentQuotationRMB: quotationData.data.materialRmb || '', |
|
|
|
recentQuotationUSD: quotationData.data.materialUsd || '', |
|
|
|
materialNum: "", |
|
|
|
materialNoRmb: 0.00, |
|
|
|
materialNoUsd: 0.00, |
|
|
|
materialRmb: 0.00, |
|
|
|
materialNoRmbSum: 0.00, |
|
|
|
materialRmbSum: 0.00, |
|
|
|
materialUsd: 0.00, |
|
|
|
materialUsdSum: 0.00, |
|
|
|
materialNoUsdSum: 0.00, |
|
|
|
createBy: "", |
|
|
|
createTime: "", |
|
|
|
updateBy: "", |
|
|
|
updateTime: "", |
|
|
|
remark: "", |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
//使用promise.all来等待所有请求完成, 并将结果直接存入newRows |
|
|
|
Promise.all(promises) |
|
|
|
.then(function(newRows){ |
|
|
|
|
|
|
|
|
|
|
|
//批量插入新行 |
|
|
|
newRows.forEach(function(row){ |
|
|
|
$("#bootstrap-sub-table-order").bootstrapTable('insertRow', {index: 1, row: row}); |
|
|
|
}); |
|
|
|
|
|
|
|
layer.close(index); |
|
|
|
}) |
|
|
|
} |
|
|
|
layer.close(index); |
|
|
|
.catch(function(error){ |
|
|
|
console.error('Some requests failed:', error); |
|
|
|
layer.close(index); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查找最新的报价数据 |
|
|
|
function queryRecentQuotation(materialNo) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
// 使用AJAX请求从服务器获取最近的报价信息 |
|
|
|
$.ajax({ |
|
|
|
url: ctx + 'system/customerQuote/queryLatestRecentQuotation', // 假设这是你的API路径 |
|
|
|
type: 'GET', |
|
|
|
data: { materialNo: materialNo, customerCode: $("#enterpriseCode").val() }, |
|
|
|
success: function (data) { |
|
|
|
resolve(data); // 成功时解析数据 |
|
|
|
}, |
|
|
|
error: function (jqXHR, textStatus, errorThrown) { |
|
|
|
reject(new Error('查找最新报价数据失败')); // 失败时抛出错误 |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function insertRow() { |
|
|
|
if ($("#enterpriseCode").val() == null || $("#enterpriseCode").val() == '') { |
|
|
|
$.modal.alertWarning("请先选择客户"); |
|
|
|