yyb
2026-05-11 3682ad63b5bdb47228325dea1efe2bb9069254a5
合格出库扫销售二维码进行发货
已添加1个文件
已修改5个文件
1095 ■■■■ 文件已修改
src/pages/inventoryManagement/scanOut/index.vue 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/inventoryManagement/scanOut/scanOut.fields.ts 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/sales/salesAccount/goOut.vue 570 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/sales/salesAccount/index.vue 181 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/sales/salesAccount/out.vue 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/salesLedgerShip.js 209 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/inventoryManagement/scanOut/index.vue
@@ -28,7 +28,7 @@
          <text class="module-label">合格出库</text>
          <text class="module-desc">扫描合格品进行领用出库</text>
          <text class="module-desc">扫描合格品进行领用出库,销售扫码发货</text>
        </view>
@@ -225,7 +225,19 @@
                  @click="cancelForm">返回</u-button>
        <u-button class="footer-confirm-btn"
        <u-button v-if="showSalesShipButton"
                  class="footer-confirm-btn"
                  :loading="submitLoading"
                  :disabled="salesShipButtonDisabled"
                  @click="handleSalesShipFromScan">发货</u-button>
        <u-button v-else
                  class="footer-confirm-btn"
                  :loading="submitLoading"
@@ -247,7 +259,12 @@
  import PageHeader from "@/components/PageHeader.vue";
  import { productList as salesProductList } from "@/api/salesManagement/salesLedger";
  import {
    productList as salesProductList,
    getSalesLedgerWithProducts,
  } from "@/api/salesManagement/salesLedger";
  import { canLedgerShip, executeSalesLedgerShip, getLedgerShippingLabel } from "@/utils/salesLedgerShip";
  import modal from "@/plugins/modal";
@@ -281,7 +298,24 @@
  /** äºŒç»´ç ä¸­çš„台账主键 id */
  const scanLedgerId = ref(null);
  /** åˆæ ¼å‡ºåº“+销售码:用于「发货」按钮与台账级校验(与销售台账一致) */
  const salesLedgerSnapshotForShip = ref(null);
  const submitLoading = ref(false);
  const showSalesShipButton = computed(
    () =>
      showForm.value &&
      type.value === QUALITY_TYPE.qualified &&
      contractKind.value === CONTRACT_KIND.sales
  );
  const salesShipButtonDisabled = computed(() => {
    if (!showSalesShipButton.value) return false;
    const snap = salesLedgerSnapshotForShip.value;
    if (!snap) return false;
    return !canLedgerShip(snap);
  });
  const submitConfigByScene = createSubmitConfig(scanLedgerId);
