ソースを参照

还库-增加组合商品

zhaohuanhuan 3 週間 前
コミット
2f64393e0b

+ 105 - 0
src/views/outbound/check/moveStock/components/MoveStockCombine.vue

@@ -0,0 +1,105 @@
+<template>
+  <div class="goods">
+    <van-dialog v-model:show="goodsTrueFalseBy"
+                :beforeClose="beforeClose"
+                title="组合商品还库"
+                show-cancel-button>
+      <div style="width:100%;max-height:150px;overflow:auto">
+        <div v-for="(item,index) in matchedSkuList" :key="index">
+          <van-cell center :title="item.matchedJson.barcode" :label="item.matchedJson.skuName">
+            <template #value>
+              <div>{{ item.matchedJson.quantity }}件/套</div>
+              <div class="goods-tips">可还:{{ item.expectedQuantity || 0 }}件 </div>
+            </template>
+          </van-cell>
+          <div class="goods-lot">生产:{{ item.productionDate || '--' }}, 失效:{{ item.expirationDate || '--' }}</div>
+        </div>
+      </div>
+      <div class="goods-number">可还套数:{{ maxCount }}</div>
+      <van-field label="还库套数" type="number" class="code-input" v-model="count" ref="countRef" placeholder="还库套数" autocomplete="off" />
+    </van-dialog>
+  </div>
+</template>
+<script setup>
+/** 还库-组合商品弹框 */
+import { computed, ref } from 'vue'
+import { showToast } from 'vant'
+const goodsTrueFalseBy = ref(false)
+const countRef = ref(null)
+const count = ref('')
+const props = defineProps({
+  matchedSku: { type: Array, default: () => [] }
+})
+const matchedSkuList = computed(() => props.matchedSku)
+const maxCount = computed(() => {
+  const min = Math.min(
+    ...props.matchedSku.map((item) => (item.expectedQuantity || 0) / (item.matchedJson?.quantity || 1))
+  )
+  return Number.isFinite(min) ? Math.floor(min) : 0
+})
+const show = () => {
+  count.value = ''
+  goodsTrueFalseBy.value = true
+  setTimeout(() => {
+    countRef.value?.focus()
+  }, 200)
+}
+const dataResult = (data) =>
+  data.map((item) => {
+    const { matchedJson, ...rest } = item
+    return { ...rest, quantity: matchedJson.quantity * Number(count.value) }
+  })
+const emit = defineEmits(['setCombine', 'cancel'])
+const beforeClose = (action) =>
+  new Promise((resolve) => {
+    if (action === 'confirm') {
+      if (count.value == '') {
+        showToast('请输入还库套数')
+        return resolve(false)
+      }
+      if (Number(count.value) <= 0) {
+        showToast('请输入正确还库套数')
+        return resolve(false)
+      }
+      if (Number(count.value) > maxCount.value) {
+        showToast({ duration: 3000, message: '还库套数不能大于可还套数' })
+        return resolve(false)
+      }
+      const dataList = dataResult(matchedSkuList.value)
+      emit('setCombine', { dataList, count: Number(count.value) })
+    } else {
+      emit('cancel')
+    }
+    resolve(true)
+  })
+defineExpose({ show })
+</script>
+<style scoped lang="sass">
+.goods
+  .code-input
+    font-size: 16px
+    font-weight: bold
+    border-bottom: 2px solid #0077ff
+  :deep(.van-cell--center)
+    padding: 5px 20px
+  :deep(.van-cell__title)
+    text-align: left !important
+  :deep(.van-cell__value)
+    width: 40% !important
+    flex: 0 0 40% !important
+    color: #000
+  .goods-number
+    text-align: left
+    font-size: 16px
+    padding-left: 20px
+    margin-top: 5px
+  .goods-tips
+    font-size: 12px
+    text-align: right
+    color: #333
+  .goods-lot
+    font-size: 12px
+    color: #666
+    margin-left: 20px
+    text-align: left
+</style>

+ 125 - 32
src/views/outbound/check/moveStock/index.vue

@@ -6,16 +6,15 @@
       fixed
       placeholder
       @click-left="goBack"
+      @click-right="refresh"
     >
       <template #left>
         <van-icon name="arrow-left" size="25" />
         <div  style="color: #fff">返回</div>
       </template>
-<!--      <template #right>-->
-<!--        <div class="nav-right" @click="onClickRight">-->
-<!--          <van-icon name="list-switch" size="25" />-->
-<!--        </div>-->
-<!--      </template>-->
+      <template #right>
+        <div style="color: #fff">刷新<van-icon name="replay" /></div>
+      </template>
     </van-nav-bar>
     <div class="move-stock">
       <div class="code">
