auto complete order

This commit is contained in:
Timi
2026-09-13 01:25:37 +08:00
parent 8d9d0c4591
commit 6cce293683
9 changed files with 317 additions and 28 deletions
+97 -3
View File
@@ -136,6 +136,41 @@
/>
</div>
</t-form-item>
<t-form-item label="已全额收款和核销" content-align="right">
<t-switch
v-model="receiveFullPayment"
size="small"
:disabled="!canReceiveImmediately"
/>
</t-form-item>
<t-form-item label="已全部产品履约和核销" content-align="right">
<t-switch
v-model="fulfillAll"
size="small"
:disabled="!canFulfillImmediately"
/>
</t-form-item>
<t-form-item label-width="0">
<div class="red">全部履约会同步启用全额收款;请先准备全部产品库存,任意一步失败,整张订单都会回滚。</div>
</t-form-item>
<t-form-item v-if="receiveFullPayment && totalAmount" label-width="0">
<photo-scroller
:model-value="paymentPhotoUrlList"
v-model:photo-items="paymentPhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="收款凭证照片(必要)"
/>
</t-form-item>
<t-form-item v-if="fulfillAll" label-width="0">
<photo-scroller
:model-value="fulfillmentPhotoUrlList"
v-model:photo-items="fulfillmentPhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="履约凭证照片(必要)"
/>
</t-form-item>
<t-form-item label="订单备注">
<t-textarea v-model="remark" class="textarea" borderless autosize maxlength="500" placeholder="记录本单需要注意的内容" />
</t-form-item>
@@ -169,6 +204,7 @@
<script setup lang="ts">
import { type Attachment, useUserStore } from "timi-web-api";
import { Time } from "timi-web";
import { DialogPlugin } from "tdesign-mobile-vue";
import CustomerAPI from "@/api/CustomerAPI";
import ProductAPI from "@/api/ProductAPI";
import SalesOrderAPI from "@/api/SalesOrderAPI";
@@ -206,7 +242,11 @@ const draftTime = ref("");
const pickerVisible = ref(false);
const isSaving = ref(false);
const photoItems = ref<PhotoItem[]>([]);
const paymentPhotoItems = ref<PhotoItem[]>([]);
const fulfillmentPhotoItems = ref<PhotoItem[]>([]);
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const paymentPhotoUrlList = computed(() => paymentPhotoItems.value.map(item => item.url));
const fulfillmentPhotoUrlList = computed(() => fulfillmentPhotoItems.value.map(item => item.url));
const maxQuantity = Number.MAX_SAFE_INTEGER;
const productCache = new Map<string, Product>();
const skuCache = new Map<string, ProductSku>();
@@ -218,6 +258,28 @@ const scannerVisible = ref(false);
const scanStatus = ref("点击扫码开始识别。");
let latestDecodedText = "";
// ---------- 交易直通 ----------
const receiveFullPayment = ref(false);
const fulfillAll = ref(false);
const canReceiveImmediately = computed(() => userStore.hasPermissions(permissionCodes.fundReceive.create)
&& userStore.hasPermissions(permissionCodes.fundReceive.verify));
const canFulfillImmediately = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.create)
&& userStore.hasPermissions(permissionCodes.orderFulfillment.verify)
&& (totalAmount.value === 0 || canReceiveImmediately.value));
watch(fulfillAll, value => {
if (value && totalAmount.value !== 0) {
receiveFullPayment.value = true;
}
});
watch(receiveFullPayment, value => {
if (!value && totalAmount.value !== 0) {
fulfillAll.value = false;
}
});
function getSku(item: FormItem): ProductSku | undefined {
return skuCache.get(item.skuId || "");
}
@@ -376,8 +438,8 @@ function resolveTimestamp(value: string): number | undefined {
const timestamp = new Date(value.replace(" ", "T")).getTime();
return Number.isFinite(timestamp) ? timestamp : undefined;
}
function buildAttachments(): Partial<Attachment>[] {
return photoItems.value.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
function buildAttachments(source: PhotoItem[] = photoItems.value): Partial<Attachment>[] {
return source.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
}
function validate(): boolean {
if (!customer.value?.id) { Message.warning("请选择客户"); return false; }
@@ -392,10 +454,36 @@ function validate(): boolean {
keys.add(key);
if (canPriceOverride.value && item.unitPriceText && parsePackageAmount(item.unitPriceText) === undefined) { Message.warning("成交单价必须是合法金额"); return false; }
}
if (receiveFullPayment.value && !canReceiveImmediately.value) { Message.warning("当前账号没有收款登记和核销权限"); return false; }
if (fulfillAll.value && !canFulfillImmediately.value) { Message.warning("当前账号没有交易直通所需权限"); return false; }
if (fulfillAll.value && totalAmount.value !== 0 && !receiveFullPayment.value) { Message.warning("全部履约直通必须同时直接全额收款"); return false; }
if (receiveFullPayment.value && totalAmount.value && !buildAttachments(paymentPhotoItems.value).length) { Message.warning("直接全额收款必须上传收款凭证照片"); return false; }
if (fulfillAll.value && !buildAttachments(fulfillmentPhotoItems.value).length) { Message.warning("全部履约直通必须上传履约凭证照片"); return false; }
return true;
}
async function save(): Promise<void> {
if (isSaving.value || !validate()) return;
if (receiveFullPayment.value || fulfillAll.value) {
const dialog = DialogPlugin.confirm({
title: "确认直通完成交易",
content: fulfillAll.value
? "将一次性创建订单、核销全额收款,并完成全部履约和库存扣减。提交后如需更正,只能走撤销或冲正流程。"
: "将一次性创建订单并核销全额收款。提交后如需更正,只能走资金冲正流程。",
cancelBtn: "取消",
confirmBtn: "确认并提交",
onCancel() {
dialog.destroy();
},
async onConfirm() {
dialog.destroy();
await submitOrder();
}
});
return;
}
await submitOrder();
}
async function submitOrder(): Promise<void> {
if (!requestNo.value) requestNo.value = createPackageRequestNo();
isSaving.value = true;
try {
@@ -413,9 +501,15 @@ async function save(): Promise<void> {
purchasedAt: resolveTimestamp(purchasedAtText.value),
itemList,
attachmentList: buildAttachments(),
straightThrough: receiveFullPayment.value || fulfillAll.value ? {
receiveFullPayment: receiveFullPayment.value,
paymentAttachmentList: buildAttachments(paymentPhotoItems.value),
fulfillAll: fulfillAll.value,
fulfillmentAttachmentList: buildAttachments(fulfillmentPhotoItems.value)
} : undefined,
remark: remark.value.trim() || null
});
Message.success("销售订单已创建");
Message.success(fulfillAll.value ? "订单、收款及履约已完成" : receiveFullPayment.value ? "订单及全额收款已完成" : "销售订单已创建");
await router.replace(`/management/sales-orders/${result.id}`);
} catch (error) {
const message = getErrorMessage(error, "销售订单创建失败,重试会复用同一请求号");