diff --git a/src/pages/fulfillment/OrderFulfillmentCreate.vue b/src/pages/fulfillment/OrderFulfillmentCreate.vue
index 34a5a3b..72889f3 100644
--- a/src/pages/fulfillment/OrderFulfillmentCreate.vue
+++ b/src/pages/fulfillment/OrderFulfillmentCreate.vue
@@ -48,31 +48,33 @@
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
/>
-
-
-
-
-
-
+
+
+ 全部履约
+
@@ -174,7 +176,7 @@ import {
mergeProductStockRequirements
} from "@/utils/productStock";
import { uploadPhotoList } from "@/utils/photo";
-import { getProductPhotoURL } from "@/utils/product";
+import { getProductPhotoURL, getProductQuantityStep } from "@/utils/product";
defineOptions({ name: "OrderFulfillmentCreate" });
const route = useRoute();
@@ -182,7 +184,7 @@ const router = useRouter();
const navBarStore = useNavBarStore();
const userStore = useUserStore();
const order = ref();
-const quantityMap = reactive>({});
+const quantityMap = reactive>({});
const fulfillmentSkuMap = reactive>({});
const fulfillmentUnitMap = reactive>({});
const deliveredAtText = ref("");
@@ -199,6 +201,7 @@ const directVerify = ref(false);
const isStockChecking = ref(false);
const stockPreviewList = ref([]);
let stockCheckToken = 0;
+let stockPreviewTimer: number | undefined;
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const isPackage = computed(() => order.value?.orderType === "PACKAGE");
const expectedItemType = computed(() => isPackage.value ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT");
@@ -258,7 +261,11 @@ async function loadFulfillmentSkuList(): Promise {
}
}));
for (const item of sourceItems.value) {
- if (!item.id || fulfillmentUnitMap[item.id]) {
+ if (!item.id) {
+ continue;
+ }
+ quantityMap[item.id] ??= 0;
+ if (fulfillmentUnitMap[item.id]) {
continue;
}
const originalUnit = getFulfillmentUnitList(item).find(unit => unit.id === item.skuUnitId);
@@ -287,6 +294,15 @@ function getItemDescription(item: GaoSalesOrderItem): string {
return `可履约 ${getAvailableQuantity(item)} ${getFulfillmentUnit(item)?.name || getBaseUnitName(item)}`;
}
+function allowsDecimalQuantity(item: GaoSalesOrderItem): boolean {
+ const sku = item.skuId ? fulfillmentSkuMap[item.skuId] : undefined;
+ return sku?.allowDecimalQuantity ?? item.allowDecimalQuantity ?? false;
+}
+
+function getQuantityStep(item: GaoSalesOrderItem): number {
+ return getProductQuantityStep({ allowDecimalQuantity: allowsDecimalQuantity(item) });
+}
+
function getBaseUnitName(item: GaoSalesOrderItem): string {
return getBaseUnit(item)?.name || "基础单位";
}
@@ -417,7 +433,7 @@ function buildAttachments(): Partial[] {
async function validateDirectStock(showShortageMessage = true): Promise {
stockPreviewList.value = [];
- const selected = sourceItems.value.filter(item => !!item.id && quantityMap[item.id]);
+ const selected = sourceItems.value.filter(hasFulfillmentQuantity);
const skuMap = new Map();
for (const item of selected) {
if (!item.skuId) {
@@ -495,6 +511,24 @@ async function refreshStockPreview(): Promise {
await previewDirectStock(!directVerify.value);
}
+function scheduleStockPreview(): void {
+ if (!directVerify.value && !stockPreviewList.value.length) {
+ return;
+ }
+ window.clearTimeout(stockPreviewTimer);
+ stockPreviewTimer = window.setTimeout(async () => {
+ await refreshStockPreview();
+ }, 250);
+}
+
+function hasFulfillmentQuantity(item: GaoSalesOrderItem): boolean {
+ if (!item.id) {
+ return false;
+ }
+ const quantity = quantityMap[item.id];
+ return !!quantity && (normalizePackageQuantity(quantity) === undefined || 0 < comparePackageQuantity(quantity, "0"));
+}
+
function validate(): boolean {
if (!order.value?.id) {
Message.warning("请从订单详情进入履约创建");
@@ -512,7 +546,7 @@ function validate(): boolean {
Message.warning("履约必须上传至少一张照片");
return false;
}
- const selected = sourceItems.value.filter(item => !!item.id && quantityMap[item.id]);
+ const selected = sourceItems.value.filter(hasFulfillmentQuantity);
if (!selected.length) {
Message.warning("请填写至少一项履约数量");
return false;
@@ -520,7 +554,7 @@ function validate(): boolean {
for (const item of selected) {
const quantity = normalizePackageQuantity(quantityMap[item.id || ""]);
const unit = getFulfillmentUnit(item);
- if (!quantity || !unit) {
+ if (!quantity || !unit || !(0 < comparePackageQuantity(quantity, "0"))) {
Message.warning("履约数量必须是正数,最多三位小数");
return false;
}
@@ -548,7 +582,7 @@ async function save(): Promise {
isSaving.value = true;
try {
const itemList: GaoOrderFulfillmentItemRequest[] = sourceItems.value
- .filter(item => !!item.id && quantityMap[item.id])
+ .filter(hasFulfillmentQuantity)
.map(item => ({
sourceOrderItemId: item.id!,
skuUnitId: fulfillmentUnitMap[item.id!]!,
@@ -584,7 +618,10 @@ onMounted(async () => {
navBarStore.setRightText("提交", "var(--td-brand-color)", save);
await loadData();
});
-onUnmounted(() => navBarStore.clearRight());
+onUnmounted(() => {
+ window.clearTimeout(stockPreviewTimer);
+ navBarStore.clearRight();
+});