fix off product sku for keep fulfillment
This commit is contained in:
@@ -159,7 +159,7 @@ const sourceItems = computed<GaoSalesOrderItem[]>(() => (order.value?.itemList |
|
||||
&& 0 < comparePackageQuantity(item.availableBaseQuantity ?? "0", "0")));
|
||||
const unitPickerOptions = computed(() => {
|
||||
const item = sourceItems.value.find(value => value.id === unitPickerSourceItemId.value);
|
||||
return item ? getSellableUnitList(item).map(unit => ({ label: unit.name, value: unit.id || "" })) : [];
|
||||
return item ? getFulfillmentUnitList(item).map(unit => ({ label: unit.name, value: unit.id || "" })) : [];
|
||||
});
|
||||
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasRoles(gaoRoleCodes.storeManager));
|
||||
|
||||
@@ -191,8 +191,8 @@ async function loadFulfillmentSkuList(): Promise<void> {
|
||||
if (!item.id || fulfillmentUnitMap[item.id]) {
|
||||
continue;
|
||||
}
|
||||
const originalUnit = getSellableUnitList(item).find(unit => unit.id === item.skuUnitId);
|
||||
const defaultUnit = getFulfillmentUnitForAvailableQuantity(item, originalUnit || getSellableUnitList(item)[0]);
|
||||
const originalUnit = getFulfillmentUnitList(item).find(unit => unit.id === item.skuUnitId);
|
||||
const defaultUnit = getFulfillmentUnitForAvailableQuantity(item, originalUnit || getFulfillmentUnitList(item)[0]);
|
||||
if (defaultUnit?.id) {
|
||||
fulfillmentUnitMap[item.id] = defaultUnit.id;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ function getBaseUnitName(item: GaoSalesOrderItem): string {
|
||||
}
|
||||
|
||||
function getBaseUnit(item: GaoSalesOrderItem): ProductSkuUnit | undefined {
|
||||
return getSellableUnitList(item).find(unit => unit.isBase);
|
||||
return getFulfillmentUnitList(item).find(unit => unit.isBase);
|
||||
}
|
||||
|
||||
function shouldDowngradeUnit(item: GaoSalesOrderItem, unit?: ProductSkuUnit): boolean {
|
||||
@@ -254,12 +254,25 @@ function fillAllQuantity(item: GaoSalesOrderItem): void {
|
||||
quantityMap[item.id] = quantity;
|
||||
}
|
||||
|
||||
function getSellableUnitList(item: GaoSalesOrderItem): ProductSkuUnit[] {
|
||||
return (item.skuId ? fulfillmentSkuMap[item.skuId]?.unitList : [])?.filter(unit => unit.allowSale !== false && !!unit.id) || [];
|
||||
function getFulfillmentUnitList(item: GaoSalesOrderItem): ProductSkuUnit[] {
|
||||
const unitList = (item.skuId ? fulfillmentSkuMap[item.skuId]?.unitList : [])?.filter(unit => !!unit.id) || [];
|
||||
if (!item.skuUnitId) {
|
||||
return unitList;
|
||||
}
|
||||
const originalUnit: ProductSkuUnit = {
|
||||
...(unitList.find(unit => unit.id === item.skuUnitId) || {}),
|
||||
id: item.skuUnitId,
|
||||
skuId: item.skuId,
|
||||
name: item.unitSnapshot || "成交单位",
|
||||
baseQuantityPerUnit: item.baseQuantityPerUnitSnapshot ?? "1",
|
||||
allowPurchase: false,
|
||||
allowSale: false
|
||||
};
|
||||
return [originalUnit, ...unitList.filter(unit => unit.id !== item.skuUnitId)];
|
||||
}
|
||||
|
||||
function getFulfillmentUnit(item: GaoSalesOrderItem): ProductSkuUnit | undefined {
|
||||
return getSellableUnitList(item).find(unit => unit.id === fulfillmentUnitMap[item.id || ""]);
|
||||
return getFulfillmentUnitList(item).find(unit => unit.id === fulfillmentUnitMap[item.id || ""]);
|
||||
}
|
||||
|
||||
function setFulfillmentUnit(item: GaoSalesOrderItem, unit: ProductSkuUnit): void {
|
||||
@@ -282,19 +295,19 @@ function openUnitPicker(item: GaoSalesOrderItem): void {
|
||||
if (!item.id) {
|
||||
return;
|
||||
}
|
||||
if (!getSellableUnitList(item).length) {
|
||||
Message.warning("当前 SKU 没有可用于履约的销售单位");
|
||||
if (!getFulfillmentUnitList(item).length) {
|
||||
Message.warning("当前 SKU 没有可用于履约的单位");
|
||||
return;
|
||||
}
|
||||
unitPickerSourceItemId.value = item.id;
|
||||
unitPickerDraft.value = [fulfillmentUnitMap[item.id] || getSellableUnitList(item)[0]?.id || ""];
|
||||
unitPickerDraft.value = [fulfillmentUnitMap[item.id] || getFulfillmentUnitList(item)[0]?.id || ""];
|
||||
unitPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmUnitPicker(value: Array<string | number>): void {
|
||||
const skuUnitId = String(value[0] || "");
|
||||
const item = sourceItems.value.find(sourceItem => sourceItem.id === unitPickerSourceItemId.value);
|
||||
const selectedUnit = item ? getSellableUnitList(item).find(unit => unit.id === skuUnitId) : undefined;
|
||||
const selectedUnit = item ? getFulfillmentUnitList(item).find(unit => unit.id === skuUnitId) : undefined;
|
||||
const fulfillmentUnit = item ? getFulfillmentUnitForAvailableQuantity(item, selectedUnit) : selectedUnit;
|
||||
if (item?.id && fulfillmentUnit?.id) {
|
||||
setFulfillmentUnit(item, fulfillmentUnit);
|
||||
|
||||
Reference in New Issue
Block a user