Bladeren bron

入库出库校验

xu 6 maanden geleden
bovenliggende
commit
2d94196a9b
1 gewijzigde bestanden met toevoegingen van 129 en 22 verwijderingen
  1. 129 22
      web/src/view/storehouse/goods/goods.vue

+ 129 - 22
web/src/view/storehouse/goods/goods.vue

@@ -500,24 +500,71 @@ const removeInboundCargo = (index) => {
 }
 
 // 提交表单
-const submitInboundForm = async() => {
-  await createInboundManifest({
-    ...manifestInboundData.value,
-    cargos: manifestInboundData.value.cargos.map(cargo => ({
-      commodityId: cargo.commodityId,
-      number: cargo.number,
-      warehouseId: cargo.location[0],
-      storageAreaId: cargo.location[1],
-      placeId: cargo.location[2]
-    }))
-  }).then(res => {
+const submitInboundForm = async () => {
+  if (!validateInboundForm()) return
+
+  try {
+    const res = await createInboundManifest({
+      ...manifestInboundData.value,
+      cargos: manifestInboundData.value.cargos.map(cargo => ({
+        commodityId: cargo.commodityId,
+        number: cargo.number,
+        warehouseId: cargo.location[0],
+        storageAreaId: cargo.location[1],
+        placeId: cargo.location[2]
+      }))
+    })
+
     if (res.code === 0) {
       ElMessage.success('入库单提交成功!')
       manifestInboundData.value.cargos = [{ commodityId: null, number: 1, location: [] }]
     }
     inboundDialog.value = false
     getData()
-  })
+  } catch (error) {
+    ElMessage.error('提交失败,请重试')
+    console.error(error)
+  }
+}
+
+const validateInboundForm = () => {
+  const data = manifestInboundData.value
+
+  if (!data.title.trim()) {
+    ElMessage.warning('请输入入库单标题')
+    return false
+  }
+
+  if (!data.custodian.trim()) {
+    ElMessage.warning('请输入保管人')
+    return false
+  }
+
+  if (!Array.isArray(data.cargos) || data.cargos.length === 0) {
+    ElMessage.warning('请至少添加一项商品')
+    return false
+  }
+
+  for (let i = 0; i < data.cargos.length; i++) {
+    const cargo = data.cargos[i]
+
+    if (!cargo.commodityId) {
+      ElMessage.warning(`第 ${i + 1} 行商品未选择`)
+      return false
+    }
+
+    if (!cargo.number || cargo.number <= 0) {
+      ElMessage.warning(`第 ${i + 1} 行数量必须大于0`)
+      return false
+    }
+
+    if (!Array.isArray(cargo.location) || cargo.location.length < 3) {
+      ElMessage.warning(`第 ${i + 1} 行请选择完整的存放位置`)
+      return false
+    }
+  }
+
+  return true
 }
 
 // 出库
@@ -561,9 +608,11 @@ const removeOutboundCargo = (index) => {
 }
 
 // 提交表单
-const submitForm = async() => {
+const submitForm = async () => {
+  if (!validateOutboundForm()) return
+
   try {
-    await createOutboundManifest({
+    const res = await createOutboundManifest({
       ...manifestOutboundData.value,
       cargos: manifestOutboundData.value.cargos.map(cargo => ({
         commodityId: cargo.commodityId,
@@ -572,19 +621,65 @@ const submitForm = async() => {
         storageAreaId: cargo.location[1],
         placeId: cargo.location[2]
       }))
-    }).then(res => {
-      if (res.code === 0) {
-        ElMessage.success('出库单提交成功!')
-      }
-      outboundDialog.value = false
-      getData()
     })
+
+    if (res.code === 0) {
+      ElMessage.success('出库单提交成功!')
+    }
+
+    outboundDialog.value = false
+    getData()
     resetForm()
   } catch (error) {
     ElMessage.error(`提交失败: ${error.message}`)
   }
 }
 
+const validateOutboundForm = () => {
+  const data = manifestOutboundData.value
+
+  if (!data.title.trim()) {
+    ElMessage.warning('请输入出库单标题')
+    return false
+  }
+
+  if (!data.custodian.trim()) {
+    ElMessage.warning('请输入保管人')
+    return false
+  }
+
+  if (!Array.isArray(data.cargos) || data.cargos.length === 0) {
+    ElMessage.warning('请至少添加一项商品')
+    return false
+  }
+
+  for (let i = 0; i < data.cargos.length; i++) {
+    const cargo = data.cargos[i]
+
+    if (!cargo.commodityId) {
+      ElMessage.warning(`第 ${i + 1} 行商品未选择`)
+      return false
+    }
+
+    if (!cargo.number || cargo.number <= 0) {
+      ElMessage.warning(`第 ${i + 1} 行数量必须大于0`)
+      return false
+    }
+
+    if (cargo.number > cargo.maxNumber) {
+      ElMessage.warning(`第 ${i + 1} 行数量不能超过最大可出库数量:${cargo.maxNumber}`)
+      return false
+    }
+
+    if (!Array.isArray(cargo.location) || cargo.location.length < 3) {
+      ElMessage.warning(`第 ${i + 1} 行请选择完整的存放位置`)
+      return false
+    }
+  }
+
+  return true
+}
+
 // 更新商品信息
 const updateCommodityInfo = (row) => {
   const goods = goodsList.value.find(item => item.commodityId === row.commodityId)
@@ -601,8 +696,20 @@ const isCommoditySelected = (id) => {
 
 // 重置表单
 const resetForm = () => {
-  manifestOutboundData.value.cargos = [{ commodityId: null, number: 1, location: [] }]
-  manifestOutboundData.value.custodian = ''
+  manifestOutboundData.value = {
+    manifestGenre: '出库',
+    title: '',
+    custodian: '',
+    cargos: [
+      {
+        commodityId: null,
+        commodityName: '',
+        number: 0,
+        maxNumber: 1,
+        location: []
+      },
+    ],
+  }
 }
 
 onMounted(() => {