|
@@ -390,10 +390,13 @@ export default {
|
|
|
typeNo: item.specs || '',
|
|
|
productDescription: item.pattern || '',
|
|
|
brandItem: item.pattern || '',
|
|
|
- storeInventory: item.storeInventory || '0',
|
|
|
+ // 回显数据可能无库存,先不默认写入 '0',留给后续合并方法填充
|
|
|
+ storeInventory: (item.storeInventory !== undefined && item.storeInventory !== null && item.storeInventory !== '') ? String(item.storeInventory) : undefined,
|
|
|
// 预测数量用于编辑
|
|
|
forecastQuantity: Number(item.forecastQuantity || 0)
|
|
|
}))
|
|
|
+ // 合并接口库存数据以支持回显
|
|
|
+ this.mergeEchoStoreInventory && this.mergeEchoStoreInventory().catch(() => {})
|
|
|
} catch (e) {
|
|
|
console.warn('映射回显明细失败:', e)
|
|
|
}
|
|
@@ -586,9 +589,12 @@ export default {
|
|
|
typeNo: item.specs || '',
|
|
|
productDescription: item.pattern || '',
|
|
|
brandItem: item.pattern || '',
|
|
|
- storeInventory: item.storeInventory || '0',
|
|
|
+ // 回显数据可能无库存,先不默认写入 '0',留给后续合并方法填充
|
|
|
+ storeInventory: (item.storeInventory !== undefined && item.storeInventory !== null && item.storeInventory !== '') ? String(item.storeInventory) : undefined,
|
|
|
forecastQuantity: Number(item.forecastQuantity || 0)
|
|
|
}))
|
|
|
+ // 合并接口库存数据以支持回显
|
|
|
+ this.mergeEchoStoreInventory && this.mergeEchoStoreInventory().catch(() => {})
|
|
|
} catch (e) {
|
|
|
console.warn('映射详情明细失败:', e)
|
|
|
}
|
|
@@ -1264,6 +1270,46 @@ export default {
|
|
|
this.formData.itemSpecs = ''
|
|
|
this.currentInventory = null
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合并回显行的库存数量
|
|
|
+ * @description 使用 getUserLinkGoods 接口返回的库存数据,为编辑态回显的物料行补齐 storeInventory 字段
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async mergeEchoStoreInventory() {
|
|
|
+ try {
|
|
|
+ if (!Array.isArray(this.stockTableData) || this.stockTableData.length === 0) return
|
|
|
+ const res = await getUserLinkGoods()
|
|
|
+ const payload = res && res.data && res.data.data ? res.data.data : null
|
|
|
+ const stockList = (payload && payload.pjpfStockDescList) || []
|
|
|
+ if (!Array.isArray(stockList) || stockList.length === 0) return
|
|
|
+
|
|
|
+ // 构建基于 goodsId 与 code 的索引映射
|
|
|
+ /** @type {Map<string, string|undefined>} */
|
|
|
+ const invByGoodsId = new Map()
|
|
|
+ /** @type {Map<string, string|undefined>} */
|
|
|
+ const invByCode = new Map()
|
|
|
+ stockList.forEach(s => {
|
|
|
+ const inv = (s && s.storeInventory !== undefined && s.storeInventory !== null && s.storeInventory !== '') ? String(s.storeInventory) : undefined
|
|
|
+ if (s && s.goodsId !== undefined && s.goodsId !== null) invByGoodsId.set(String(s.goodsId), inv)
|
|
|
+ if (s && s.code) invByCode.set(String(s.code), inv)
|
|
|
+ })
|
|
|
+
|
|
|
+ // 合并库存到现有表格数据(仅填充缺失的库存字段)
|
|
|
+ this.stockTableData = this.stockTableData.map(row => {
|
|
|
+ const hasInv = !(row.storeInventory === undefined || row.storeInventory === null || row.storeInventory === '')
|
|
|
+ if (hasInv) return row
|
|
|
+ const keyGoodsId = row && row.goodsId !== undefined && row.goodsId !== null ? String(row.goodsId) : ''
|
|
|
+ const keyCode = row && row.code ? String(row.code) : ''
|
|
|
+ const fromGoods = keyGoodsId ? invByGoodsId.get(keyGoodsId) : undefined
|
|
|
+ const fromCode = (!fromGoods && keyCode) ? invByCode.get(keyCode) : undefined
|
|
|
+ const value = (fromGoods !== undefined && fromGoods !== null && fromGoods !== '') ? fromGoods : ((fromCode !== undefined && fromCode !== null && fromCode !== '') ? fromCode : '0')
|
|
|
+ return { ...row, storeInventory: String(value) }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('回显库存合并失败:', e)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|