yyb
4 天以前 1ae3be372c9064d4158dc7b73f1043c144e3690f
refactor: 优化发货状态逻辑和可发货产品判断

- 更新发货状态的处理逻辑,增加对发货状态的代码映射
- 修改可发货产品的判断条件,确保只有在产品状态充足且符合发货条件时才可发货
- 增强用户提示信息,明确发货条件和状态
- 调整发货状态标签以与后端枚举对齐,提升代码可读性
已修改1个文件
92 ■■■■ 文件已修改
src/pages/sales/salesAccount/index.vue 92 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/sales/salesAccount/index.vue
@@ -165,26 +165,33 @@
  const hasShippedProducts = products => {
    if (!products || products.length === 0) return false;
    return products.some(p => {
      const statusStr = (p.shippingStatus ?? "").toString();
      // 包含“发货”或有发货日期/车牌号视为已发货
      const statusCode = normalizeShippingStatusToCode(p.deliveryStatus ?? p.shippingStatus);
      const statusStr = (p.shippingStatus ?? "").toString().trim();
      // 有发货日期/车牌号,或状态明确为“已发货/发货完成”视为已发货
      return (
        statusStr.includes("发货") || !!p.shippingDate || !!p.shippingCarNumber
        statusCode === 5 ||
        statusStr === "已发货" ||
        statusStr === "发货完成" ||
        statusStr === "已完成发货" ||
        !!p.shippingDate ||
        !!p.shippingCarNumber
      );
    });
  };
  // 台账发货状态:1-未发货,2-审批中,3-审批不通过,4-已发货(与后端枚举对齐,兼容多种字段名)
  // 台账发货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货(与后端枚举对齐,兼容多种字段名)
  const LEDGER_SHIPPING_LABELS = {
    1: "未发货",
    2: "审批中",
    3: "审批不通过",
    4: "已发货",
    4: "审批通过",
    5: "已发货",
  };
  const normalizeShippingStatusToCode = v => {
    if (v === null || v === undefined || v === "") return 1;
    const n = Number(v);
    if (!Number.isNaN(n) && n >= 1 && n <= 4) return n;
    if (!Number.isNaN(n) && n >= 1 && n <= 5) return n;
    const s = String(v).trim();
    const textMap = {
      未发货: 1,
@@ -194,7 +201,11 @@
      待审核: 2,
      审批不通过: 3,
      审核拒绝: 3,
      已发货: 4,
      审批通过: 4,
      审核通过: 4,
      已发货: 5,
      发货完成: 5,
      已完成发货: 5,
    };
    return textMap[s] ?? 1;
  };
@@ -219,7 +230,7 @@
    LEDGER_SHIPPING_LABELS[getLedgerShippingStatusCode(item)] ?? "未发货";
  const getLedgerShippingTagType = item => {
    const t = { 1: "info", 2: "warning", 3: "error", 4: "success" };
    const t = { 1: "info", 2: "warning", 3: "error", 4: "primary", 5: "success" };
    return t[getLedgerShippingStatusCode(item)] ?? "info";
  };
@@ -228,14 +239,36 @@
    return c === 1 || c === 3;
  };
  // 与明细页原逻辑一致:仅库存充足、未实际发货、状态为未发货/审批不通过时可提交发货审批
  const canShipProduct = row => {
    if (!row || row.approveStatus !== 1) return false;
  /**
   * 判断是否可以发货
   * 只有在产品状态是充足,发货状态是待发货和审核拒绝的时候才可以发货
   * @param row 行数据
   */
  const canShip = row => {
    if (!row) return false;
    // 产品状态必须是充足(approveStatus === 1)
    if (row.approveStatus !== 1) return false;
    // 如果已发货(有发货日期或车牌号),不能再次发货
    if (row.shippingDate || row.shippingCarNumber) return false;
    const code = normalizeShippingStatusToCode(row.shippingStatus);
    if (code === 1 || code === 3) return true;
    const s = row.shippingStatus ? String(row.shippingStatus).trim() : "";
    return s === "待发货" || s === "未发货" || s === "审核拒绝" || s === "审批不通过";
    // 如果后端返回了发货状态(deliveryStatus),已发货则禁止再次发货
    const deliveryStatus = row.deliveryStatus;
    if (deliveryStatus !== null && deliveryStatus !== undefined && String(deliveryStatus).trim() !== "") {
      const code = normalizeShippingStatusToCode(deliveryStatus);
      if (code === 5) return false;
    }
    // 发货状态必须是"待发货"或"审核拒绝"
    const statusStr = row.shippingStatus ? String(row.shippingStatus).trim() : "";
    return statusStr === "待发货" || statusStr === "审核拒绝";
  };
  const productLabel = row => {
    if (!row) return "产品";
    const parts = [row.productCategory, row.floorCode, row.specificationModel].filter(Boolean);
    return parts.length ? parts.join(" / ") : (row.productName || row.goodsName || "产品");
  };
  const handleShip = async item => {
@@ -251,15 +284,38 @@
    try {
      const res = await productList({ salesLedgerId: item.id, type: 1 });
      const products = res.data || res.records || [];
      const row = products.find(p => canShipProduct(p));
      closeToast();
      if (!row) {
      if (!products.length) {
        uni.showToast({
          title: "没有可发货的产品",
          title: "没有产品数据",
          icon: "none",
        });
        return;
      }
      // 先检查是否存在“不足”的产品:有一个不足就禁止发货并提示
      const insufficient = products.filter(p => p?.approveStatus !== 1);
      if (insufficient.length) {
        const names = insufficient.slice(0, 3).map(productLabel).join("、");
        uni.showToast({
          title: `存在库存不足产品:${names}${insufficient.length > 3 ? "…" : ""}`,
          icon: "none",
          duration: 2500,
        });
        return;
      }
      // 全部充足后,再筛选可发货产品(仅待发货/审核拒绝)
      const row = products.find(p => canShip(p));
      if (!row) {
        uni.showToast({
          title: "没有可发货的产品(仅待发货/审核拒绝可发货)",
          icon: "none",
          duration: 2500,
        });
        return;
      }
      uni.setStorageSync("goOutData", JSON.stringify(row));
      uni.navigateTo({
        url: "/pages/sales/salesAccount/goOut",