add product stock preview
This commit is contained in:
@@ -165,11 +165,14 @@
|
||||
<t-switch
|
||||
v-model="fulfillAll"
|
||||
size="small"
|
||||
:disabled="!canFulfillImmediately"
|
||||
:disabled="!canFulfillImmediately || isStockChecking"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<div class="red">全部履约会同步启用全额收款;请先准备全部产品库存,任意一步失败,整张订单都会回滚。</div>
|
||||
<div class="stock-tips">
|
||||
<div class="tips red">全部履约会同步启用全额收款;请先准备充足的库存,任意一步失败都会下单失败。</div>
|
||||
<product-stock-preview v-if="stockPreviewList.length" :items="stockPreviewList" />
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="(paymentVerified && paymentAmount) || (receiveFullPayment && totalAmount)" label-width="0">
|
||||
<photo-scroller
|
||||
@@ -230,6 +233,7 @@ import CodeScanner from "@/components/CodeScanner.vue";
|
||||
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import PhotoScroller from "@/components/PhotoScroller.vue";
|
||||
import ProductStockPreview from "@/components/ProductStockPreview.vue";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { Product, ProductSku, ProductSkuUnit } from "@/types/Product";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
@@ -239,7 +243,8 @@ import { formatProductAmount, getProductQuantityStep } from "@/utils/product";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getProductStockShortageMessage, mergeProductStockRequirements } from "@/utils/productStock";
|
||||
import { buildProductStockPreview, getProductStockShortageMessage, mergeProductStockRequirements } from "@/utils/productStock";
|
||||
import type { ProductStockPreviewItem } from "@/utils/productStock";
|
||||
import { uploadPhotoList } from "@/utils/photo";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import { useSettingStore } from "@/store/settingStore";
|
||||
@@ -269,6 +274,9 @@ const paymentPhotoUrlList = computed(() => paymentPhotoItems.value.map(item => i
|
||||
const fulfillmentPhotoUrlList = computed(() => fulfillmentPhotoItems.value.map(item => item.url));
|
||||
const receiveFullPayment = ref(false);
|
||||
const fulfillAll = ref(false);
|
||||
const isStockChecking = ref(false);
|
||||
const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
|
||||
let stockCheckToken = 0;
|
||||
const paymentAmount = computed(() => parsePackageAmount(paymentAmountText.value));
|
||||
const paymentVerified = computed(() => !receiveFullPayment.value
|
||||
&& 0 < paymentAmountText.value.trim().length
|
||||
@@ -293,9 +301,26 @@ const canFulfillImmediately = computed(() => userStore.hasPermissions(permission
|
||||
&& userStore.hasPermissions(permissionCodes.productStock.read)
|
||||
&& (totalAmount.value === 0 || canReceiveImmediately.value));
|
||||
|
||||
watch(fulfillAll, value => {
|
||||
if (value && totalAmount.value !== 0) {
|
||||
receiveFullPayment.value = true;
|
||||
watch(fulfillAll, async value => {
|
||||
stockCheckToken += 1;
|
||||
const token = stockCheckToken;
|
||||
if (!value) {
|
||||
isStockChecking.value = false;
|
||||
return;
|
||||
}
|
||||
isStockChecking.value = true;
|
||||
try {
|
||||
if (!await validateDirectStock() && token === stockCheckToken && fulfillAll.value) {
|
||||
fulfillAll.value = false;
|
||||
return;
|
||||
}
|
||||
if (token === stockCheckToken && fulfillAll.value && totalAmount.value !== 0) {
|
||||
receiveFullPayment.value = true;
|
||||
}
|
||||
} finally {
|
||||
if (token === stockCheckToken) {
|
||||
isStockChecking.value = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -469,6 +494,7 @@ function buildAttachments(source: PhotoItem[] = photoItems.value): Partial<Attac
|
||||
}
|
||||
|
||||
async function validateDirectStock(): Promise<boolean> {
|
||||
stockPreviewList.value = [];
|
||||
const requirementList = mergeProductStockRequirements(items.value.flatMap(item => {
|
||||
const sku = getSku(item);
|
||||
const unit = getUnit(item);
|
||||
@@ -477,13 +503,14 @@ async function validateDirectStock(): Promise<boolean> {
|
||||
if (!item.skuId || !sku?.stockEnabled || !baseQuantity) {
|
||||
return [];
|
||||
}
|
||||
return [{ skuId: item.skuId, baseQuantity, productName: getProduct(item)?.name || item.productName || "未命名产品", unitName: "基础单位" }];
|
||||
return [{ skuId: item.skuId, baseQuantity, productName: getProduct(item)?.name || item.productName || "未命名产品", unitName: "基础单位", stockEnabled: sku.stockEnabled }];
|
||||
}));
|
||||
if (!requirementList.length) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const stockList = await ProductAPI.stockBatchDetail({ skuIdList: requirementList.map(item => item.skuId) });
|
||||
stockPreviewList.value = buildProductStockPreview(stockList, requirementList);
|
||||
const shortageMessage = getProductStockShortageMessage(stockList, requirementList);
|
||||
if (shortageMessage) {
|
||||
Message.warning(`${shortageMessage},不能直接履约`);
|
||||
@@ -491,6 +518,7 @@ async function validateDirectStock(): Promise<boolean> {
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
stockPreviewList.value = [];
|
||||
Message.error(getErrorMessage(error, "库存查询失败,暂不能直接履约"));
|
||||
return false;
|
||||
}
|
||||
@@ -518,7 +546,12 @@ function validate(): boolean {
|
||||
return true;
|
||||
}
|
||||
async function save(): Promise<void> {
|
||||
if (isSaving.value || !validate()) return;
|
||||
if (isSaving.value) return;
|
||||
if (isStockChecking.value) {
|
||||
Message.warning("库存正在预检,请稍候再提交");
|
||||
return;
|
||||
}
|
||||
if (!validate()) return;
|
||||
if (paymentVerified.value || receiveFullPayment.value || fulfillAll.value) {
|
||||
const dialog = DialogPlugin.confirm({
|
||||
title: "确认直通完成交易",
|
||||
@@ -631,6 +664,10 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
font-size: .875rem;
|
||||
}
|
||||
|
||||
.product-part {
|
||||
|
||||
> .header {
|
||||
@@ -738,10 +775,6 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
.textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.photo-part {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.submit-wrap {
|
||||
|
||||
Reference in New Issue
Block a user