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")));
|
&& 0 < comparePackageQuantity(item.availableBaseQuantity ?? "0", "0")));
|
||||||
const unitPickerOptions = computed(() => {
|
const unitPickerOptions = computed(() => {
|
||||||
const item = sourceItems.value.find(value => value.id === unitPickerSourceItemId.value);
|
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));
|
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]) {
|
if (!item.id || fulfillmentUnitMap[item.id]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const originalUnit = getSellableUnitList(item).find(unit => unit.id === item.skuUnitId);
|
const originalUnit = getFulfillmentUnitList(item).find(unit => unit.id === item.skuUnitId);
|
||||||
const defaultUnit = getFulfillmentUnitForAvailableQuantity(item, originalUnit || getSellableUnitList(item)[0]);
|
const defaultUnit = getFulfillmentUnitForAvailableQuantity(item, originalUnit || getFulfillmentUnitList(item)[0]);
|
||||||
if (defaultUnit?.id) {
|
if (defaultUnit?.id) {
|
||||||
fulfillmentUnitMap[item.id] = defaultUnit.id;
|
fulfillmentUnitMap[item.id] = defaultUnit.id;
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ function getBaseUnitName(item: GaoSalesOrderItem): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getBaseUnit(item: GaoSalesOrderItem): ProductSkuUnit | undefined {
|
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 {
|
function shouldDowngradeUnit(item: GaoSalesOrderItem, unit?: ProductSkuUnit): boolean {
|
||||||
@@ -254,12 +254,25 @@ function fillAllQuantity(item: GaoSalesOrderItem): void {
|
|||||||
quantityMap[item.id] = quantity;
|
quantityMap[item.id] = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSellableUnitList(item: GaoSalesOrderItem): ProductSkuUnit[] {
|
function getFulfillmentUnitList(item: GaoSalesOrderItem): ProductSkuUnit[] {
|
||||||
return (item.skuId ? fulfillmentSkuMap[item.skuId]?.unitList : [])?.filter(unit => unit.allowSale !== false && !!unit.id) || [];
|
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 {
|
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 {
|
function setFulfillmentUnit(item: GaoSalesOrderItem, unit: ProductSkuUnit): void {
|
||||||
@@ -282,19 +295,19 @@ function openUnitPicker(item: GaoSalesOrderItem): void {
|
|||||||
if (!item.id) {
|
if (!item.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!getSellableUnitList(item).length) {
|
if (!getFulfillmentUnitList(item).length) {
|
||||||
Message.warning("当前 SKU 没有可用于履约的销售单位");
|
Message.warning("当前 SKU 没有可用于履约的单位");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unitPickerSourceItemId.value = item.id;
|
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;
|
unitPickerVisible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmUnitPicker(value: Array<string | number>): void {
|
function confirmUnitPicker(value: Array<string | number>): void {
|
||||||
const skuUnitId = String(value[0] || "");
|
const skuUnitId = String(value[0] || "");
|
||||||
const item = sourceItems.value.find(sourceItem => sourceItem.id === unitPickerSourceItemId.value);
|
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;
|
const fulfillmentUnit = item ? getFulfillmentUnitForAvailableQuantity(item, selectedUnit) : selectedUnit;
|
||||||
if (item?.id && fulfillmentUnit?.id) {
|
if (item?.id && fulfillmentUnit?.id) {
|
||||||
setFulfillmentUnit(item, fulfillmentUnit);
|
setFulfillmentUnit(item, fulfillmentUnit);
|
||||||
|
|||||||
@@ -418,11 +418,19 @@ function closeBatchUnitEditor(): void {
|
|||||||
|
|
||||||
function applyBatchUnitTemplate(): void {
|
function applyBatchUnitTemplate(): void {
|
||||||
const templateList = batchUnitList.value;
|
const templateList = batchUnitList.value;
|
||||||
|
for (const sku of form.skuList) {
|
||||||
|
const templateNameSet = new Set(templateList.map(unit => unit.name.trim()));
|
||||||
|
if (sku.unitList.some(unit => !!unit.id && !templateNameSet.has(unit.name.trim()))) {
|
||||||
|
Message.warning("统一配置不能删除或重命名已保存单位,请在 SKU 明细中停售");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
form.skuList.forEach(sku => {
|
form.skuList.forEach(sku => {
|
||||||
const oldUnitList = sku.unitList;
|
const oldUnitList = sku.unitList;
|
||||||
|
const oldUnitMap = new Map(oldUnitList.filter(unit => !!unit.id).map(unit => [unit.name.trim(), unit]));
|
||||||
sku.unitList = templateList.map((unit, unitIndex) => ({
|
sku.unitList = templateList.map((unit, unitIndex) => ({
|
||||||
...unit,
|
...unit,
|
||||||
id: oldUnitList[unitIndex]?.id,
|
id: oldUnitMap.get(unit.name.trim())?.id,
|
||||||
skuId: sku.id,
|
skuId: sku.id,
|
||||||
clientKey: window.crypto.randomUUID(),
|
clientKey: window.crypto.randomUUID(),
|
||||||
sort: unitIndex
|
sort: unitIndex
|
||||||
|
|||||||
@@ -28,7 +28,15 @@
|
|||||||
<div v-for="(unit, unitIndex) in sku.unitList" :key="unit.clientKey" class="unit-card">
|
<div v-for="(unit, unitIndex) in sku.unitList" :key="unit.clientKey" class="unit-card">
|
||||||
<div class="unit-card-header">
|
<div class="unit-card-header">
|
||||||
<strong v-text="`单位 ${unitIndex + 1}`" />
|
<strong v-text="`单位 ${unitIndex + 1}`" />
|
||||||
<t-button v-if="1 < sku.unitList.length" theme="danger" variant="text" size="extra-small" content="删除" @click="removeUnit(unitIndex)" />
|
<t-button
|
||||||
|
v-if="1 < sku.unitList.length"
|
||||||
|
theme="danger"
|
||||||
|
variant="text"
|
||||||
|
size="extra-small"
|
||||||
|
:content="unit.id ? '停售' : '删除'"
|
||||||
|
:disabled="!!unit.id && unit.allowSale === false && unit.allowPurchase === false"
|
||||||
|
@click="removeUnit(unitIndex)"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<t-form class="unit-form" label-align="left" label-width="6rem">
|
<t-form class="unit-form" label-align="left" label-width="6rem">
|
||||||
<t-form-item label="单位名称" required-mark>
|
<t-form-item label="单位名称" required-mark>
|
||||||
@@ -134,6 +142,13 @@ function removeUnit(index: number): void {
|
|||||||
Message.warning("每个 SKU 至少需要一个单位");
|
Message.warning("每个 SKU 至少需要一个单位");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const unit = sku.value.unitList[index];
|
||||||
|
if (unit?.id) {
|
||||||
|
unit.allowSale = false;
|
||||||
|
unit.allowPurchase = false;
|
||||||
|
Message.success("单位已停售并禁止采购,历史订单仍可履约");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const wasBase = sku.value.unitList[index]?.isBase;
|
const wasBase = sku.value.unitList[index]?.isBase;
|
||||||
sku.value.unitList.splice(index, 1);
|
sku.value.unitList.splice(index, 1);
|
||||||
if (wasBase && sku.value.unitList[0]) {
|
if (wasBase && sku.value.unitList[0]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user