Переглянути джерело

宝时快上-库位库满度校验

zhaohuanhuan 1 тиждень тому
батько
коміт
8420b5a208
2 змінених файлів з 85 додано та 15 видалено
  1. 14 0
      src/api/basic/index.ts
  2. 71 15
      src/views/inbound/putaway/task/index.vue

+ 14 - 0
src/api/basic/index.ts

@@ -54,6 +54,20 @@ export function getLocationTypeList(params: { warehouse: string }) {
   })
 }
 
+/** 查询库位类型库满度是否存在 */
+export function existsLocationTypeMaxQty(data: {
+  warehouse: string
+  owner: string
+  sku: string
+  location: string
+}) {
+  return request({
+    url: '/api/basic/location/resource/existsLocationTypeMaxQty',
+    method: 'post',
+    data,
+  })
+}
+
 
 
 /**

+ 71 - 15
src/views/inbound/putaway/task/index.vue

@@ -195,7 +195,7 @@ import { getWaitPutawayListNew, setPutawayNew } from '@/api/putaway/index'
 import { getListCombineSku } from '@/api/picking'
 import { barcodeToUpperCase } from '@/utils/dataType.js'
 import { getRecommendedLocation, getRecommendedLocationNew } from '@/api/haikang/index'
-import { findSysParamByKey } from '@/api/basic/index'
+import { existsLocationTypeMaxQty, findSysParamByKey } from '@/api/basic/index'
 import { getOwnerList } from '@/hooks/basic/index'
 
 const router = useRouter()
@@ -223,8 +223,35 @@ async function loadForcePublishParam() {
 // 扫描步骤:2=商品条码 3=库位 4=上架数量
 const SCAN_TYPE = { BARCODE: 2, LOCATION: 3, QUANTITY: 4 }
 
-// 从推荐库位项取编码(精准推荐接口字段为 locationId)
-const getRecommendedLocationCode = (item) => barcodeToUpperCase(item?.locationId || '')
+// 从推荐库位项取编码(精准推荐 locationId,旧接口 location)
+const getRecommendedLocationCode = (item) => barcodeToUpperCase(item?.locationId || item?.location || '')
+
+// 自定义库位(不在推荐列表内)上架前校验库位类型库满度
+const validateCustomPutawayLocation = async (locationCode) => {
+  if (isScannedLocationInRecommendedList(locationCode)) return true
+  const batchItem = barcodeActiveList.value[0]
+  if (!batchItem) return false
+  try {
+    const res = await existsLocationTypeMaxQty({
+      warehouse,
+      owner: batchItem.owner,
+      sku: batchItem.sku,
+      location: locationCode,
+    })
+    if (res?.data === true) {
+      showNotify({ type: 'warning', duration: 3000, message: '请按系统推荐库位上架' })
+      return false
+    }
+    if (res?.data === false) {
+      return true
+    }
+    return false
+  } catch (err) {
+    console.error(err)
+    showNotify({ type: 'danger', duration: 3000, message: err.message || '库位校验失败,请重试' })
+    return false
+  }
+}
 
 // 是否需要校验扫描库位在推荐列表内(仅精准推荐开启且未禁止强制上架时校验)
 const shouldForceLocationMatch = () => {
@@ -236,12 +263,16 @@ const shouldForceLocationMatch = () => {
 }
 
 // 判断扫描库位是否在推荐列表内
-const isLocationInRecommendedList = (locationCode) => {
-  if (!shouldForceLocationMatch()) return true
+const isScannedLocationInRecommendedList = (locationCode) => {
   const scanned = barcodeToUpperCase(locationCode)
   return locationList.value.some(item => getRecommendedLocationCode(item) === scanned)
 }
 
+const isLocationInRecommendedList = (locationCode) => {
+  if (!shouldForceLocationMatch()) return true
+  return isScannedLocationInRecommendedList(locationCode)
+}
+
 // 从已排除库位记录中提取 locationId 列表(换一换时使用,INVENTORY 类型不排除)
 const getExcludedLocationIds = (list) => {
   const ids = [...new Set(list.map(loc => {
@@ -614,18 +645,32 @@ const _handlerScan = (code) => {
       _handlePutawayCombineProduct(code)
     }
   } else if (scanType.value === SCAN_TYPE.LOCATION) {
-    const scannedLocation = barcodeToUpperCase(code)
-    if (!isLocationInRecommendedList(scannedLocation)) {
-      showNotify({ type: 'warning', duration: 3000, message: `扫描库位${scannedLocation}与推荐库位不一致,请确认` })
+    _handleLocationScan(code)
+  }
+}
+
+const _handleLocationScan = async (code) => {
+  const scannedLocation = barcodeToUpperCase(code)
+  if (!isLocationInRecommendedList(scannedLocation)) {
+    showNotify({ type: 'warning', duration: 3000, message: `扫描库位${scannedLocation}与推荐库位不一致,请确认` })
+    searchLocation.value = ''
+    scanError()
+    return
+  }
+  if (!isScannedLocationInRecommendedList(scannedLocation)) {
+    showLoading()
+    const valid = await validateCustomPutawayLocation(scannedLocation)
+    closeLoading()
+    if (!valid) {
       searchLocation.value = ''
       scanError()
       return
     }
-    searchLocation.value = scannedLocation
-    scanType.value = SCAN_TYPE.QUANTITY
-    if (!searchCount.value) searchCount.value = 1
-    scanSuccess()
   }
+  searchLocation.value = scannedLocation
+  scanType.value = SCAN_TYPE.QUANTITY
+  if (!searchCount.value) searchCount.value = 1
+  scanSuccess()
 }
 // 获取推荐库位(根据 systemForcePublishEnabled 分流新旧接口)
 const _getRecommendedLocation = async (item, options = {}) => {
@@ -691,7 +736,7 @@ const doChangeLocationWithType = async (item) => {
 const numberRef = ref(null)
 const locationRef = ref(null)
 // 完成收货校验
-const isCheck = () => {
+const isCheck = async () => {
   if (searchLocation.value == '') {
     locationRef.value?.focus()
     scanError()
@@ -710,6 +755,17 @@ const isCheck = () => {
     showToast({ duration: 3000, message: '库位与推荐库位不一致,无法上架' })
     return false
   }
+  if (!isScannedLocationInRecommendedList(searchLocation.value)) {
+    showLoading()
+    const valid = await validateCustomPutawayLocation(searchLocation.value)
+    closeLoading()
+    if (!valid) {
+      searchLocation.value = ''
+      locationRef.value?.focus()
+      scanError()
+      return false
+    }
+  }
   if (searchCount.value == '') {
     numberRef.value?.focus()
     scanError()
@@ -726,8 +782,8 @@ const isCheck = () => {
   return true
 }
 // 上架
-const onConfirm = () => {
-  if (isCheck()) {
+const onConfirm = async () => {
+  if (await isCheck()) {
     const quantity = searchCount.value
     const asnDoShelfList = []
     const noAsnDoShelfList=[]