zhaohuanhuan 1 год назад
Родитель
Сommit
eadbb535d1

+ 105 - 0
src/views/outbound/components/BarcodeCombine.vue

@@ -0,0 +1,105 @@
+<template>
+  <div class="goods">
+    <van-dialog v-model:show="goodsTrueFalseBy"
+                :beforeClose="beforeClose"
+                title="组合商品包含"
+                show-cancel-button>
+      <div  v-for="(item,index) in matchedSkuList" :key="index">
+        <van-cell center :title="item.matchedJson.barcode" :value="item.matchedJson.quantity+'件'" :label="item.matchedJson.skuName" />
+        <div class="goods-tips">预期数量:{{item.expectedQuantity}}件</div>
+      </div>
+      <div class="goods-number">应拣数量:{{maxCount}}</div>
+      <van-field label="实拣数" class="code-input" v-model="count" ref="countRef" placeholder="实拣数" />
+    </van-dialog>
+  </div>
+</template>
+<script setup lang="ts">
+import { computed, ref } from 'vue'
+import { showToast } from 'vant'
+import { formatDateTime } from '@/utils/date'
+const goodsTrueFalseBy=ref(false)
+const countRef=ref(null)
+const count=ref('');
+const props = defineProps({
+  matchedSku: Array,
+  container:String
+});
+const maxCount = ref(0);
+const matchedSkuList = computed(() => {
+  let minNumber = Infinity;
+  props.matchedSku.forEach((item) => {
+    // 计算每个 item 的 number 值
+    const number = item.expectedQuantity / item.matchedJson.quantity;
+    if (number < minNumber) {
+      minNumber = number;
+    }
+  });
+  // 将最小的 number 向下取整并赋值给 maxCount
+  maxCount.value = Math.floor(minNumber);
+  // 返回 props.matchedSku 数组
+  return props.matchedSku;
+});
+const show = async () => {
+  count.value=''
+  goodsTrueFalseBy.value = true
+  setTimeout(()=>{
+    countRef.value?.focus()
+  },200)
+}
+//输入拣货容器号
+const emit = defineEmits()
+const  beforeClose = (action) =>
+  new Promise(async (resolve) => {
+    if (action === 'confirm') {
+      if (count.value == '') {
+        showToast('请输入拣货数量')
+        return resolve(false)
+      }
+      if (count.value >maxCount.value) {
+        showToast({duration:3000,message:'拣货数量不能大于应拣数量'})
+        return resolve(false)
+      }
+      const data= dataResult(matchedSkuList.value)
+      emit('setCombine', data)
+    }
+    resolve(true)
+  });
+const dataResult=(data)=>{
+  const list=JSON.parse(JSON.stringify(data))
+  list.forEach((item,index)=>{
+    item.quantity=item.matchedJson.quantity * count.value
+    item.container=props.container
+    item.operationTime=formatDateTime(new Date())
+    delete item.matchedJson
+  })
+  return list
+}
+defineExpose({show})
+</script>
+<style scoped lang="sass">
+.goods
+  .code-input
+    font-size: 16px
+    font-weight: bold
+    border-bottom: 2px solid #0077ff
+    margin-top: 10px
+  :deep(.van-cell--center)
+    padding: 5px 20px
+  :deep(.van-cell__title)
+    text-align: left !important
+  :deep(.van-cell__value)
+    width: 20% !important
+    flex: 0 0 20% !important
+    color: #000
+  :deep(.van-field__control)
+    font-size: 18spx
+  .goods-number
+    text-align: left
+    font-size: 16px
+    padding-left: 20px
+  .goods-tips
+    font-size: 12px
+    text-align: right
+    padding: 5px 20px 0 0
+    color: #333
+</style>

+ 17 - 0
src/views/outbound/picking/list/hooks/barcodeCombine.js

@@ -0,0 +1,17 @@
+//组合商品匹配到的商品
+export function barcodeCombine(goodsList, combineSkuMap){
+  const result = goodsList.map(item => {
+      const barcode = item.barcode || item.barcodeAs;
+      // 如果有匹配数据,将 matchedJson 添加到 item 中
+      if (combineSkuMap[barcode] && item.expectedQuantity <= combineSkuMap[barcode].quantity ) {
+        return {
+          ...item,
+          matchedJson: combineSkuMap[barcode]
+        };
+      }
+      return null
+    })
+    .filter(item => item !== null) // 过滤掉 null 元素,保留匹配到的项
+  // 如果 result 数组为空,返回空数组,否则返回 result
+  return result.length > 0 ? result : []
+}