t-stepper for quantity
This commit is contained in:
@@ -48,25 +48,26 @@
|
|||||||
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
:fallback="item.specSummarySnapshot || item.skuNameSnapshot"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<t-input
|
<div class="quantity">
|
||||||
v-model.trim="quantityMap[item.id || '']"
|
<t-stepper
|
||||||
class="quantity"
|
v-model="quantityMap[item.id || '']"
|
||||||
type="number"
|
class="stepper"
|
||||||
borderless
|
size="large"
|
||||||
align="right"
|
:max="Number.MAX_SAFE_INTEGER"
|
||||||
|
:min="0"
|
||||||
|
:step="getQuantityStep(item)"
|
||||||
|
:integer="!allowsDecimalQuantity(item)"
|
||||||
:disabled="!getFulfillmentUnit(item)"
|
:disabled="!getFulfillmentUnit(item)"
|
||||||
placeholder="请输入履约数量"
|
theme="outline"
|
||||||
@change="refreshStockPreview"
|
@change="scheduleStockPreview"
|
||||||
>
|
/>
|
||||||
<template #suffix-icon>
|
|
||||||
<t-button
|
<t-button
|
||||||
|
class="unit"
|
||||||
size="extra-small"
|
size="extra-small"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
:content="getFulfillmentUnit(item)?.name || '选择实际单位'"
|
:content="getFulfillmentUnit(item)?.name || '选择实际单位'"
|
||||||
@click.stop="openUnitPicker(item)"
|
@click.stop="openUnitPicker(item)"
|
||||||
/>
|
/>
|
||||||
</template>
|
|
||||||
</t-input>
|
|
||||||
<t-button
|
<t-button
|
||||||
size="extra-small"
|
size="extra-small"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -76,6 +77,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
</t-form>
|
</t-form>
|
||||||
<div v-else class="empty" v-text="'暂无可履约明细,请返回订单详情检查'" />
|
<div v-else class="empty" v-text="'暂无可履约明细,请返回订单详情检查'" />
|
||||||
@@ -174,7 +176,7 @@ import {
|
|||||||
mergeProductStockRequirements
|
mergeProductStockRequirements
|
||||||
} from "@/utils/productStock";
|
} from "@/utils/productStock";
|
||||||
import { uploadPhotoList } from "@/utils/photo";
|
import { uploadPhotoList } from "@/utils/photo";
|
||||||
import { getProductPhotoURL } from "@/utils/product";
|
import { getProductPhotoURL, getProductQuantityStep } from "@/utils/product";
|
||||||
|
|
||||||
defineOptions({ name: "OrderFulfillmentCreate" });
|
defineOptions({ name: "OrderFulfillmentCreate" });
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -182,7 +184,7 @@ const router = useRouter();
|
|||||||
const navBarStore = useNavBarStore();
|
const navBarStore = useNavBarStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const order = ref<SalesOrder>();
|
const order = ref<SalesOrder>();
|
||||||
const quantityMap = reactive<Record<string, string>>({});
|
const quantityMap = reactive<Record<string, string | number>>({});
|
||||||
const fulfillmentSkuMap = reactive<Record<string, ProductSku>>({});
|
const fulfillmentSkuMap = reactive<Record<string, ProductSku>>({});
|
||||||
const fulfillmentUnitMap = reactive<Record<string, string>>({});
|
const fulfillmentUnitMap = reactive<Record<string, string>>({});
|
||||||
const deliveredAtText = ref("");
|
const deliveredAtText = ref("");
|
||||||
@@ -199,6 +201,7 @@ const directVerify = ref(false);
|
|||||||
const isStockChecking = ref(false);
|
const isStockChecking = ref(false);
|
||||||
const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
|
const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
|
||||||
let stockCheckToken = 0;
|
let stockCheckToken = 0;
|
||||||
|
let stockPreviewTimer: number | undefined;
|
||||||
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
|
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
|
||||||
const isPackage = computed(() => order.value?.orderType === "PACKAGE");
|
const isPackage = computed(() => order.value?.orderType === "PACKAGE");
|
||||||
const expectedItemType = computed(() => isPackage.value ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT");
|
const expectedItemType = computed(() => isPackage.value ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT");
|
||||||
@@ -258,7 +261,11 @@ async function loadFulfillmentSkuList(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
for (const item of sourceItems.value) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
const originalUnit = getFulfillmentUnitList(item).find(unit => unit.id === item.skuUnitId);
|
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)}`;
|
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 {
|
function getBaseUnitName(item: GaoSalesOrderItem): string {
|
||||||
return getBaseUnit(item)?.name || "基础单位";
|
return getBaseUnit(item)?.name || "基础单位";
|
||||||
}
|
}
|
||||||
@@ -417,7 +433,7 @@ function buildAttachments(): Partial<Attachment>[] {
|
|||||||
|
|
||||||
async function validateDirectStock(showShortageMessage = true): Promise<boolean> {
|
async function validateDirectStock(showShortageMessage = true): Promise<boolean> {
|
||||||
stockPreviewList.value = [];
|
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>();
|
const skuMap = new Map<string, ProductSku>();
|
||||||
for (const item of selected) {
|
for (const item of selected) {
|
||||||
if (!item.skuId) {
|
if (!item.skuId) {
|
||||||
@@ -495,6 +511,24 @@ async function refreshStockPreview(): Promise<void> {
|
|||||||
await previewDirectStock(!directVerify.value);
|
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 {
|
function validate(): boolean {
|
||||||
if (!order.value?.id) {
|
if (!order.value?.id) {
|
||||||
Message.warning("请从订单详情进入履约创建");
|
Message.warning("请从订单详情进入履约创建");
|
||||||
@@ -512,7 +546,7 @@ function validate(): boolean {
|
|||||||
Message.warning("履约必须上传至少一张照片");
|
Message.warning("履约必须上传至少一张照片");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const selected = sourceItems.value.filter(item => !!item.id && quantityMap[item.id]);
|
const selected = sourceItems.value.filter(hasFulfillmentQuantity);
|
||||||
if (!selected.length) {
|
if (!selected.length) {
|
||||||
Message.warning("请填写至少一项履约数量");
|
Message.warning("请填写至少一项履约数量");
|
||||||
return false;
|
return false;
|
||||||
@@ -520,7 +554,7 @@ function validate(): boolean {
|
|||||||
for (const item of selected) {
|
for (const item of selected) {
|
||||||
const quantity = normalizePackageQuantity(quantityMap[item.id || ""]);
|
const quantity = normalizePackageQuantity(quantityMap[item.id || ""]);
|
||||||
const unit = getFulfillmentUnit(item);
|
const unit = getFulfillmentUnit(item);
|
||||||
if (!quantity || !unit) {
|
if (!quantity || !unit || !(0 < comparePackageQuantity(quantity, "0"))) {
|
||||||
Message.warning("履约数量必须是正数,最多三位小数");
|
Message.warning("履约数量必须是正数,最多三位小数");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -548,7 +582,7 @@ async function save(): Promise<void> {
|
|||||||
isSaving.value = true;
|
isSaving.value = true;
|
||||||
try {
|
try {
|
||||||
const itemList: GaoOrderFulfillmentItemRequest[] = sourceItems.value
|
const itemList: GaoOrderFulfillmentItemRequest[] = sourceItems.value
|
||||||
.filter(item => !!item.id && quantityMap[item.id])
|
.filter(hasFulfillmentQuantity)
|
||||||
.map(item => ({
|
.map(item => ({
|
||||||
sourceOrderItemId: item.id!,
|
sourceOrderItemId: item.id!,
|
||||||
skuUnitId: fulfillmentUnitMap[item.id!]!,
|
skuUnitId: fulfillmentUnitMap[item.id!]!,
|
||||||
@@ -584,7 +618,10 @@ onMounted(async () => {
|
|||||||
navBarStore.setRightText("提交", "var(--td-brand-color)", save);
|
navBarStore.setRightText("提交", "var(--td-brand-color)", save);
|
||||||
await loadData();
|
await loadData();
|
||||||
});
|
});
|
||||||
onUnmounted(() => navBarStore.clearRight());
|
onUnmounted(() => {
|
||||||
|
window.clearTimeout(stockPreviewTimer);
|
||||||
|
navBarStore.clearRight();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
@@ -675,6 +712,7 @@ onUnmounted(() => navBarStore.clearRight());
|
|||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
margin-top: .5rem;
|
margin-top: .5rem;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
.sku-tags {
|
.sku-tags {
|
||||||
gap: .375rem;
|
gap: .375rem;
|
||||||
@@ -683,6 +721,13 @@ onUnmounted(() => navBarStore.clearRight());
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.quantity {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
min-width: 0;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: end;
|
||||||
|
|
||||||
.unit {
|
.unit {
|
||||||
font-size: .875rem;
|
font-size: .875rem;
|
||||||
}
|
}
|
||||||
@@ -691,6 +736,7 @@ onUnmounted(() => navBarStore.clearRight());
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.time-actions {
|
.time-actions {
|
||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user