@@ -568,6 +602,8 @@
      return formatProductStockStatus(item.productStockStatus);
    if (row.key === "ledgerShippingStatus") return getLedgerShippingLabel(item);
    if (row.key === "heavyBox") return formatHeavyBox(item.heavyBox);
    if (row.key === "remainingQuantity") {
@@ -633,6 +669,8 @@
    contractKind.value = CONTRACT_KIND.sales;
    scanLedgerId.value = null;
    salesLedgerSnapshotForShip.value = null;
    expandedByIndex.value = {};
@@ -724,6 +762,62 @@
      modal.closeLoading();
      console.error("扫码出库提交失败", e);
    } finally {
      submitLoading.value = false;
    }
  };
  const handleSalesShipFromScan = async () => {
    if (scanLedgerId.value == null || scanLedgerId.value === "") {
      modal.msgError("缺少订单信息,请重新扫码");
      return;
    }
    if (salesLedgerSnapshotForShip.value && !canLedgerShip(salesLedgerSnapshotForShip.value)) return;
    submitLoading.value = true;
    try {
      modal.loading("加载中...");
      let ledgerRow = salesLedgerSnapshotForShip.value;
      if (!ledgerRow?.id) {
        ledgerRow = await getSalesLedgerWithProducts({ id: scanLedgerId.value, type: 1 });
      }
      modal.closeLoading();
      if (!ledgerRow?.id) {
        modal.msgError("获取台账失败");
        return;
      }
      const { productData: _pd, ...ledgerForShip } = ledgerRow;
      await executeSalesLedgerShip(ledgerForShip);
    } catch (e) {
      modal.closeLoading();
      console.error("扫码发货失败", e);
      modal.msgError("获取台账失败");
    } finally {
@@ -900,9 +994,35 @@
        showForm.value = true;
        if (type.value === QUALITY_TYPE.qualified && kind === CONTRACT_KIND.sales) {
          salesLedgerSnapshotForShip.value = null;
          getSalesLedgerWithProducts({ id: scanData.id, type: 1 })
            .then(res => {
              salesLedgerSnapshotForShip.value = res;
            })
            .catch(() => {
              salesLedgerSnapshotForShip.value = null;
            });
        } else {
          salesLedgerSnapshotForShip.value = null;
        }
      } else {
        scanLedgerId.value = null;
        salesLedgerSnapshotForShip.value = null;
        modal.msgError("未查询到明细数据");
@@ -914,6 +1034,8 @@
      scanLedgerId.value = null;
      salesLedgerSnapshotForShip.value = null;
      console.error("处理扫码结果失败", error);
      modal.msgError("扫码处理失败,请重试");
src/pages/inventoryManagement/scanOut/scanOut.fields.ts
@@ -28,6 +28,7 @@
  { label: "重箱", key: "heavyBox" },
  { label: "产品状态", key: "approveStatus" },
  { label: "入库状态", key: "productStockStatus" },
  { label: "发货状态", key: "ledgerShippingStatus" },
  { label: "快递公司", key: "expressCompany" },
  { label: "快递单号", key: "expressNumber" },
  { label: "发货车牌", key: "shippingCarNumber" },
@@ -59,6 +60,7 @@
  { label: "数量", key: "quantity" },
  { label: "产品状态", key: "approveStatus" },
  { label: "入库状态", key: "productStockStatus" },
  { label: "发货状态", key: "ledgerShippingStatus" },
] as const;
export const summaryFieldRowsPurchase = [
src/pages/sales/salesAccount/goOut.vue
@@ -20,7 +20,78 @@
                   @click="showPicker = true"></up-icon>
        </template>
      </u-form-item>
      <u-form-item v-if="typeValue === '货车'"
                   prop="shippingCarNumber"
                   label="车牌号"
                   required>
        <u-input v-model="form.shippingCarNumber"
                 placeholder="请输入车牌号"
                 clearable />
      </u-form-item>
      <u-form-item v-if="typeValue === '快递'"
                   prop="expressNumber"
                   label="快递单号"
                   required>
        <u-input v-model="form.expressNumber"
                 placeholder="请输入快递单号"
                 clearable />
      </u-form-item>
    </u-form>
    <!-- å‘货图片:相册或相机、/file/upload、预览与列表样式 -->
    <view class="ship-images-card">
      <view class="ship-images-header">
        <text class="ship-images-title">发货图片</text>
        <text class="ship-images-hint">最多 {{ uploadConfig.limit }} å¼ </text>
      </view>
      <view class="simple-upload-area">
        <view class="upload-buttons">
          <u-button type="primary"
                    @click="chooseShipImage"
                    :loading="shipUploading"
                    :disabled="shipFiles.length >= uploadConfig.limit"
                    :customStyle="{ width: '100%' }">
            <u-icon name="camera"
                    size="18"
                    color="#fff"
                    style="margin-right: 5px;"></u-icon>
            {{ shipUploading ? '上传中...' : '添加图片' }}
          </u-button>
        </view>
        <view v-if="shipUploading"
              class="upload-progress">
          <u-line-progress :percentage="shipUploadProgress"
                           :showText="true"
                           activeColor="#409eff"></u-line-progress>
        </view>
        <view v-if="shipFiles.length > 0"
              class="file-list">
          <view v-for="(file, index) in shipFiles"
                :key="file.uid || index"
                class="file-item">
            <view class="file-preview-container"
                  @click="previewShipImage(file)">
              <image :src="getFileAccessUrl(file)"
                     class="file-preview"
                     mode="aspectFill" />
              <view class="delete-btn"
                    @click.stop="removeShipFile(index)">
                <u-icon name="close"
                        size="12"
                        color="#fff"></u-icon>
              </view>
            </view>
            <view class="file-info">
              <text class="file-name">{{ file.bucketFilename || file.name || '图片' }}</text>
              <text class="file-size">{{ formatFileSize(file.size) }}</text>
            </view>
          </view>
        </view>
        <view v-else
              class="empty-state">
          <text>请从相册选择或拍照上传发货图片</text>
        </view>
      </view>
    </view>
    <!-- é€‰æ‹©å™¨å¼¹çª— -->
    <up-action-sheet :show="showPicker"
                     :actions="productOptions"
@@ -87,9 +158,11 @@
</template>
<script setup>
  import { ref, onMounted, onUnmounted, reactive, toRefs } from "vue";
  import { ref, computed, onMounted, onUnmounted, reactive, toRefs } from "vue";
  import PageHeader from "@/components/PageHeader.vue";
  import { addShippingInfo } from "@/api/salesManagement/salesLedger";
  import config from "@/config";
  import { getToken } from "@/utils/auth";
  const showToast = message => {
    uni.showToast({
      title: message,
@@ -97,6 +170,8 @@
    });
  };
  import { userListNoPageByTenantId } from "@/api/system/user";
  const typeValue = ref("货车");
  const data = reactive({
    form: {
@@ -114,9 +189,43 @@
      endDate: "",
      location: "",
      price: "",
      shippingCarNumber: "",
      expressNumber: "",
    },
    rules: {
      typeValue: [{ required: false, message: "请选择", trigger: "change" }],
      shippingCarNumber: [
        {
          validator: (rule, value, callback) => {
            if (typeValue.value !== "货车") {
              callback();
              return;
            }
            if (!value || !String(value).trim()) {
              callback(new Error("请输入车牌号"));
              return;
            }
            callback();
          },
          trigger: ["blur", "change"],
        },
      ],
      expressNumber: [
        {
          validator: (rule, value, callback) => {
            if (typeValue.value !== "快递") {
              callback();
              return;
            }
            if (!value || !String(value).trim()) {
              callback(new Error("请输入快递单号"));
              return;
            }
            callback();
          },
          trigger: ["blur", "change"],
        },
      ],
    },
  });
  const { form, rules } = toRefs(data);
@@ -138,6 +247,329 @@
  const formRef = ref(null);
  const approveType = ref(0);
  const goOutData = ref({});
  // ä¸Žè®¾å¤‡å·¡æ£€ inspectionUpload/index.vue ä¸­ uploadConfig ä¸€è‡´
  const uploadConfig = {
    action: "/file/upload",
    limit: 10,
    fileSize: 50,
    fileType: ["jpg", "jpeg", "png", "gif", "webp"],
  };
  /** ä¸Žè®¾å¤‡å·¡æ£€ä¸€è‡´ï¼šç”Ÿäº§å‰ type=10 ä¼ ç»™ /file/upload çš„ formData.type */
  const shipUploadFormType = 10;
  const uploadFileUrl = computed(() => (config.baseUrl || "").replace(/\/$/, "") + uploadConfig.action);
  const shipFiles = ref([]);
  const shipUploading = ref(false);
  const shipUploadProgress = ref(0);
  const isImageFile = file => {
    if (file?.contentType && String(file.contentType).startsWith("image/")) return true;
    if (file?.type === "image" || file?.mediaType === "image") return true;
    const name = file?.bucketFilename || file?.originalFilename || file?.name || "";
    const ext = name.split(".").pop()?.toLowerCase();
    return ["jpg", "jpeg", "png", "gif", "webp"].includes(ext);
  };
  const filePreviewBase = config.fileUrl;
  const normalizeFileUrl = (rawUrl = "") => {
    let fileUrl = rawUrl || "";
    if (typeof fileUrl === "string") {
      fileUrl = fileUrl.trim().replace(/^['"]|['"]$/g, "");
    }
    const javaApi = filePreviewBase;
    const localPrefixes = ["wxfile://", "file://", "content://", "blob:", "data:"];
    if (localPrefixes.some(prefix => fileUrl.startsWith(prefix))) {
      return fileUrl;
    }
    if (fileUrl && fileUrl.indexOf("\\") > -1) {
      const lowerPath = fileUrl.toLowerCase();
      const uploadPathIndex = lowerPath.indexOf("uploadpath");
      const prodIndex = lowerPath.indexOf("\\prod\\");
      if (uploadPathIndex > -1) {
        fileUrl = fileUrl.substring(uploadPathIndex).replace(/\\/g, "/");
      } else if (prodIndex > -1) {
        fileUrl = fileUrl
          .substring(prodIndex + "\\prod\\".length)
          .replace(/\\/g, "/");
      } else {
        fileUrl = fileUrl.replace(/\\/g, "/");
      }
    }
    const normalizedLower = String(fileUrl).toLowerCase();
    const fileProdIdx = normalizedLower.indexOf("/file/prod/");
    if (fileProdIdx > -1) {
      fileUrl = `/profile/prod/${fileUrl.substring(fileProdIdx + "/file/prod/".length)}`;
    }
    const fileTempIdx = normalizedLower.indexOf("/file/temp/");
    if (fileTempIdx > -1) {
      fileUrl = `/profile/temp/${fileUrl.substring(fileTempIdx + "/file/temp/".length)}`;
    }
    if (/^\/?uploadPath/i.test(fileUrl)) {
      fileUrl = fileUrl.replace(/^\/?uploadPath/i, "/profile");
    }
    if (fileUrl && !fileUrl.startsWith("http")) {
      if (!fileUrl.startsWith("/")) fileUrl = "/" + fileUrl;
      fileUrl = javaApi + fileUrl;
    }
    return fileUrl;
  };
  const getFileAccessUrl = (file = {}) => {
    if (file?.link) {
      if (String(file.link).startsWith("http")) return file.link;
      return normalizeFileUrl(file.link);
    }
    const remoteUrl = normalizeFileUrl(
      file?.url || file?.downloadUrl || file?.tempPath || ""
    );
    if (remoteUrl) return remoteUrl;
    if (file?._localPreviewUrl) return file._localPreviewUrl;
    return normalizeFileUrl(file?.tempFilePath || file?.path || "");
  };
  const formatFileSize = size => {
    if (!size) return "";
    if (size < 1024) return size + "B";
    if (size < 1024 * 1024) return (size / 1024).toFixed(1) + "KB";
    return (size / (1024 * 1024)).toFixed(1) + "MB";
  };
  const handleShipUploadError = (message = "上传文件失败") => {
    shipUploading.value = false;
    shipUploadProgress.value = 0;
    uni.showToast({ title: message, icon: "error" });
  };
  const handleShipUploadSuccess = (res, file) => {
    const uploadedFile = res.data;
    if (!uploadedFile) {
      handleShipUploadError("上传响应数据格式错误");
      return;
    }
    const fileData = {
      ...file,
      id: uploadedFile.id,
      tempId: uploadedFile.tempId ?? uploadedFile.tempFileId ?? uploadedFile.id,
      url:
        uploadedFile.url ||
        uploadedFile.downloadUrl ||
        uploadedFile.tempPath ||
        file.tempFilePath ||
        file.path,
      tempPath: uploadedFile.tempPath || file.tempPath || "",
      _localPreviewUrl: file.tempFilePath || file.path || "",
      bucketFilename:
        uploadedFile.bucketFilename ||
        uploadedFile.originalFilename ||
        uploadedFile.originalName ||
        file.name,
      downloadUrl: uploadedFile.downloadUrl || uploadedFile.url,
      size: uploadedFile.size || uploadedFile.byteSize || file.size,
      createTime: uploadedFile.createTime || new Date().getTime(),
      mediaType: file.type || uploadedFile.mediaType,
    };
    shipFiles.value.push(fileData);
    uni.showToast({ title: "上传成功", icon: "success" });
  };
  const uploadShipWithUniUploadFile = (file, filePath, token) => {
    if (!filePath) {
      handleShipUploadError("文件路径不存在");
      return;
    }
    shipUploading.value = true;
    shipUploadProgress.value = 0;
    const uploadTask = uni.uploadFile({
      url: uploadFileUrl.value,
      filePath,
      name: "file",
      formData: {
        type: shipUploadFormType,
      },
      header: {
        Authorization: `Bearer ${token}`,
      },
      success: res => {
        try {
          if (res.statusCode === 200) {
            const response = JSON.parse(res.data || "{}");
            if (response.code === 200) {
              handleShipUploadSuccess(response, file);
            } else {
              handleShipUploadError(response.msg || "服务器返回错误");
            }
          } else {
            handleShipUploadError(`服务器错误,状态码: ${res.statusCode}`);
          }
        } catch (e) {
          console.error("解析响应失败:", e);
          handleShipUploadError("响应数据解析失败");
        }
      },
      fail: err => {
        let errorMessage = "上传失败";
        if (err.errMsg) {
          if (err.errMsg.includes("statusCode: null")) {
            errorMessage = "网络连接失败,请检查网络设置";
          } else if (err.errMsg.includes("timeout")) {
            errorMessage = "上传超时,请重试";
          } else if (err.errMsg.includes("fail")) {
            errorMessage = "上传失败,请检查网络连接";
          } else {
            errorMessage = err.errMsg;
          }
        }
        handleShipUploadError(errorMessage);
      },
      complete: () => {
        shipUploading.value = false;
        shipUploadProgress.value = 0;
      },
    });
    if (uploadTask && uploadTask.onProgressUpdate) {
      uploadTask.onProgressUpdate(r => {
        shipUploadProgress.value = r.progress;
      });
    }
  };
  const uploadShipFile = file => {
    const token = getToken();
    if (!token) {
      handleShipUploadError("用户未登录");
      return;
    }
    uploadShipWithUniUploadFile(file, file.tempFilePath || file.path || "", token);
  };
  const handleBeforeShipUpload = async file => {
    if (uploadConfig.fileType?.length) {
      const fileName = file.name || "";
      const fileExtension = fileName ? fileName.split(".").pop().toLowerCase() : "";
      const expectedTypes = ["jpg", "jpeg", "png", "gif", "webp"];
      if (fileExtension && expectedTypes.length > 0) {
        const isAllowed = expectedTypes.some(
          t => uploadConfig.fileType.includes(t) && t === fileExtension
        );
        if (!isAllowed) {
          uni.showToast({
            title: `文件格式不支持,请选择 ${expectedTypes.join("/")} æ ¼å¼çš„图片`,
            icon: "none",
          });
          return false;
        }
      }
    }
    uploadShipFile(file);
    return true;
  };
  const chooseShipImage = () => {
    if (shipFiles.value.length >= uploadConfig.limit) {
      uni.showToast({
        title: `最多只能上传${uploadConfig.limit}张图片`,
        icon: "none",
      });
      return;
    }
    const remaining = uploadConfig.limit - shipFiles.value.length;
    if (typeof uni.chooseMedia === "function") {
      uni.chooseMedia({
        count: Math.min(remaining, 1),
        mediaType: ["image"],
        sizeType: ["compressed", "original"],
        sourceType: ["album", "camera"],
        success: res => {
          try {
            const files = res?.tempFiles || [];
            if (!files.length) throw new Error("未获取到文件");
            files.forEach((tf, idx) => {
              const filePath = tf.tempFilePath || tf.path || "";
              const file = {
                tempFilePath: filePath,
                path: filePath,
                type: "image",
                name: `image_${Date.now()}_${idx}.jpg`,
                size: tf.size || 0,
                createTime: Date.now(),
                uid: Date.now() + Math.random() + idx,
              };
              handleBeforeShipUpload(file);
            });
          } catch (e) {
            console.error("处理图片选择结果失败:", e);
            uni.showToast({ title: "处理文件失败", icon: "error" });
          }
        },
        fail: () => uni.showToast({ title: "选择图片失败", icon: "error" }),
      });
      return;
    }
    uni.chooseImage({
      count: 1,
      sizeType: ["compressed", "original"],
      sourceType: ["album", "camera"],
      success: res => {
        const tempFilePath = res?.tempFilePaths?.[0];
        const tempFile = res?.tempFiles?.[0] || {};
        if (!tempFilePath) return;
        handleBeforeShipUpload({
          tempFilePath,
          path: tempFilePath,
          type: "image",
          name: `photo_${Date.now()}.jpg`,
          size: tempFile.size || 0,
          createTime: Date.now(),
          uid: Date.now() + Math.random(),
        });
      },
      fail: () => uni.showToast({ title: "选择图片失败", icon: "none" }),
    });
  };
  const previewShipImage = file => {
    if (!file || !isImageFile(file)) return;
    const imageUrls = shipFiles.value
      .filter(f => isImageFile(f))
      .map(f => getFileAccessUrl(f))
      .filter(Boolean);
    const current = getFileAccessUrl(file);
    if (!imageUrls.length || !current) return;
    uni.previewImage({ urls: imageUrls, current });
  };
  const removeShipFile = index => {
    uni.showModal({
      title: "确认删除",
      content: "确定要删除这个文件吗?",
      success: res => {
        if (res.confirm) {
          shipFiles.value.splice(index, 1);
          uni.showToast({ title: "删除成功", icon: "success" });
        }
      },
    });
  };
  const getShipTempFileIds = () =>
    shipFiles.value
      .map(it => it.tempId ?? it.tempFileId ?? it.id)
      .filter(v => v !== undefined && v !== null && v !== "");
  onMounted(async () => {
    try {
      userListNoPageByTenantId().then(res => {
@@ -161,11 +593,14 @@
    // ç§»é™¤äº‹ä»¶ç›‘听
    uni.$off("selectContact", handleSelectContact);
  });
  const typeValue = ref("货车");
  const onConfirm = item => {
    // è®¾ç½®é€‰ä¸­çš„部门
    typeValue.value = item.name;
    showPicker.value = false;
    if (item.name === "货车") {
      form.value.expressNumber = "";
    } else {
      form.value.shippingCarNumber = "";
    }
  };
  const goBack = () => {
@@ -183,6 +618,10 @@
      showToast("请为每个审批步骤选择审批人");
      return;
    }
    if (shipUploading.value) {
      showToast("图片正在上传,请稍候");
      return;
    }
    formRef.value
      .validate()
      .then(valid => {
@@ -198,6 +637,11 @@
            salesLedgerProductId: goOutData.value.id,
            type: typeValue.value,
            approveUserIds,
            shippingCarNumber:
              typeValue.value === "货车" ? String(form.value.shippingCarNumber || "").trim() : "",
            expressNumber:
              typeValue.value === "快递" ? String(form.value.expressNumber || "").trim() : "",
            tempFileIds: getShipTempFileIds(),
          };
          console.log(params, "params");
@@ -273,6 +717,126 @@
<style scoped lang="scss">
  @import "@/static/scss/form-common.scss";
  .ship-images-card {
    background: #fff;
    margin: 16px;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }
  .ship-images-header {
    margin-bottom: 12px;
  }
  .ship-images-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    display: block;
    margin-bottom: 4px;
  }
  .ship-images-hint {
    font-size: 12px;
    color: #999;
  }
  /* ä»¥ä¸‹ä¸Ž inspectionUpload/index.vue ç®€åŒ–上传区、文件列表、视频弹窗一致 */
  .simple-upload-area {
    padding: 0;
  }
  .upload-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
  }
  .upload-progress {
    margin-bottom: 12px;
  }
  .file-list {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
  }
  .file-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border-radius: 12px;
    padding: 8px;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    width: calc(50% - 6px);
    min-width: 120px;
  }
  .file-preview-container {
    position: relative;
    margin-bottom: 8px;
  }
  .file-preview {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid #f0f0f0;
  }
  .delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: #ff4757;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(255, 71, 87, 0.3);
  }
  .file-info {
    text-align: center;
    width: 100%;
  }
  .file-name {
    font-size: 12px;
    color: #333;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
  }
  .file-size {
    font-size: 10px;
    color: #999;
    margin-top: 2px;
    display: block;
  }
  .empty-state {
    text-align: center;
    padding: 24px 16px;
    color: #999;
    font-size: 14px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #ddd;
  }
  .approval-process {
    background: #fff;
    margin: 16px;
src/pages/sales/salesAccount/index.vue
@@ -137,11 +137,14 @@
<script setup>
  import { ref } from "vue";
  import { onShow } from "@dcloudio/uni-app";
  import { ledgerListPage, delLedger, productList } from "@/api/salesManagement/salesLedger";
  import {
    ledgerListPage,
    delLedger,
    productList,
  } from "@/api/salesManagement/salesLedger";
    hasShippedProducts,
    getLedgerShippingLabel,
    getLedgerShippingTagType,
    canLedgerShip,
    executeSalesLedgerShip,
  } from "@/utils/salesLedgerShip";
  import useUserStore from "@/store/modules/user";
  import PageHeader from "@/components/PageHeader.vue";
  const userStore = useUserStore();
@@ -161,173 +164,7 @@
  // é”€å”®å°è´¦æ•°æ®
  const ledgerList = ref([]);
  // åˆ¤æ–­æ˜¯å¦å­˜åœ¨å·²å‘è´§/发货完成的产品
  const hasShippedProducts = products => {
    if (!products || products.length === 0) return false;
    return products.some(p => {
      const statusCode = normalizeShippingStatusToCode(p.deliveryStatus ?? p.shippingStatus);
      const statusStr = (p.shippingStatus ?? "").toString().trim();
      // æœ‰å‘货日期/车牌号,或状态明确为“已发货/发货完成”视为已发货
      return (
        statusCode === 5 ||
        statusStr === "已发货" ||
        statusStr === "发货完成" ||
        statusStr === "已完成发货" ||
        !!p.shippingDate ||
        !!p.shippingCarNumber
      );
    });
  };
  // å°è´¦å‘货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货(与后端枚举对齐,兼容多种字段名)
  const LEDGER_SHIPPING_LABELS = {
    1: "未发货",
    2: "审批中",
    3: "审批不通过",
    4: "审批通过",
    5: "已发货",
  };
  const normalizeShippingStatusToCode = v => {
    if (v === null || v === undefined || v === "") return 1;
    const n = Number(v);
    if (!Number.isNaN(n) && n >= 1 && n <= 5) return n;
    const s = String(v).trim();
    const textMap = {
      æœªå‘è´§: 1,
      å¾…发货: 1,
      å®¡æ‰¹ä¸­: 2,
      å®¡æ ¸ä¸­: 2,
      å¾…审核: 2,
      å®¡æ‰¹ä¸é€šè¿‡: 3,
      å®¡æ ¸æ‹’绝: 3,
      å®¡æ‰¹é€šè¿‡: 4,
      å®¡æ ¸é€šè¿‡: 4,
      å·²å‘è´§: 5,
      å‘货完成: 5,
      å·²å®Œæˆå‘è´§: 5,
    };
    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: "primary", 5: "success" };
    return t[getLedgerShippingStatusCode(item)] ?? "info";
  };
  const canLedgerShip = item => {
    const c = getLedgerShippingStatusCode(item);
    return c === 1 || c === 3;
  };
  /**
   * åˆ¤æ–­æ˜¯å¦å¯ä»¥å‘è´§
   * åªæœ‰åœ¨äº§å“çŠ¶æ€æ˜¯å……è¶³ï¼Œå‘è´§çŠ¶æ€æ˜¯å¾…å‘è´§å’Œå®¡æ ¸æ‹’ç»çš„æ—¶å€™æ‰å¯ä»¥å‘è´§
   * @param row è¡Œæ•°æ®
   */
  const canShip = row => {
    if (!row) return false;
    // äº§å“çŠ¶æ€å¿…é¡»æ˜¯å……è¶³ï¼ˆapproveStatus === 1)
    if (row.approveStatus !== 1) return false;
    // å¦‚果已发货(有发货日期或车牌号),不能再次发货
    if (row.shippingDate || row.shippingCarNumber) return false;
    // å¦‚果后端返回了发货状态(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 => {
    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 || [];
      closeToast();
      if (!products.length) {
        uni.showToast({
          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",
      });
    } catch (e) {
      closeToast();
      uni.showToast({
        title: "加载产品失败",
        icon: "none",
      });
    }
  };
  const handleShip = item => executeSalesLedgerShip(item);
  // è¿”回上一页
  const goBack = () => {
@@ -374,7 +211,7 @@
    if (hasShippedProducts(products)) {
      uni.showToast({
        title: "已发货/发货完成的销售订单不能删除",
        title: "已发货、部分发货或已有发货记录的销售订单不能删除",
        icon: "none",
      });
      return;
src/pages/sales/salesAccount/out.vue
@@ -113,6 +113,10 @@
                  class="detail-value danger">不足</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">发货状态</text>
            <text class="detail-value">{{ getLedgerShippingLabel(item) }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">快递公司</text>
            <text class="detail-value">{{ dv(item.expressCompany) }}</text>
          </view>
@@ -166,6 +170,7 @@
<script setup>
  import { ref, onMounted } from "vue";
  import { productList } from "@/api/salesManagement/salesLedger";
  import { getLedgerShippingLabel } from "@/utils/salesLedgerShip";
  // å®¢æˆ·ä¿¡æ¯
  const supplierId = ref("");
src/utils/salesLedgerShip.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,209 @@
import { productList } from "@/api/salesManagement/salesLedger";
/** å°è´¦/产品发货状态:1-未发货 â€¦ 5-已发货 6-部分发货(与后端枚举对齐,兼容多种字段名) */
export const LEDGER_SHIPPING_LABELS = {
  1: "未发货",
  2: "审批中",
  3: "审批不通过",
  4: "审批通过",
  5: "已发货",
  6: "部分发货",
};
export const normalizeShippingStatusToCode = v => {
  if (v === null || v === undefined || v === "") return 1;
  const n = Number(v);
  if (!Number.isNaN(n) && n >= 1 && n <= 6) return n;
  const s = String(v).trim();
  const textMap = {
    æœªå‘è´§: 1,
    å¾…发货: 1,
    å®¡æ‰¹ä¸­: 2,
    å®¡æ ¸ä¸­: 2,
    å¾…审核: 2,
    å®¡æ‰¹ä¸é€šè¿‡: 3,
    å®¡æ ¸æ‹’绝: 3,
    å®¡æ‰¹é€šè¿‡: 4,
    å®¡æ ¸é€šè¿‡: 4,
    å·²å‘è´§: 5,
    å‘货完成: 5,
    å·²å®Œæˆå‘è´§: 5,
    éƒ¨åˆ†å‘è´§: 6,
    éƒ¨åˆ†å·²å‘è´§: 6,
  };
  return textMap[s] ?? 1;
};
export 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;
};
export const getLedgerShippingLabel = item =>
  LEDGER_SHIPPING_LABELS[getLedgerShippingStatusCode(item)] ?? "未发货";
export const getLedgerShippingTagType = item => {
  const t = {
    1: "info",
    2: "warning",
    3: "error",
    4: "primary",
    5: "success",
    6: "warning",
  };
  return t[getLedgerShippingStatusCode(item)] ?? "info";
};
/** å°è´¦çº§æ˜¯å¦å…è®¸å‘èµ·/继续发货(含部分发货后继续发剩余) */
export const canLedgerShip = item => {
  const c = getLedgerShippingStatusCode(item);
  return c === 1 || c === 3 || c === 6;
};
/** productStockStatus:0 æœªå‡ºåº“ â€” ä¸å…è®¸å‘货(与业务端展示一致) */
export const isProductStockStatusUnOutbound = row => {
  if (!row) return false;
  const v = row.productStockStatus;
  return v === 0 || v === "0";
};
/**
 * å•行产品是否允许进入发货页(充足 + éžæœªå‡ºåº“;待发货/审核拒绝/部分发货可继续)
 * éƒ¨åˆ†å‘货行可能已有 shippingDate/车牌,仍允许再次发货
 */
export const canShipProductRow = row => {
  if (!row) return false;
  if (isProductStockStatusUnOutbound(row)) return false;
  if (row.approveStatus !== 1) return false;
  const statusStr = row.shippingStatus ? String(row.shippingStatus).trim() : "";
  let rowCode = 1;
  if (row.deliveryStatus !== null && row.deliveryStatus !== undefined && String(row.deliveryStatus).trim() !== "") {
    rowCode = normalizeShippingStatusToCode(row.deliveryStatus);
  } else if (statusStr) {
    rowCode = normalizeShippingStatusToCode(statusStr);
  }
  if (rowCode === 5) return false;
  const isPartialRow = rowCode === 6 || statusStr === "部分发货" || statusStr === "部分已发货";
  if ((row.shippingDate || row.shippingCarNumber) && !isPartialRow) return false;
  if (row.deliveryStatus !== null && row.deliveryStatus !== undefined && String(row.deliveryStatus).trim() !== "") {
    const code = normalizeShippingStatusToCode(row.deliveryStatus);
    if (code === 5) return false;
  }
  return (
    statusStr === "待发货" ||
    statusStr === "审核拒绝" ||
    statusStr === "部分发货" ||
    statusStr === "部分已发货" ||
    rowCode === 6
  );
};
export const productLabelForShip = row => {
  if (!row) return "产品";
  const parts = [row.productCategory, row.floorCode, row.specificationModel].filter(Boolean);
  return parts.length ? parts.join(" / ") : row.productName || row.goodsName || "产品";
};
/** åˆ¤æ–­æ˜¯å¦å­˜åœ¨å·²å‘货、部分发货或已有发货痕迹的产品(删除台账等场景) */
export const hasShippedProducts = products => {
  if (!products || products.length === 0) return false;
  return products.some(p => {
    const statusCode = normalizeShippingStatusToCode(p.deliveryStatus ?? p.shippingStatus);
    const statusStr = (p.shippingStatus ?? "").toString().trim();
    return (
      statusCode === 5 ||
      statusCode === 6 ||
      statusStr === "已发货" ||
      statusStr === "发货完成" ||
      statusStr === "已完成发货" ||
      statusStr === "部分发货" ||
      statusStr === "部分已发货" ||
      !!p.shippingDate ||
      !!p.shippingCarNumber
    );
  });
};
const showLoadingToast = message => {
  uni.showLoading({ title: message, mask: true });
};
const closeToast = () => {
  uni.hideLoading();
};
/**
 * ä¸Žé”€å”®å°è´¦ã€Œå‘货」按钮一致:校验台账状态 â†’ æ‹‰äº§å“ â†’ æ ¡éªŒåº“存与可发货行 â†’ è·³è½¬ goOut
 * @param {Record<string, any>} ledgerItem è‡³å°‘含 id;含发货审批字段时先做 canLedgerShip æ ¡éªŒ
 */
export async function executeSalesLedgerShip(ledgerItem) {
  if (!canLedgerShip(ledgerItem)) {
    uni.showToast({
      title: "仅未发货、审批不通过或部分发货时可继续发货",
      icon: "none",
    });
    return;
  }
  if (!ledgerItem?.id) return;
  showLoadingToast("加载中...");
  try {
    const res = await productList({ salesLedgerId: ledgerItem.id, type: 1 });
    const products = res.data || res.records || [];
    closeToast();
    if (!products.length) {
      uni.showToast({ title: "没有产品数据", icon: "none" });
      return;
    }
    const insufficient = products.filter(p => p?.approveStatus !== 1);
    if (insufficient.length) {
      const names = insufficient.slice(0, 3).map(productLabelForShip).join("、");
      uni.showToast({
        title: `存在库存不足产品:${names}${insufficient.length > 3 ? "…" : ""}`,
        icon: "none",
        duration: 2500,
      });
      return;
    }
    const unOutbound = products.filter(p => isProductStockStatusUnOutbound(p));
    if (unOutbound.length) {
      const names = unOutbound.slice(0, 3).map(productLabelForShip).join("、");
      uni.showToast({
        title: `存在未出库产品,不能发货:${names}${unOutbound.length > 3 ? "…" : ""}`,
        icon: "none",
        duration: 2500,
      });
      return;
    }
    const row = products.find(p => canShipProductRow(p));
    if (!row) {
      uni.showToast({
        title: "没有可发货的产品(待发货、审核拒绝或部分发货可继续)",
        icon: "none",
        duration: 2500,
      });
      return;
    }
    uni.setStorageSync("goOutData", JSON.stringify(row));
    uni.navigateTo({
      url: "/pages/sales/salesAccount/goOut",
    });
  } catch (e) {
    closeToast();
    uni.showToast({ title: "加载产品失败", icon: "none" });
  }
}