Kaynağa Gözat

手持-上架-数量扣除优先有单据数据-无单据优先同批次同业务号最小的数量

zhaohuanhuan 2 ay önce
ebeveyn
işleme
7a4e95edc1
1 değiştirilmiş dosya ile 30 ekleme ve 1 silme
  1. 30 1
      src/views/inbound/putaway/task/index.vue

+ 30 - 1
src/views/inbound/putaway/task/index.vue

@@ -278,10 +278,12 @@ const setBarcode = (code, type) => {
       const asnToShelfList = res.data.asnToShelfList.map(item => {
         return {
           ...item,
+          totalQuantity: 0,
           type:'asn'
         }
       })
-      const noAsnToShelfList = res.data.noAsnToShelfList.map(item => {
+      // 先映射数据
+      const noAsnToShelfListTemp = res.data.noAsnToShelfList.map(item => {
         return {
           ...item,
           lotNumber: item.lotNum,
@@ -295,6 +297,27 @@ const setBarcode = (code, type) => {
           type:'noAsn'
         }
       })
+      // 按照 lotNumber 和 businessNo 分组并累加 quantity
+      const groupedMap = {}
+      noAsnToShelfListTemp.forEach(item => {
+        const key = `${item.lotNumber}_${item.businessNo || ''}`
+        if (!groupedMap[key]) {
+          groupedMap[key] = {
+            items: [],
+            totalQuantity: 0
+          }
+        }
+        groupedMap[key].items.push(item)
+        groupedMap[key].totalQuantity += Number(item.quantity) || 0
+      })
+      // 更新每项的 totalQuantity 为累加后的值
+      const noAsnToShelfList = noAsnToShelfListTemp.map(item => {
+        const key = `${item.lotNumber}_${item.businessNo || ''}`
+        return {
+          ...item,
+          totalQuantity: groupedMap[key].totalQuantity
+        }
+      })
       dataList.value = [...asnToShelfList,...noAsnToShelfList]
       dataMap.value = groupedData(dataList.value)
       containerNo.value = code
@@ -450,6 +473,12 @@ const onConfirm = () => {
     const asnDoShelfList = []
     const noAsnDoShelfList=[]
     const list = structuredClone(barcodeActiveList.value) // 深拷贝,保证原始数据不被修改
+    // 按照 totalQuantity 从小到大排序,优先扣除最小的
+    list.sort((a, b) => {
+      const totalQuantityA = Number(a.totalQuantity || a.quantity || 0)
+      const totalQuantityB = Number(b.totalQuantity || b.quantity || 0)
+      return totalQuantityA - totalQuantityB
+    })
     let remainingQuantity = quantity
     for (let i = 0; i < list.length && remainingQuantity > 0; i++) {
       const { taskNo, taskLineNo, warehouse, quantity } = list[i]