@@ -32,6 +31,8 @@
             v-model="searchBarcode"
             placeholder="请扫描商品条码"
             @search="_handlerScan(searchBarcode)"
+            @input="onBarcodeChange"
+            @clear="onBarcodeClear"
             label="商品条码:"
             left-icon=""
             :class="[scanType===2?'search-input-barcode':'','van-hairline--bottom']"
@@ -124,6 +125,8 @@
     />
     <!-- 条码输入组件 -->
     <input-barcode :back="back" @setBarcode="setBarcode" ref="inputBarcodeRef" />
+    <!-- 组合商品还库 -->
+    <move-stock-combine ref="moveStockCombineRef" :matched-sku="combineMatchedSku" @set-combine="setCombineMoveStock" @cancel="onCombineCancel" />
     <van-dialog v-model:show="moveStockTrueFalseBy"
                 :beforeClose="beforeClose"
                 :title="'商品条码:'+ model.sku +',还库:'+location" show-cancel-button  >
@@ -171,17 +174,20 @@
 </template>
 
 <script setup>
-import { onMounted, onUnmounted, ref, computed } from 'vue'
-import { useRouter } from 'vue-router'
-import { useStore } from '@/store/modules/user'
-import { androidFocus, getHeader, goBack, scanError, scanSuccess } from '@/utils/android'
-import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
-import { getInventory, getInventoryList, movementReturn } from '@/api/check/index'
+import {computed, onMounted, onUnmounted, ref} from 'vue'
+import {useRouter} from 'vue-router'
+import {useStore} from '@/store/modules/user'
+import {androidFocus, getHeader, goBack, scanError, scanSuccess} from '@/utils/android'
+import {closeListener, openListener, scanInit} from '@/utils/keydownListener'
+import {getInventory, getInventoryList, movementReturn} from '@/api/check/index'
 import InputBarcode from '@/views/outbound/picking/components/InputBarcode.vue'
-import { closeLoading, showLoading } from '@/utils/loading'
+import {closeLoading, showLoading} from '@/utils/loading'
 import nodataUrl from '@/assets/nodata.png'
