|
|
@@ -2040,6 +2040,19 @@
|
|
|
let comitDatasource = copyObj(this.form.datasource);
|
|
|
if (comitDatasource.length === 0) return [];
|
|
|
comitDatasource.forEach((v) => {
|
|
|
+ // 计量数量在后端是非空字段,库存台账多选等入口只带回销售数量,
|
|
|
+ // 未触发数量换算时会留空,提交前统一用销售数量兜底,避免提交报 SQL 错误
|
|
|
+ const saleCount = v[this.countObj.countKey];
|
|
|
+ if (
|
|
|
+ (v.totalCount === undefined ||
|
|
|
+ v.totalCount === null ||
|
|
|
+ v.totalCount === '') &&
|
|
|
+ saleCount !== undefined &&
|
|
|
+ saleCount !== null &&
|
|
|
+ saleCount !== ''
|
|
|
+ ) {
|
|
|
+ v.totalCount = saleCount;
|
|
|
+ }
|
|
|
if (v.guaranteePeriodUnitCode) {
|
|
|
v.guaranteePeriodUnitName = this.getDictValue(
|
|
|
'保质期单位',
|
|
|
@@ -2589,6 +2602,8 @@
|
|
|
},
|
|
|
async replaceTable(obj, idx) {
|
|
|
console.log('replaceTable', obj, idx);
|
|
|
+ // 先按物品ID去重并并行查询商品信息,避免逐行串行请求,物品较多时明显加快回显
|
|
|
+ const goodsMap = await this.loadGoodsByCategoryIds(obj);
|
|
|
for (let index = 0; index < obj.length; index++) {
|
|
|
const item = obj[index];
|
|
|
let i = idx == -1 ? index : idx;
|
|
|
@@ -2639,7 +2654,7 @@
|
|
|
? this.defTaxRate
|
|
|
: undefined
|
|
|
);
|
|
|
- let goodsData = await getGoodsByCategoryId(item.productId);
|
|
|
+ let goodsData = goodsMap.get(item.productId) || [];
|
|
|
goodsData = goodsData.filter((item) => item.approvalStatus == 2);
|
|
|
if (goodsData?.length) {
|
|
|
let goodsPriceList = goodsData[0]?.goodsPriceList[0];
|
|
|
@@ -2716,10 +2731,44 @@
|
|
|
}
|
|
|
}
|
|
|
// console.log(this.form.datasource);
|
|
|
+ // 计量数量为后端非空字段:只补齐留空的行,避免覆盖已按计量单位换算好的数据
|
|
|
+ this.form.datasource.forEach((item) => {
|
|
|
+ const count = item[this.countObj.countKey];
|
|
|
+ if (
|
|
|
+ (item.totalCount === undefined ||
|
|
|
+ item.totalCount === null ||
|
|
|
+ item.totalCount === '') &&
|
|
|
+ count !== undefined &&
|
|
|
+ count !== null &&
|
|
|
+ count !== ''
|
|
|
+ ) {
|
|
|
+ this.$set(item, 'totalCount', count);
|
|
|
+ }
|
|
|
+ });
|
|
|
if (this.showSaleCount) {
|
|
|
this.changeCount();
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 批量查询物品对应的商品信息。
|
|
|
+ * 按物品ID去重后并行请求,替代逐行 await 的串行查询,
|
|
|
+ * 同一物品选中多行(多批次)时只请求一次。
|
|
|
+ */
|
|
|
+ async loadGoodsByCategoryIds(list) {
|
|
|
+ const goodsMap = new Map();
|
|
|
+ const productIds = [
|
|
|
+ ...new Set(
|
|
|
+ (list || []).map((item) => item.productId).filter((id) => id)
|
|
|
+ )
|
|
|
+ ];
|
|
|
+ await Promise.all(
|
|
|
+ productIds.map(async (productId) => {
|
|
|
+ const goodsList = await getGoodsByCategoryId(productId);
|
|
|
+ goodsMap.set(productId, goodsList || []);
|
|
|
+ })
|
|
|
+ );
|
|
|
+ return goodsMap;
|
|
|
+ },
|
|
|
remove(index) {
|
|
|
this.form.datasource.splice(index, 1);
|
|
|
this.setSort();
|