yaowanxin
13 小时以前 23623551f46642c53c94593b90ab2d1c7e493258
发货前校验产品库存
已修改1个文件
53 ■■■■ 文件已修改
src/views/salesManagement/salesLedger/index.vue 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/index.vue
@@ -482,6 +482,10 @@
import { modelList, productTreeList } from "@/api/basicData/product.js";
import useFormData from "@/hooks/useFormData.js";
import dayjs from "dayjs";
import {
  getStockInPage
} from "@/api/inventoryManagement/stockIn.js";
const userStore = useUserStore();
const { proxy } = getCurrentInstance();
@@ -1528,13 +1532,48 @@
}
// 打开发货弹框
const openDeliveryForm = (parentRow, productRow) => {
  currentDeliveryContext.value = { parentRow, productRow };
  deliveryForm.value = {
    shippingDate: getCurrentDate(),
    shippingCarNumber: "",
  };
  deliveryFormVisible.value = true;
const openDeliveryForm = async (parentRow, productRow) => {
  // productRow的minStock和quantity
  console.log('22222', productRow)
  // 检查产品库存是否足够
  const requiredQuantity = productRow.quantity || 0;  // 需要发货的数量
  try {
    // 等待获取库存信息
    const res = await getStockInPage({
      current: 1,
      size: 100
    });
    // console.log('res33333', res.data.records)
    // 通过 productRow.id 过滤出对应的库存记录
    const matchingStockRecords = res.data?.records?.filter(record =>
        record.salesLedgerProductId === productRow.id
    ) || [];
    // 计算匹配记录的总库存数量
    const currentStock = matchingStockRecords.reduce((total, record) => {
      return total + (record.inboundNum0 || 0);
    }, 0);
    // 检查库存是否充足
    if (currentStock < requiredQuantity) {
      // 库存不足提示
      proxy.$modal.msgWarning(`产品库存不足`);
      return;
    }
    // 库存充足,继续打开发货弹框
    currentDeliveryContext.value = { parentRow, productRow };
    deliveryForm.value = {
      shippingDate: getCurrentDate(),
      shippingCarNumber: "",
    };
    deliveryFormVisible.value = true;
  } catch (error) {
    console.error('获取库存信息失败:', error);
    proxy.$modal.msgError("获取库存信息失败,请重试");
  }
};
// 提交发货表单