|
|
@@ -328,11 +328,27 @@ const toLocationItem = (item) => ({
|
|
|
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 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 分流新旧接口)
|
|
|
@@ -343,8 +359,7 @@ const _getRecommendedLocation = async (item) => {
|
|
|
const params = { warehouse, lotNum: lotNumber, owner, zoneGroup: 'WH01-02' }
|
|
|
const res = await getRecommendedLocation(params)
|
|
|
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)
|
|
|
if (!result) {
|
|
|
result = eaItems.find(loc => loc.quantity === null)
|
|
|
@@ -373,6 +388,17 @@ const _getRecommendedLocation = async (item) => {
|
|
|
const loc = res.data?.locationList || []
|
|
|
locationList.value = loc
|
|
|
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()
|
|
|
const msg = `${searchBarcode.value}:库区内无商品库存,请调空料箱进行入库`
|
|
|
tips.value = msg
|
|
|
@@ -381,7 +407,7 @@ const _getRecommendedLocation = async (item) => {
|
|
|
scanType.value = 2
|
|
|
return
|
|
|
}
|
|
|
- setLocation(pickRecommendedLocations(loc))
|
|
|
+ setLocation(picked)
|
|
|
} catch (err) {
|
|
|
locationList.value = []
|
|
|
scanError()
|