From 3682ad63b5bdb47228325dea1efe2bb9069254a5 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期一, 11 五月 2026 15:53:18 +0800
Subject: [PATCH] 合格出库扫销售二维码进行发货
---
src/utils/salesLedgerShip.js | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 209 insertions(+), 0 deletions(-)
diff --git a/src/utils/salesLedgerShip.js b/src/utils/salesLedgerShip.js
new file mode 100644
index 0000000..00df9af
--- /dev/null
+++ b/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" });
+ }
+}
--
Gitblit v1.9.3