From 1ae3be372c9064d4158dc7b73f1043c144e3690f Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期一, 13 四月 2026 14:45:12 +0800
Subject: [PATCH] refactor: 优化发货状态逻辑和可发货产品判断
---
src/pages/sales/salesAccount/index.vue | 92 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 74 insertions(+), 18 deletions(-)
diff --git a/src/pages/sales/salesAccount/index.vue b/src/pages/sales/salesAccount/index.vue
index cafae6f..3834435 100644
--- a/src/pages/sales/salesAccount/index.vue
+++ b/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;
+
+ // 浜у搧鐘舵�佸繀椤绘槸鍏呰冻锛坅pproveStatus === 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",
--
Gitblit v1.9.3