From 0528179eca9c096319671f5e3d1d31e534ebadf2 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Fri, 27 Sep 2024 09:25:39 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E9=94=80=E5=94=AE=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7=E6=8A=A5=E4=BB=B7=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=89=B9=E9=87=8F=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E7=89=A9=E6=96=99=E7=9A=84=E5=89=8D=E7=AB=AFjs?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=A6=82=E4=B8=8B?= =?UTF-8?q?=EF=BC=9A=201=EF=BC=9A=E4=BD=BF=E7=94=A8=E4=B8=A4=E4=B8=AASet?= =?UTF-8?q?=EF=BC=9A=E4=B8=80=E4=B8=AA=E7=94=A8=E4=BA=8E=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=9A=84=E7=89=A9=E6=96=99=E5=8F=B7=EF=BC=8C?= =?UTF-8?q?=E5=8F=A6=E4=B8=80=E4=B8=AA=E7=94=A8=E4=BA=8E=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=8D=B3=E5=B0=86=E6=8F=92=E5=85=A5=E7=9A=84=E7=89=A9=E6=96=99?= =?UTF-8?q?=E5=8F=B7=E3=80=82=202=EF=BC=9A=E5=9C=A8=E5=8F=91=E8=B5=B7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=B7=E6=B1=82=E4=B9=8B=E5=89=8D=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=EF=BC=9A=E7=A1=AE=E4=BF=9D=E7=89=A9=E6=96=99=E5=8F=B7?= =?UTF-8?q?=E6=97=A2=E4=B8=8D=E5=9C=A8=E7=8E=B0=E6=9C=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E4=B9=9F=E4=B8=8D=E5=9C=A8=E5=8D=B3=E5=B0=86?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E7=9A=84=E6=95=B0=E6=8D=AE=E4=B8=AD=E3=80=82?= =?UTF-8?q?=203=EF=BC=9A=E4=BD=BF=E7=94=A8map=E7=94=9F=E6=88=90Promise?= =?UTF-8?q?=E6=95=B0=E7=BB=84=EF=BC=9A=E8=BF=99=E6=A0=B7=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E6=AF=8F=E4=B8=AA=E9=80=89=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=89=A9=E6=96=99=E5=8F=B7=E9=83=BD=E5=8F=AA=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/system/customerQuote/add.html | 3 + .../templates/system/customerQuote/edit.html | 101 ++++++------------ 2 files changed, 38 insertions(+), 66 deletions(-) diff --git a/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html b/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html index fdce477f..9ff58600 100644 --- a/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html +++ b/ruoyi-admin/src/main/resources/templates/system/customerQuote/add.html @@ -642,6 +642,9 @@ } }); } + + + //批量插入选择的物料 function doSubmit(index, layero, uniqueId) { console.log(uniqueId); var iframeWin = window[layero.find('iframe')[0]['name']]; diff --git a/ruoyi-admin/src/main/resources/templates/system/customerQuote/edit.html b/ruoyi-admin/src/main/resources/templates/system/customerQuote/edit.html index a9fa7f8f..5cf6f49d 100644 --- a/ruoyi-admin/src/main/resources/templates/system/customerQuote/edit.html +++ b/ruoyi-admin/src/main/resources/templates/system/customerQuote/edit.html @@ -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,58 +478,23 @@ 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] }); - } - } - layer.close(index); - }).catch(function (error) { - console.error('Some requests failed:', error); - layer.close(index); - }); + newRows.forEach(function (row) { + $("#bootstrap-sub-table-quoteChild").bootstrapTable('insertRow', { index: 1, row: row }); + }); + + layer.close(index); + }) + .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 = {