yyb
5 天以前 0fd269224211075e9657d6cb285b10805cd5d24f
src/pages/sales/salesAccount/index.vue
@@ -26,7 +26,8 @@
          v-if="ledgerList.length > 0">
      <view v-for="(item, index) in ledgerList"
            :key="index">
        <view class="ledger-item">
        <view class="ledger-item"
              @click="openOut(item)">
          <view class="item-header">
            <view class="item-left">
              <view class="document-icon">
@@ -66,6 +67,13 @@
              <text class="detail-label">签订日期</text>
              <text class="detail-value">{{ item.executionDate }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">发货状态</text>
              <u-tag size="mini"
                     :type="getLedgerShippingTagType(item)">{{
                getLedgerShippingLabel(item)
              }}</u-tag>
            </view>
            <up-divider></up-divider>
            <view class="detail-info">
              <view class="detail-row">
@@ -83,8 +91,9 @@
                        size="small"
                        type="primary"
                        plain
                        @click.stop="openOut(item)">
                发货状态
                        :disabled="!canLedgerShip(item)"
                        @click.stop="handleShip(item)">
                发货
              </u-button>
              <!-- <u-button class="detail-button"
                        size="small"
@@ -164,6 +173,106 @@
    });
  };
  // 台账发货状态:1-未发货,2-审批中,3-审批不通过,4-已发货(与后端枚举对齐,兼容多种字段名)
  const LEDGER_SHIPPING_LABELS = {
    1: "未发货",
    2: "审批中",
    3: "审批不通过",
    4: "已发货",
  };
  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;
    const s = String(v).trim();
    const textMap = {
      未发货: 1,
      待发货: 1,
      审批中: 2,
      审核中: 2,
      待审核: 2,
      审批不通过: 3,
      审核拒绝: 3,
      已发货: 4,
    };
    return textMap[s] ?? 1;
  };
  const getLedgerShippingStatusCode = item => {
    if (!item) return 1;
    const raw =
      item.deliveryStatus ??
      item.shippingApprovalStatus ??
      item.shipmentApproveStatus ??
      item.ledgerShippingStatus;
    if (raw !== null && raw !== undefined && raw !== "") {
      return normalizeShippingStatusToCode(raw);
    }
    if (item.shippingStatus !== null && item.shippingStatus !== undefined && item.shippingStatus !== "") {
      return normalizeShippingStatusToCode(item.shippingStatus);
    }
    return 1;
  };
  const getLedgerShippingLabel = item =>
    LEDGER_SHIPPING_LABELS[getLedgerShippingStatusCode(item)] ?? "未发货";
  const getLedgerShippingTagType = item => {
    const t = { 1: "info", 2: "warning", 3: "error", 4: "success" };
    return t[getLedgerShippingStatusCode(item)] ?? "info";
  };
  const canLedgerShip = item => {
    const c = getLedgerShippingStatusCode(item);
    return c === 1 || c === 3;
  };
  // 与明细页原逻辑一致:仅库存充足、未实际发货、状态为未发货/审批不通过时可提交发货审批
  const canShipProduct = row => {
    if (!row || 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 === "审批不通过";
  };
  const handleShip = async item => {
    if (!canLedgerShip(item)) {
      uni.showToast({
        title: "仅未发货或审批不通过时可发货",
        icon: "none",
      });
      return;
    }
    if (!item?.id) return;
    showLoadingToast("加载中...");
    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) {
        uni.showToast({
          title: "没有可发货的产品",
          icon: "none",
        });
        return;
      }
      uni.setStorageSync("goOutData", JSON.stringify(row));
      uni.navigateTo({
        url: "/pages/sales/salesAccount/goOut",
      });
    } catch (e) {
      closeToast();
      uni.showToast({
        title: "加载产品失败",
        icon: "none",
      });
    }
  };
  // 返回上一页
  const goBack = () => {
    uni.navigateBack();