-import { showNotify, showToast } from 'vant'
-import { barcodeToUpperCase } from '@/utils/dataType.js'
+import {showNotify, showToast} from 'vant'
+import {barcodeToUpperCase} from '@/utils/dataType.js'
+import {getListCombineSku} from '@/api/picking'
+import MoveStockCombine from './components/MoveStockCombine.vue'
+
 const router = useRouter()
 const store = useStore()
 try {
@@ -193,7 +199,7 @@ try {
 const warehouse = store.warehouse
 const pattern=/^[1-9]\d*$/
 // 容器号和扫描类型的状态
-const containerNo = ref('')
+const containerNo = ref('FJ-WH01-1')
 //输入框组件类型
 const inputBarcodeType = ref('')
 //扫描类型
@@ -207,12 +213,17 @@ const totalList=ref([])
 const searchRef=ref(null)
 //扫描条码
 const searchBarcode=ref('')
+const oldSearchBarcode=ref('')
 //扫描库位
 const location=ref('')
 //
 const model=ref({})
 const countRef=ref(null)
 const back=ref(true)
+// 组合商品还库
+const moveStockCombineRef = ref(null)
+const combineData = ref(null)
+const combineMatchedSku = ref([])
 // 页面初始化
 onMounted(() => {
   openListener()
@@ -238,7 +249,8 @@ const setBarcode = (code) => {
   scanType.value = 2
   containerNo.value = code
   searchBarcode.value=''
-  moveList.value=''
+  moveList.value=[]
+  combineData.value=null
   location.value=''
   // if(searchBarcode.value){
   //   _getInventoryList(searchBarcode.value)
@@ -251,6 +263,23 @@ const _setContainerNo=()=>{
   inputBarcodeRef.value?.show('', '请扫描反拣容器')
 }
 
+// 商品条码调整时,清空还库推荐、库存列表、还库库位
+const onBarcodeChange = () => {
+  if (searchBarcode.value === '' || (oldSearchBarcode.value && oldSearchBarcode.value.length !== searchBarcode.value.length)) {
+    moveList.value = []
+    totalList.value = []
+    location.value = ''
+    combineData.value = null
+  }
+}
+const onBarcodeClear = () => {
+  moveList.value = []
+  totalList.value = []
+  location.value = ''
+  combineData.value = null
+  oldSearchBarcode.value = ''
+}
+
 // 扫描条码监听
 const _handlerScan = (code) => {
   console.log(code)
@@ -266,8 +295,35 @@ const _handlerScan = (code) => {
   }
 }
 
+// 商品条码查询为空时,查询组合商品列表
+const _handleCombineProduct = async (code) => {
+  try {
+    showLoading()
+    const res = await getListCombineSku({ combineSku: barcodeToUpperCase(code), workEnvironment: 'movement' })
+    closeLoading()
+    const _err = (msg) => {
+      scanError()
+      searchBarcode.value = ''
+      showNotify({ type: 'danger', duration: 5000, message: msg })
+    }
+    if (!res.data?.length) return _err(`条码:${code},未找到可还库库存,请检查条码!`)
+    if (res.data.length > 1) return _err('组合商品不支持多商品')
+    const innerBarcode = res.data[0].barcode
+    combineData.value = res.data[0]
+    searchBarcode.value = code
+    oldSearchBarcode.value = code
+    _getInventoryList(innerBarcode, true)
+    scanSuccess()
+  } catch (err) {
+    closeLoading()
+    scanError()
+    searchBarcode.value = ''
+    showNotify({ type: 'danger', duration: 5000, message: `条码查询失败,请检查条码!` })
+  }
+}
+
 // 获取库存数据
-const _getInventoryList = async (barcode) => {
+const _getInventoryList = async (barcode, fromCombineQuery = false) => {
   const data = { warehouse, location: containerNo.value, barcode }
   try {
     showLoading()
@@ -275,25 +331,43 @@ const _getInventoryList = async (barcode) => {
     closeLoading()
     moveList.value = res.data
     if (res.data.length === 0) {
-      scanError()
-      searchBarcode.value = ''
-      showNotify({ duration: 5000, message: `条码:${barcode},未找到可还库库存,请检查条码!` })
+      _handleCombineProduct(barcode)
       return
     }
+    // 仅当直接扫描普通条码命中时清除组合标记;从组合商品内件查询来时保留
+    if (!fromCombineQuery) combineData.value = null
     scanSuccess()
-    searchBarcode.value= res.data[0].sku
-    const params={ warehouse, barcode,locationRegexp:'^(?!STAGE_|SORTATION_|REVERSEPICK_|FJ-|TRANSFER_).*$',queryLocationInfo:true }
-    if(barcode==='') return
-    getInventory(params).then(res=>{
-      totalList.value=res.data
+    if (!fromCombineQuery) {
+      searchBarcode.value = res.data[0].sku
+      oldSearchBarcode.value = res.data[0].sku
+    }
+    const params = { warehouse, barcode, locationRegexp: '^(?!STAGE_|SORTATION_|REVERSEPICK_|FJ-|TRANSFER_).*$', queryLocationInfo: true }
+    if (barcode === '') return
+    getInventory(params).then(res => {
+      totalList.value = res.data
     })
-    scanType.value=3
+    scanType.value = 3
   } catch (err) {
     closeLoading()
     console.error(err)
   }
 }
 
+// 刷新
+const refresh = () => {
+  moveList.value = []
+  totalList.value = []
+  location.value = ''
+  combineData.value = null
+  scanType.value = 2
+  if (containerNo.value && searchBarcode.value) {
+    oldSearchBarcode.value = ''
+    _getInventoryList(searchBarcode.value)
+  } else {
+    loadData()
+  }
+}
+
 //移动数量
 const moveCount=ref('')
 //移动弹框
@@ -311,11 +385,30 @@ const onMove=(item)=>{
     return
   }
   model.value=item
-  moveCount.value=''
-  moveStockTrueFalseBy.value=true
-  setTimeout(()=>{
-    countRef.value?.focus()
-  },300)
+  if (combineData.value) {
+    combineMatchedSku.value = [{ ...item, matchedJson: combineData.value, expectedQuantity: item.availableQty }]
+    moveStockCombineRef.value?.show()
+  } else {
+    moveCount.value=''
+    moveStockTrueFalseBy.value=true
+    setTimeout(()=>{
+      countRef.value?.focus()
+    },300)
+  }
+}
+
+// 组合商品还库确认
+const setCombineMoveStock = ({ dataList }) => {
+  if (!dataList?.[0]) return
+  const row = dataList[0]
+  moveCount.value = String(row.quantity)
+  model.value = { ...model.value, ...row }
+  createMoveStock()
+}
+
+// 组合商品还库取消
+const onCombineCancel = () => {
+  moveCount.value = ''
 }
 /**
  * 确认还库
@@ -373,6 +466,7 @@ const  createMoveStock=()=>{
       location.value=''
       moveList.value=[]
       totalList.value=[]
+      combineData.value=null
     }else {
       location.value=''
       _getInventoryList(searchBarcode.value)
@@ -434,7 +528,6 @@ const onSelectMode = async (value) => {
     inputBarcodeRef.value?.show()
   }
 }
-
 // 数据刷新
 const loadData = () => {
   if(searchBarcode.value){