Browse Source

海柔快上-选中库位逻辑调整

zhaohuanhuan 5 days ago
parent
commit
2dadc89653
1 changed files with 32 additions and 6 deletions
  1. 32 6
      src/views/robot/putaway/index.vue

+ 32 - 6
src/views/robot/putaway/index.vue

@@ -328,11 +328,27 @@ const toLocationItem = (item) => ({
   quantity: item.qty ?? item.quantity ?? 0,
   quantity: item.qty ?? item.quantity ?? 0,
 })
 })
 
 
-// 优先取所有 FORCE 库位,无 FORCE 则取第一个
+const ALLOWED_LOCATION_TYPES = ['EA', 'PC', 'GY', 'TH', 'CS']
+
+const getLocType = (item) => item.locationUsage || item.type
+const getLocQty = (item) => item.qty ?? item.quantity
+
+// 优先取所有 FORCE 库位;无 FORCE 则在允许类型中按库存升序取最少且大于 0 的库位
 const pickRecommendedLocations = (loc) => {
 const pickRecommendedLocations = (loc) => {
   const forceLocs = loc.filter(item => item.displayType === 'FORCE')
   const forceLocs = loc.filter(item => item.displayType === 'FORCE')
-  const source = forceLocs.length > 0 ? forceLocs : [loc[0]]
-  return source.map(toLocationItem)
+  if (forceLocs.length > 0) {
+    return forceLocs.map(toLocationItem)
+  }
+
+  const minStockLoc = loc
+    .filter(item => ALLOWED_LOCATION_TYPES.includes(getLocType(item)))
+    .filter(item => {
+      const qty = getLocQty(item)
+      return qty != null && Number(qty) > 0
+    })
+    .sort((a, b) => Number(getLocQty(a)) - Number(getLocQty(b)))[0]
+
+  return minStockLoc ? [toLocationItem(minStockLoc)] : null
 }
 }
 
 
 // 获取推荐库位(根据 systemForcePublishEnabled 分流新旧接口)
 // 获取推荐库位(根据 systemForcePublishEnabled 分流新旧接口)
@@ -343,8 +359,7 @@ const _getRecommendedLocation = async (item) => {
       const params = { warehouse, lotNum: lotNumber, owner, zoneGroup: 'WH01-02' }
       const params = { warehouse, lotNum: lotNumber, owner, zoneGroup: 'WH01-02' }
       const res = await getRecommendedLocation(params)
       const res = await getRecommendedLocation(params)
       locationList.value = res.data || []
       locationList.value = res.data || []
-      const allowedLocationTypes = ['EA', 'PC', 'GY', 'TH', 'CS']
-      const eaItems = locationList.value.filter(loc => allowedLocationTypes.includes(loc.type))
+      const eaItems = locationList.value.filter(loc => ALLOWED_LOCATION_TYPES.includes(loc.type))
       let result = eaItems.find(loc => loc.quantity !== null && loc.quantity < 1000)
       let result = eaItems.find(loc => loc.quantity !== null && loc.quantity < 1000)
       if (!result) {
       if (!result) {
         result = eaItems.find(loc => loc.quantity === null)
         result = eaItems.find(loc => loc.quantity === null)
@@ -373,6 +388,17 @@ const _getRecommendedLocation = async (item) => {
     const loc = res.data?.locationList || []
     const loc = res.data?.locationList || []
     locationList.value = loc
     locationList.value = loc
     if (loc.length === 0) {
     if (loc.length === 0) {
+      scanError()
+       searchBarcode.value = ''
+      const msg = `${searchBarcode.value}:库区内无商品库存,请调空料箱进行入库`
+      tips.value = msg
+      showNotify({ type: 'danger', duration: 3000, message: msg })
+    
+      scanType.value = 2
+      return
+    }
+    const picked = pickRecommendedLocations(loc)
+    if (!picked) {
       scanError()
       scanError()
       const msg = `${searchBarcode.value}:库区内无商品库存,请调空料箱进行入库`
       const msg = `${searchBarcode.value}:库区内无商品库存,请调空料箱进行入库`
       tips.value = msg
       tips.value = msg
@@ -381,7 +407,7 @@ const _getRecommendedLocation = async (item) => {
       scanType.value = 2
       scanType.value = 2
       return
       return
     }
     }
-    setLocation(pickRecommendedLocations(loc))
+    setLocation(picked)
   } catch (err) {
   } catch (err) {
     locationList.value = []
     locationList.value = []
     scanError()
     scanError()