t-stepper for quantity
This commit is contained in:
@@ -48,31 +48,33 @@
|
||||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
||||
/>
|
||||
</div>
|
||||
<t-input
|
||||
v-model.trim="quantityMap[item.id || '']"
|
||||
class="quantity"
|
||||
type="number"
|
||||
borderless
|
||||
align="right"
|
||||
:disabled="!getFulfillmentUnit(item)"
|
||||
placeholder="请输入履约数量"
|
||||
@change="refreshStockPreview"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:content="getFulfillmentUnit(item)?.name || '选择实际单位'"
|
||||
@click.stop="openUnitPicker(item)"
|
||||
/>
|
||||
</template>
|
||||
</t-input>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
<div class="quantity">
|
||||
<t-stepper
|
||||
v-model="quantityMap[item.id || '']"
|
||||
class="stepper"
|
||||
size="large"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:min="0"
|
||||
:step="getQuantityStep(item)"
|
||||
:integer="!allowsDecimalQuantity(item)"
|
||||
:disabled="!getFulfillmentUnit(item)"
|
||||
theme="outline"
|
||||
@change="scheduleStockPreview"
|
||||
/>
|
||||
<t-button
|
||||
class="unit"
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:content="getFulfillmentUnit(item)?.name || '选择实际单位'"
|
||||
@click.stop="openUnitPicker(item)"
|
||||
/>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:disabled="getAvailableBaseQuantity(item) === '0' || (directVerify && isStockChecking)"
|
||||
@click.stop="fillAllQuantity(item)"
|
||||
>全部履约</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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<SalesOrder>();
|
||||
const quantityMap = reactive<Record<string, string>>({});
|
||||
const quantityMap = reactive<Record<string, string | number>>({});
|
||||
const fulfillmentSkuMap = reactive<Record<string, ProductSku>>({});
|
||||
const fulfillmentUnitMap = reactive<Record<string, string>>({});
|
||||
const deliveredAtText = ref("");
|
||||
@@ -199,6 +201,7 @@ const directVerify = ref(false);
|
||||
const isStockChecking = ref(false);
|
||||
const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
|
||||
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<void> {
|
||||
}
|
||||
}));
|
||||
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<Attachment>[] {
|
||||
|
||||
async function validateDirectStock(showShortageMessage = true): Promise<boolean> {
|
||||
stockPreviewList.value = [];
|
||||
const selected = sourceItems.value.filter(item => !!item.id && quantityMap[item.id]);
|
||||
const selected = sourceItems.value.filter(hasFulfillmentQuantity);
|
||||
const skuMap = new Map<string, ProductSku>();
|
||||
for (const item of selected) {
|
||||
if (!item.skuId) {
|
||||
@@ -495,6 +511,24 @@ async function refreshStockPreview(): Promise<void> {
|
||||
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<void> {
|
||||
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();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -675,6 +712,7 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
margin-top: .5rem;
|
||||
flex-direction: column;
|
||||
|
||||
.sku-tags {
|
||||
gap: .375rem;
|
||||
@@ -683,8 +721,16 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.unit {
|
||||
font-size: .875rem;
|
||||
.quantity {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
justify-content: end;
|
||||
|
||||
.unit {
|
||||
font-size: .875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user