cancel sale order with fulfillment and fund record

This commit is contained in:
Timi
2026-10-28 00:33:53 +08:00
parent cf132fd8fe
commit e71c0e8a4e
29 changed files with 1791 additions and 142 deletions
+5 -1
View File
@@ -6,6 +6,7 @@ import type {
FulfillmentPageResult,
FulfillmentPrepareStockRequest,
FulfillmentRevokeRequest,
FulfillmentReturnRequest,
OrderFulfillment,
OrderFulfillmentCreateRequest,
QuickFulfillmentCreateRequest,
@@ -50,5 +51,8 @@ async function cancel(request: FulfillmentActionRequest): Promise<OrderFulfillme
async function revoke(request: FulfillmentRevokeRequest): Promise<OrderFulfillment> {
return await axios.post(`${URI}/revoke`, request);
}
async function returnGoods(request: FulfillmentReturnRequest): Promise<OrderFulfillment> {
return await axios.post(`${URI}/return`, request);
}
export default { list, detail, create, createAndVerify, quickSkuList, quickSourceOrderList, quickCreate, prepareStock, verify, reject, cancel, revoke };
export default { list, detail, create, createAndVerify, quickSkuList, quickSourceOrderList, quickCreate, prepareStock, verify, reject, cancel, revoke, returnGoods };
+13 -6
View File
@@ -152,13 +152,20 @@ html.theme-dark body {
}
}
.page-content.scroll.list {
padding-top: 0;
padding-bottom: 0;
.page-content.scroll {
.pull-refresh {
padding-top: calc(48px + 1rem);
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
&.notice {
padding-top: var(--app-nav-height);
}
&.list {
padding-top: 0;
padding-bottom: 0;
.pull-refresh {
padding-top: calc(var(--app-nav-height) + 1rem);
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
}
}
}
}
@@ -17,6 +17,11 @@
<time-label :timestamp="fulfillment.deliveredAt" underline />
</template>
</t-cell>
<t-cell v-if="fulfillment.returnedAt" title="退货时间">
<template #note>
<time-label :timestamp="fulfillment.returnedAt" underline />
</template>
</t-cell>
<t-cell title="提交人" :note="fulfillment.operator?.nick || fulfillment.operator?.name || fulfillment.operatorUserId || '未知'" />
<t-cell title="处理人" :note="fulfillment.verifier?.nick || fulfillment.verifier?.name || fulfillment.verifierUserId || '未处理'" />
<t-cell v-if="fulfillment.reason" title="原因" :note="fulfillment.reason" />
@@ -73,7 +78,7 @@
<product-stock-preview v-else-if="stockPreviewList.length" :items="stockPreviewList" />
</section>
<section
v-if="(!isOrderCancelled && isWaitingStock && (canVerify || canCreate)) || (!isOrderCancelled && isPending && (canVerify || canCreate)) || (isVerified && canRevoke)"
v-if="(!isOrderCancelled && isWaitingStock && (canVerify || canCreate)) || (!isOrderCancelled && isPending && (canVerify || canCreate)) || (isVerified && (canReturn || canRevoke))"
class="actions"
v-entrance-transition
>
@@ -93,6 +98,12 @@
content="撤销履约"
@click="openReason('cancel')"
/>
<t-button
v-if="isVerified && canReturn"
theme="primary"
content="履约退货"
@click="returnVisible = true"
/>
<t-button
v-if="isVerified && canRevoke"
theme="danger"
@@ -151,6 +162,12 @@
:fulfillment="fulfillment"
@success="loadData"
/>
<order-fulfillment-return
v-if="fulfillment"
v-model:visible="returnVisible"
:fulfillment="fulfillment"
@success="loadData"
/>
</div>
</template>
@@ -164,6 +181,7 @@ import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelect
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import ProductStockPreview from "@/components/ProductStockPreview.vue";
import OrderFulfillmentRevoke from "@/pages/fulfillment/components/OrderFulfillmentRevoke.vue";
import OrderFulfillmentReturn from "@/pages/fulfillment/components/OrderFulfillmentReturn.vue";
import type { GaoSalesOrderItemType, SalesOrder } from "@/types/SalesOrder";
import type { PhotoItem } from "@/types/Photo";
import { addPackageQuantity, getPackageQuantityText } from "@/utils/package";
@@ -195,6 +213,7 @@ const reasonPickerVisible = ref(false);
const reasonPickerDraft = ref<string[]>([]);
const reasonPickerZIndex = 12001;
const revokeVisible = ref(false);
const returnVisible = ref(false);
const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
const stockPreviewLoading = ref(false);
const fulfillmentPhotoItems = computed<PhotoItem[]>(() => (fulfillment.value?.attachmentList || [])
@@ -212,6 +231,7 @@ const isOrderCancelled = computed(() => order.value?.status === "CANCELLED");
const canVerify = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.verify));
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.create));
const canRevoke = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.revoke));
const canReturn = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.return));
const reasonOptions: Record<ReasonAction, string[]> = {
reject: [
"履约信息填写有误",
@@ -251,7 +251,8 @@ const statusOptions = [
{ label: "已核销", value: "VERIFIED" },
{ label: "已拒绝", value: "REJECTED" },
{ label: "已撤销", value: "CANCELLED" },
{ label: "已冲正", value: "REVOKED" }
{ label: "已冲正", value: "REVOKED" },
{ label: "已退货", value: "RETURNED" }
];
const dateFilterLabel = computed(() => dateOptions.find(item => item.value === dateFilterType.value)?.label || "时间范围");
const customerDisplayText = computed(() => selectedCustomer.value?.name || selectedCustomer.value?.code || "");
@@ -278,7 +279,7 @@ function getSkuIdList(value: unknown): string[] {
function getInitialStatus(value: unknown): "ALL" | GaoFulfillmentStatus {
const statusValue = getQueryText(value);
if (["WAITING_STOCK", "PENDING", "VERIFIED", "REJECTED", "CANCELLED", "REVOKED"].includes(statusValue)) {
if (["WAITING_STOCK", "PENDING", "VERIFIED", "REJECTED", "CANCELLED", "REVOKED", "RETURNED"].includes(statusValue)) {
return statusValue as GaoFulfillmentStatus;
}
return "ALL";
@@ -87,7 +87,7 @@ const statusText = computed(() => getFulfillmentStatusText(props.fulfillment.sta
const statusTheme = computed(() => getStatusTheme(props.fulfillment.status));
const operatorName = computed(() => getUserName(props.fulfillment.operator, props.fulfillment.operatorUserId, "未知操作人"));
const verifierName = computed(() => getUserName(props.fulfillment.verifier, props.fulfillment.verifierUserId, "未知核销人"));
const showVerifier = computed(() => ["VERIFIED", "REVOKED"].includes(props.fulfillment.status || ""));
const showVerifier = computed(() => ["VERIFIED", "REVOKED", "RETURNED"].includes(props.fulfillment.status || ""));
const totalProductQuantity = computed(() => {
let total = 0;
for (const item of itemList.value) {
@@ -0,0 +1,172 @@
<template>
<bottom-popup
v-model="visible"
title="履约退货"
left-button-text="取消"
:right-button-text="operating ? '提交中' : '提交'"
:z-index="returnPopupZIndex"
:overlay-props="{ zIndex: returnPopupZIndex - 1 }"
@left-button-click="visible = false"
@right-button-click="submit"
>
<t-form class="return-form" label-width="7rem">
<t-notice-bar
theme="warning"
visible
content="退货将同步退回实物,请上传退货凭证。"
/>
<t-form-item label="退货原因" required-mark>
<div class="reason">
<t-textarea v-model.trim="reason" borderless autosize maxlength="500" placeholder="请输入或选择退货原因" />
<t-button size="extra-small" theme="primary" variant="outline" content="选择" @click="openReasonPicker" />
</div>
</t-form-item>
<t-form-item label="退货备注">
<t-textarea v-model.trim="remark" borderless autosize maxlength="500" placeholder="可选" />
</t-form-item>
<t-form-item label-width="0">
<attachment-selector v-model:items="photoItems" :upload="uploadPhotoList" required title="退货凭证照片" />
</t-form-item>
</t-form>
</bottom-popup>
<t-popup
v-model="reasonPickerVisible"
placement="bottom"
:z-index="reasonPickerZIndex"
:overlay-props="{ zIndex: reasonPickerZIndex - 1 }"
>
<t-picker
v-model="reasonPickerDraft"
:columns="reasonPickerColumns"
title="选择退货原因"
@cancel="reasonPickerVisible = false"
@confirm="confirmReason"
/>
</t-popup>
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import type { Attachment } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { OrderFulfillment } from "@/types/Fulfillment";
import type { PhotoItem } from "@/types/Photo";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { Message } from "@/utils/message";
import { createPackageRequestNo } from "@/utils/package";
import { uploadPhotoList } from "@/utils/photo";
defineOptions({ name: "OrderFulfillmentReturn" });
const props = defineProps<{ fulfillment: OrderFulfillment }>();
const emit = defineEmits<{ success: [] }>();
const visible = defineModel<boolean>("visible", { default: false });
const returnPopupZIndex = 12000;
const reasonPickerZIndex = returnPopupZIndex + 1;
const operating = ref(false);
const reason = ref("");
const remark = ref("");
const photoItems = ref<PhotoItem[]>([]);
const reasonPickerVisible = ref(false);
const reasonPickerDraft = ref<string[]>([]);
const requestNo = ref("");
const reasonOptions = [
"客户申请退货",
"商品或服务与实际不符",
"履约数量填写有误",
"重复履约",
"履约操作有误"
];
const reasonPickerColumns = reasonOptions.map(item => ({ label: item, value: item }));
function resetForm(): void {
reason.value = "";
remark.value = "";
photoItems.value = [];
reasonPickerVisible.value = false;
reasonPickerDraft.value = [];
requestNo.value = "";
}
function openReasonPicker(): void {
const currentReason = reasonOptions.includes(reason.value) ? reason.value : reasonOptions[0];
reasonPickerDraft.value = [currentReason];
reasonPickerVisible.value = true;
}
function confirmReason(value: Array<string | number>): void {
reason.value = String(value[0] || reasonPickerDraft.value[0] || "");
reasonPickerVisible.value = false;
}
function buildAttachments(): Partial<Attachment>[] {
return photoItems.value.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
}
async function submit(): Promise<void> {
if (operating.value) return;
if (!props.fulfillment.id) {
Message.error("履约单编号缺失,无法退货");
return;
}
if (!reason.value.trim()) {
Message.warning("退货原因不能为空");
return;
}
const attachmentList = buildAttachments();
if (!attachmentList.length) {
Message.warning("退货必须上传至少一张照片");
return;
}
if (!requestNo.value) requestNo.value = createPackageRequestNo();
operating.value = true;
try {
await FulfillmentAPI.returnGoods({
fulfillmentId: props.fulfillment.id,
requestNo: requestNo.value,
reason: reason.value.trim(),
returnedToStore: true,
attachmentList,
remark: remark.value.trim() || null
});
visible.value = false;
emitListDataChanged(listDataEventKeys.salesOrderChanged, props.fulfillment.salesOrderId);
emitListDataChanged(listDataEventKeys.productStockChanged);
Message.success("履约单已退货");
emit("success");
} catch (error) {
Message.error(getErrorMessage(error, "履约退货失败,重试会复用同一请求号"));
} finally {
operating.value = false;
}
}
watch(visible, value => {
if (value) {
resetForm();
} else {
reasonPickerVisible.value = false;
}
});
</script>
<style scoped lang="less">
.return-form {
margin: 0;
.reason {
gap: .5rem;
flex: 1;
display: flex;
align-items: flex-start;
.t-textarea {
flex: 1;
min-width: 0;
}
}
}
</style>
@@ -269,6 +269,7 @@ const operationOptions = [
{ label: "履约释放预占", value: "ORDER_RELEASE" },
{ label: "履约出库", value: "ORDER_OUT" },
{ label: "履约冲正入库", value: "ORDER_REVOKE" },
{ label: "履约退货入库", value: "ORDER_RETURN_IN" },
{ label: "盘盈", value: "STOCKTAKE_GAIN" },
{ label: "盘亏", value: "STOCKTAKE_LOSS" }
];
@@ -310,6 +311,7 @@ function getOperationIcon(type?: StockOperationType): string {
ORDER_RELEASE: "lock-off",
ORDER_OUT: "task",
ORDER_REVOKE: "rollback",
ORDER_RETURN_IN: "rollback",
STOCKTAKE_GAIN: "arrow-up",
STOCKTAKE_LOSS: "arrow-down"
} as Record<string, string>)[type || ""] || "history";
@@ -325,6 +327,7 @@ function getOperationClass(type?: StockOperationType): string {
ORDER_RELEASE: "order-release",
ORDER_OUT: "order-out",
ORDER_REVOKE: "order-revoke",
ORDER_RETURN_IN: "order-return-in",
STOCKTAKE_GAIN: "stocktake-gain",
STOCKTAKE_LOSS: "stocktake-loss"
} as Record<string, string>)[type || ""] || "unknown";
+188 -101
View File
@@ -1,91 +1,92 @@
<template>
<t-navbar
fixed
:z-index="20"
title="取消销售订单"
left-arrow
@left-click="$router.back()"
>
<template #right>
<t-button
v-if="userStore.hasPermissions(permissionCodes.salesOrder.cancel)"
@click="save"
theme="danger"
variant="text"
size="small"
content="确认"
<div class="page-layout navbar sales-order-cancel">
<t-navbar fixed :z-index="20" title="取消销售订单" left-arrow @left-click="$router.back()">
<template #right>
<t-button
v-if="userStore.hasPermissions(permissionCodes.salesOrder.cancel)"
:disabled="loadingActionDetail || saving || validating"
:loading="saving"
theme="danger"
variant="text"
size="small"
content="确认"
@click="save"
/>
</template>
</t-navbar>
<main v-can="permissionCodes.salesOrder.cancel" class="page-content scroll column notice">
<t-notice-bar
theme="warning"
visible
content="请检查并处理该订单的履约和资金,勾选需要处理的记录后选择退货、退款或冲正。未勾选的记录会保留,所有处理均为可选。"
/>
</template>
</t-navbar>
<div v-can="permissionCodes.salesOrder.cancel" class="sales-order-operation">
<t-notice-bar
theme="warning"
visible
content="取消订单会立即撤销本单有效消费;受影响的订单积分和签到消费条件积分将由系统自动追加撤销流水。退款仍需按资金流程处理。"
/>
<t-cell-group
v-if="order"
title="销售订单"
theme="card"
v-entrance-transition
>
<t-cell title="订单号" :note="order.orderNo || order.id"/>
<t-cell title="当前状态" :note="getSalesOrderStatusText(order.status)"/>
<t-cell v-if="hasPendingFulfillment" title="履约提示" note="存在待处理履约,暂不能取消订单"/>
</t-cell-group>
<t-form
v-if="order"
class="form card"
label-width="6rem"
v-entrance-transition
>
<t-form-item label="取消原因" required-mark>
<div class="reason">
<t-textarea
v-model="reason"
borderless
autosize
maxlength="500"
placeholder="请输入取消原因"
<t-cell-group v-if="order" title="销售订单" theme="card" v-entrance-transition>
<t-cell title="订单号" :note="order.orderNo || order.id" />
<t-cell title="当前状态" :note="getSalesOrderStatusText(order.status)" />
<t-cell title="有效收款" :note="`¥${formatPackageAmount(order.paidAmount)}`" />
</t-cell-group>
<t-form v-if="order" class="form card" label-width="6rem" v-entrance-transition>
<t-form-item label="取消原因" required-mark>
<div class="reason">
<t-textarea v-model="reason" borderless autosize maxlength="500" placeholder="请输入取消原因" />
<t-button size="extra-small" theme="primary" variant="outline" content="选择" @click="openCancelReasonPicker" />
</div>
</t-form-item>
</t-form>
<fulfillment-cancel-section
ref="fulfillmentSection"
:shared-reason="reason"
:shared-photo-items="sharedPhotoItems"
:upload="uploadActionPhotos"
/>
<fund-cancel-section
ref="fundSection"
:shared-reason="reason"
:shared-photo-items="sharedPhotoItems"
:upload="uploadActionPhotos"
/>
<t-form v-if="hasSelectedAction" class="form card" label-width="0" v-entrance-transition>
<t-form-item label-width="0">
<attachment-selector
v-model:items="sharedPhotoItems"
:upload="uploadActionPhotos"
:busy="saving"
title="共用处理凭证(未上传专有凭证时使用)"
/>
<t-button
size="extra-small"
theme="primary"
variant="outline"
@click="openCancelReasonPicker"
>选择</t-button>
</div>
</t-form-item>
</t-form>
<t-empty v-if="!order" :description="loading ? '正在加载订单' : '订单不存在'"/>
<t-popup v-model="cancelReasonPickerVisible" placement="bottom">
<t-picker
v-if="cancelReasonPickerVisible"
v-model="cancelReasonPickerDraft"
:columns="cancelReasonPickerColumns"
title="选择取消原因"
@cancel="cancelReasonPickerVisible = false"
@confirm="confirmCancelReason"
/>
</t-popup>
</t-form-item>
</t-form>
<t-empty v-if="!order" :description="loading ? '正在加载订单' : '订单不存在'" />
</main>
</div>
<t-popup v-model="cancelReasonPickerVisible" placement="bottom">
<t-picker
v-if="cancelReasonPickerVisible"
v-model="cancelReasonPickerDraft"
:columns="cancelReasonPickerColumns"
title="选择取消原因"
@cancel="cancelReasonPickerVisible = false"
@confirm="confirmCancelReason"
/>
</t-popup>
</template>
<script setup lang="ts">
import { DialogPlugin } from "tdesign-mobile-vue";
import { useUserStore } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import type { SalesOrder } from "@/types/SalesOrder";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { Message } from "@/utils/message";
import { createPackageRequestNo, formatPackageAmount } from "@/utils/package";
import { permissionCodes } from "@/utils/permission";
import { uploadPhotoList } from "@/utils/photo";
import { getSalesOrderStatusText } from "@/utils/salesOrder";
import type { SalesOrder } from "@/types/SalesOrder";
import FulfillmentCancelSection from "./component/FulfillmentCancelSection.vue";
import FundCancelSection from "./component/FundCancelSection.vue";
import { buildActionAttachmentList } from "./component/salesOrderCancelUtils";
defineOptions({ name: "SalesOrderCancel" });
const route = useRoute();
@@ -94,20 +95,26 @@ const userStore = useUserStore();
const order = ref<SalesOrder>();
const loading = ref(false);
const saving = ref(false);
const validating = ref(false);
const uploadCount = ref(0);
const reason = ref("");
const cancelRequestNo = ref("");
const cancelReasonPickerDraft = ref<string[]>([]);
const cancelReasonPickerVisible = ref(false);
const hasPendingFulfillment = ref(false);
const sharedPhotoItems = ref<PhotoItem[]>([]);
const fulfillmentSection = ref<InstanceType<typeof FulfillmentCancelSection>>();
const fundSection = ref<InstanceType<typeof FundCancelSection>>();
const cancelReasonOptions = [
"客户主动取消订单",
"客户重复下单",
"商品缺货,无法履约",
"订单信息有误",
"价格或优惠配置错误",
"客户需求变更",
"其他原因"
"客户需求变更"
];
const cancelReasonPickerColumns = cancelReasonOptions.map(item => ({ label: item, value: item }));
const hasSelectedAction = computed(() => !!fulfillmentSection.value?.hasSelected || !!fundSection.value?.hasSelected);
const loadingActionDetail = computed(() => !!fulfillmentSection.value?.loadingDetail || !!fundSection.value?.loadingDetail);
function openCancelReasonPicker(): void {
const currentReason = cancelReasonOptions.includes(reason.value) ? reason.value : cancelReasonOptions[0];
@@ -120,19 +127,68 @@ function confirmCancelReason(value: Array<string | number>): void {
cancelReasonPickerVisible.value = false;
}
async function uploadActionPhotos(fileList: File[]): Promise<PhotoItem[]> {
uploadCount.value += 1;
try {
return await uploadPhotoList(fileList);
} finally {
uploadCount.value -= 1;
}
}
function getCancelRequestNo(): string {
if (!cancelRequestNo.value) cancelRequestNo.value = createPackageRequestNo();
return cancelRequestNo.value;
}
async function validateActionData(): Promise<boolean> {
const fulfillment = fulfillmentSection.value;
const fund = fundSection.value;
if (!fulfillment || !fund) {
Message.warning("处理列表尚未就绪");
return false;
}
if (0 < uploadCount.value) {
Message.warning("附件上传完成后再提交");
return false;
}
if (loadingActionDetail.value) {
Message.warning("正在校验所选处理记录,请稍候");
return false;
}
const fulfillmentIncomplete = fulfillment.getIncompleteIds();
const fundIncomplete = fund.getIncompleteIds();
const incompleteCount = fulfillmentIncomplete.length + fundIncomplete.length;
if (incompleteCount) {
Message.warning(`还有 ${incompleteCount} 项处理资料待完善`);
if (fulfillmentIncomplete.length) await fulfillment.openIncomplete(fulfillmentIncomplete[0]);
else await fund.openIncomplete(fundIncomplete[0]);
return false;
}
const balance = Math.max(0, (order.value?.paidAmount || 0) - (order.value?.refundedAmount || 0));
const refundableAmount = Math.max(0, balance + fund.getRevokeAdjustment());
if (refundableAmount < fund.getSelectedRefundAmount()) {
Message.warning("退款金额不能超过执行本次资金冲正后的有效收款余额");
return false;
}
return true;
}
async function loadData(): Promise<void> {
const id = String(route.params.id || "");
if (!id) return;
const fulfillment = fulfillmentSection.value;
const fund = fundSection.value;
if (!id || !fulfillment || !fund) return;
loading.value = true;
try {
order.value = await SalesOrderAPI.detail(id);
if (userStore.hasPermissions(permissionCodes.orderFulfillment.read)) {
const [pendingResult, waitingStockResult] = await Promise.all([
FulfillmentAPI.list({ salesOrderId: id, status: "PENDING", index: 0, size: 1 }),
FulfillmentAPI.list({ salesOrderId: id, status: "WAITING_STOCK", index: 0, size: 1 })
]);
hasPendingFulfillment.value = !!pendingResult.list?.length || !!waitingStockResult.list?.length;
}
const [loadedOrder, fulfillmentList, fundList] = await Promise.all([
SalesOrderAPI.detail(id),
fulfillment.load(id),
fund.load(id)
]);
fulfillment.setCandidates(fulfillmentList);
fund.setCandidates(fundList);
order.value = loadedOrder;
} catch (error) {
Message.error(getErrorMessage(error, "订单加载失败"));
} finally {
@@ -141,40 +197,72 @@ async function loadData(): Promise<void> {
}
async function save(): Promise<void> {
if (!order.value?.id || !reason.value || saving.value) return;
if (order.value.status !== "ACTIVE") {
Message.warning("只有进行中的订单可以取消");
if (!order.value?.id || saving.value || validating.value) return;
if (!reason.value.trim()) {
Message.warning("请输入取消原因");
return;
}
if (hasPendingFulfillment.value) {
Message.warning("存在待处理履约,暂不能取消订单");
if (order.value.status !== "ACTIVE" && order.value.status !== "FULFILLED") {
Message.warning("当前订单不可取消");
return;
}
validating.value = true;
let valid: boolean;
try {
valid = await validateActionData();
} finally {
validating.value = false;
}
if (!valid) return;
const dialog = DialogPlugin.confirm({
title: "确认取消订单",
content: "未勾选的已核销履约和资金记录会保留为历史事实。取消后若请求失败,请使用同一页面重试,不要重复发起其他操作。",
cancelBtn: "再检查一下",
confirmBtn: "确认取消",
onCancel() {
dialog.destroy();
},
async onConfirm() {
dialog.destroy();
await submitCancel();
}
});
}
async function submitCancel(): Promise<void> {
const fulfillment = fulfillmentSection.value;
const fund = fundSection.value;
if (!order.value?.id || saving.value || !fulfillment || !fund) return;
saving.value = true;
try {
await SalesOrderAPI.cancel({ salesOrderId: order.value.id, reason: reason.value.trim() });
await SalesOrderAPI.cancel({
salesOrderId: order.value.id,
reason: reason.value.trim(),
requestNo: getCancelRequestNo(),
attachmentList: buildActionAttachmentList(sharedPhotoItems.value),
fulfillmentReturnList: fulfillment.buildFulfillmentReturnList(),
fulfillmentRevokeList: fulfillment.buildFulfillmentRevokeList(),
fundRevokeList: fund.buildFundRevokeList(),
fundRefundList: fund.buildFundRefundList(order.value.id)
});
emitListDataChanged(listDataEventKeys.salesOrderChanged, order.value.id);
emitListDataChanged(listDataEventKeys.productStockChanged);
Message.success("订单已取消");
await router.replace(`/management/sales-orders/${order.value.id}`);
} catch (error) {
Message.error(getErrorMessage(error, "订单取消失败"));
Message.error(getErrorMessage(error, "订单取消失败,重试会复用同一请求号"));
} finally {
saving.value = false;
}
}
onMounted(async () => {
if (!userStore.hasPermissions(permissionCodes.salesOrder.cancel)) return;
await loadData();
if (userStore.hasPermissions(permissionCodes.salesOrder.cancel)) await loadData();
});
</script>
<style scoped lang="less">
.sales-order-operation {
gap: 1rem;
padding: var(--app-nav-height) 0 2rem;
display: flex;
flex-direction: column;
.sales-order-cancel {
.form {
@@ -184,5 +272,4 @@ onMounted(async () => {
}
}
}
</style>
+3 -16
View File
@@ -229,7 +229,6 @@
<script setup lang="ts">
import { TimeLabel, Text, Time } from "timi-web";
import { type Attachment, useUserStore } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
@@ -258,7 +257,6 @@ const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const order = ref<SalesOrder>();
const hasPendingFulfillment = ref(false);
const loading = ref(false);
const isEditing = ref(false);
const isSaving = ref(false);
@@ -271,7 +269,9 @@ const canCreateFulfillment = computed(() => userStore.hasPermissions(permissionC
const canReceive = computed(() => !!order.value && order.value.status !== "CANCELLED" && order.value.paymentStatus !== "PAID" && userStore.hasPermissions(permissionCodes.fundReceive.create));
const canRefund = computed(() => !!order.value && order.value.status === "CANCELLED" && order.value.refundStatus === "PENDING" && userStore.hasPermissions(permissionCodes.fund.refund));
const canConfirmNoRefund = computed(() => !!order.value && order.value.status === "CANCELLED" && order.value.refundStatus === "PENDING" && userStore.hasPermissions(permissionCodes.fund.refund));
const canCancel = computed(() => !!order.value && order.value.status === "ACTIVE" && !hasPendingFulfillment.value && userStore.hasPermissions(permissionCodes.salesOrder.cancel));
const canCancel = computed(() => !!order.value
&& (order.value.status === "ACTIVE" || order.value.status === "FULFILLED")
&& userStore.hasPermissions(permissionCodes.salesOrder.cancel));
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasRoles(gaoRoleCodes.storeManager));
function toPhotoItems(attachmentList?: readonly Partial<Attachment>[]): PhotoItem[] {
@@ -372,25 +372,12 @@ async function loadData(): Promise<void> {
isEditing.value = false;
if (!id) {
order.value = undefined;
hasPendingFulfillment.value = false;
photoItems.value = [];
return;
}
loading.value = true;
try {
order.value = await SalesOrderAPI.detail(id);
hasPendingFulfillment.value = false;
if (userStore.hasPermissions(permissionCodes.orderFulfillment.read)) {
try {
const [pendingResult, waitingStockResult] = await Promise.all([
FulfillmentAPI.list({ salesOrderId: id, status: "PENDING", index: 0, size: 1 }),
FulfillmentAPI.list({ salesOrderId: id, status: "WAITING_STOCK", index: 0, size: 1 })
]);
hasPendingFulfillment.value = !!pendingResult.list?.length || !!waitingStockResult.list?.length;
} catch {
// 取消接口仍会在后端校验待处理履约,查询失败时不阻断订单详情展示。
}
}
editRemark.value = order.value.remark || "";
photoItems.value = toPhotoItems(order.value.attachmentList);
} catch (error) {
+6 -6
View File
@@ -115,9 +115,9 @@ import CustomerAPI from "@/api/CustomerAPI";
import PackageAPI from "@/api/PackageAPI";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import CustomerSelector from "@/components/CustomerSelector.vue";
import SalesOrderFilterSummary from "@/pages/salesOrder/components/SalesOrderFilterSummary.vue";
import SalesOrderListCell from "@/pages/salesOrder/components/SalesOrderListCell.vue";
import SalesOrderSummary from "@/pages/salesOrder/components/SalesOrderSummary.vue";
import SalesOrderFilterSummary from "@/pages/salesOrder/component/SalesOrderFilterSummary.vue";
import SalesOrderListCell from "@/pages/salesOrder/component/SalesOrderListCell.vue";
import SalesOrderSummary from "@/pages/salesOrder/component/SalesOrderSummary.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import type { GaoPackageConfig } from "@/types/Package";
import type {
@@ -141,7 +141,7 @@ import { events, isCurrentStoreEvent, type ListDataChangedPayload, listDataEvent
import { Message } from "@/utils/message";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
import SalesOrderFilterPopup from "@/pages/salesOrder/components/SalesOrderFilterPopup.vue";
import SalesOrderFilterPopup from "@/pages/salesOrder/component/SalesOrderFilterPopup.vue";
import type { Customer } from "@/types/Customer";
defineOptions({ name: "SalesOrderList" });
@@ -198,14 +198,14 @@ function restorePageScrollPosition(): void {
const actions = computed(() => [
...(canCreate.value ? [{
key: "create",
text: "直接产品下单",
text: "创建产品订单",
icon: "task",
theme: "primary" as const,
action: () => router.push("/management/sales-orders/create")
}] : []),
...(canCreatePackageOrder.value ? [{
key: "create-package-order",
text: "创建客户套餐",
text: "创建套餐订单",
icon: "layers",
theme: "primary" as const,
action: () => router.push("/management/customer-packages/create")
@@ -0,0 +1,164 @@
<template>
<bottom-popup
:model-value="props.modelValue"
title="配置履约处理"
left-button-text="关闭"
:z-index="actionPopupZIndex"
:overlay-props="{ zIndex: actionPopupZIndex - 1 }"
@update:model-value="updateVisible"
@left-button-click="updateVisible(false)"
>
<template #rightButton>
<t-button theme="primary" variant="text" size="small" content="确认" @click="updateVisible(false)" />
</template>
<div v-if="props.selection" class="action-popup">
<t-form class="form" label-width="7rem">
<t-form-item label="所属履约单" arrow @click="openDetail()" />
<t-form-item label="类型" content-align="right">
<t-radio-group
:model-value="props.selection.action"
class="action-selector"
variant="default-filled"
@update:model-value="updateAction"
>
<t-radio v-if="props.canReturn" :block="false" borderless value="RETURN">退货</t-radio>
<t-radio v-if="props.canRevoke" :block="false" borderless value="REVOKE">冲正</t-radio>
</t-radio-group>
</t-form-item>
<t-form-item :label="`${actionText}原因`">
<t-input
:model-value="props.selection.form.reason"
@update:model-value="updateReason"
borderless
placeholder="未填写时使用订单取消原因"
/>
</t-form-item>
<t-form-item v-if="isPhysical && props.selection.action === 'REVOKE'" label="库存退回门店" content-align="right">
<t-switch
:model-value="props.selection.form.returnedToStore"
@update:model-value="updateReturnedToStore"
/>
</t-form-item>
<t-form-item :label="`${actionText}备注`">
<t-textarea
:model-value="props.selection.form.remark"
@update:model-value="updateRemark"
borderless
autosize
maxlength="500"
placeholder="可选"
/>
</t-form-item>
<div class="photo-wrap">
<attachment-selector
:items="props.selection.form.photoItems"
@update:items="updatePhotoItems"
:upload="props.upload"
:title="`专有${actionText}凭证(未添加时使用共用凭证)`"
/>
</div>
</t-form>
</div>
</bottom-popup>
<fulfillment-detail-popup
v-model="detailPopupVisible"
:fulfillment="props.selection?.fulfillment"
:z-index="detailPopupZIndex"
/>
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import FulfillmentDetailPopup from "./FulfillmentDetailPopup.vue";
import type { OrderFulfillment } from "@/types/Fulfillment";
import type { PhotoItem } from "@/types/Photo";
type FulfillmentAction = "RETURN" | "REVOKE";
type FulfillmentActionForm = {
reason: string;
remark: string;
returnedToStore: boolean;
photoItems: PhotoItem[];
requestNo: string;
};
type FulfillmentActionSelection = {
fulfillment: OrderFulfillment;
action: FulfillmentAction;
form: FulfillmentActionForm;
};
const props = defineProps<{
modelValue: boolean;
selection?: FulfillmentActionSelection;
canReturn: boolean;
canRevoke: boolean;
sharedReason: string;
sharedPhotoItems: PhotoItem[];
upload: (files: File[]) => Promise<PhotoItem[]>;
}>();
const actionPopupZIndex = 12000;
const detailPopupZIndex = actionPopupZIndex + 1;
const detailPopupVisible = ref(false);
const emit = defineEmits<{
(event: "update:modelValue", visible: boolean): void;
(event: "update:action", action: FulfillmentAction): void;
(event: "update:form", form: FulfillmentActionForm): void;
}>();
const isPhysical = computed(() => !!props.selection?.fulfillment.stockRecordList?.length);
const actionText = computed(() => props.selection?.action === "RETURN" ? "退货" : "冲正");
function updateVisible(visible: boolean): void {
emit("update:modelValue", visible);
}
function openDetail(): void {
if (props.selection) detailPopupVisible.value = true;
}
function updateAction(value: unknown): void {
if (value === "RETURN" || value === "REVOKE") emit("update:action", value);
}
function updateForm(form: Partial<FulfillmentActionForm>): void {
if (!props.selection) return;
emit("update:form", { ...props.selection.form, ...form });
}
function updateReason(value: string): void {
updateForm({ reason: value });
}
function updateReturnedToStore(value: boolean | number | string): void {
updateForm({ returnedToStore: Boolean(value) });
}
function updateRemark(value: string): void {
updateForm({ remark: value });
}
function updatePhotoItems(items: PhotoItem[]): void {
updateForm({ photoItems: items });
}
watch(() => props.modelValue, visible => {
if (!visible) detailPopupVisible.value = false;
});
</script>
<style scoped lang="less">
.action-popup {
.photo-wrap {
padding: 1rem;
}
.form {
margin: 0;
}
}
</style>
@@ -0,0 +1,336 @@
<template>
<t-cell-group v-if="canManageFulfillment && fulfillmentCandidateList.length" title="已核销履约处理" theme="card" v-entrance-transition>
<t-cell
v-for="item in fulfillmentCandidateList"
:key="item.id"
class="action-cell"
:class="{ selected: isFulfillmentSelected(item) }"
@click="toggleFulfillmentSelected(item)"
>
<template #left-icon>
<t-checkbox
:model-value="isFulfillmentSelected(item)"
:aria-label="`选择履约单 ${item.id}`"
borderless
@click.stop
@update:model-value="(checked: unknown) => setFulfillmentSelected(item, Boolean(checked))"
/>
</template>
<template #title>
<div class="title">
<div class="summary">
<time-label v-if="item.deliveredAt" :timestamp="item.deliveredAt" underline />
<span v-else>履约时间未知</span>
</div>
<div class="actions">
<t-button
size="extra-small"
variant="outline"
content="详情"
:disabled="!item.id || isFulfillmentDetailLoading(item.id)"
@click.stop="openFulfillmentDetail(item)"
/>
<t-button
v-if="isFulfillmentSelected(item)"
size="extra-small"
theme="primary"
variant="outline"
content="配置"
:disabled="isFulfillmentDetailLoading(item.id)"
@click.stop="openFulfillmentConfig(item)"
/>
</div>
</div>
</template>
<template #description>
<div class="description">
<t-tag v-if="isFulfillmentDetailLoading(item.id)" theme="warning" content="正在校验" size="small" variant="light-outline" />
<template v-else-if="isFulfillmentSelected(item)">
<t-tag v-if="!getFulfillmentAction(item)" theme="warning" content="待配置" size="small" variant="light-outline" />
<template v-else>
<t-tag v-bind="getFulfillmentActionTag(item)" size="small" variant="light-outline" />
<t-tag
v-if="getFulfillmentAction(item) === 'RETURN' || (item.id && fulfillmentDetailMap[item.id]?.stockRecordList?.length)"
v-bind="getFulfillmentStockTag(item)"
size="small"
variant="light-outline"
/>
<t-tag v-bind="getFulfillmentPhotoTag(item)" size="small" variant="light-outline" />
</template>
</template>
</div>
</template>
</t-cell>
</t-cell-group>
<fulfillment-cancel-action-popup
v-model="fulfillmentActionPopupVisible"
:selection="activeFulfillmentSelection"
:can-return="canReturnFulfillment"
:can-revoke="canRevokeFulfillment"
:shared-reason="props.sharedReason"
:shared-photo-items="props.sharedPhotoItems"
:upload="props.upload"
@update:action="updateActiveFulfillmentAction"
@update:form="updateActiveFulfillmentForm"
/>
<fulfillment-detail-popup
v-model="fulfillmentDetailPopupVisible"
:fulfillment="detailFulfillment"
/>
</template>
<script setup lang="ts">
import { TimeLabel } from "timi-web";
import { useUserStore } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import type { FulfillmentReturnRequest, FulfillmentRevokeRequest, OrderFulfillment } from "@/types/Fulfillment";
import type { PhotoItem } from "@/types/Photo";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import FulfillmentCancelActionPopup from "./FulfillmentCancelActionPopup.vue";
import FulfillmentDetailPopup from "./FulfillmentDetailPopup.vue";
import { actionPageSize, buildActionAttachmentList, getActionPhotoTag, getActionRequestNo, hasActionPhoto, loadAllPages } from "./salesOrderCancelUtils";
import type { ActionTag } from "./salesOrderCancelUtils";
type FulfillmentAction = "RETURN" | "REVOKE";
type FulfillmentActionForm = {
reason: string;
remark: string;
returnedToStore: boolean;
photoItems: PhotoItem[];
requestNo: string;
};
const props = defineProps<{
sharedReason: string;
sharedPhotoItems: PhotoItem[];
upload: (files: File[]) => Promise<PhotoItem[]>;
}>();
const userStore = useUserStore();
const fulfillmentCandidateList = ref<OrderFulfillment[]>([]);
const selectedFulfillmentIdList = ref<string[]>([]);
const fulfillmentActionMap = ref<Record<string, FulfillmentAction>>({});
const fulfillmentDetailMap = ref<Record<string, OrderFulfillment>>({});
const fulfillmentFormMap = ref<Record<string, Partial<Record<FulfillmentAction, FulfillmentActionForm>>>>({});
const loadingFulfillmentDetailIdList = ref<string[]>([]);
const activeFulfillmentId = ref("");
const fulfillmentActionPopupVisible = ref(false);
const detailFulfillment = ref<OrderFulfillment>();
const fulfillmentDetailPopupVisible = ref(false);
const canReturnFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.return));
const canRevokeFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.revoke));
const canManageFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.read)
&& (canReturnFulfillment.value || canRevokeFulfillment.value));
const hasSelected = computed(() => selectedFulfillmentIdList.value.length !== 0);
const loadingDetail = computed(() => loadingFulfillmentDetailIdList.value.length !== 0);
const activeFulfillmentSelection = computed(() => {
const id = activeFulfillmentId.value;
const fulfillment = fulfillmentDetailMap.value[id];
const action = fulfillmentActionMap.value[id];
const form = action ? fulfillmentFormMap.value[id]?.[action] : undefined;
return fulfillment && action && form ? { fulfillment, action, form } : undefined;
});
function isFulfillmentSelected(fulfillment: OrderFulfillment): boolean {
return !!fulfillment.id && selectedFulfillmentIdList.value.includes(fulfillment.id);
}
function isFulfillmentDetailLoading(id?: string): boolean {
return !!id && loadingFulfillmentDetailIdList.value.includes(id);
}
function getFulfillmentAction(fulfillment: OrderFulfillment): FulfillmentAction | undefined {
return fulfillment.id ? fulfillmentActionMap.value[fulfillment.id] : undefined;
}
function getFulfillmentActionTag(fulfillment: OrderFulfillment): ActionTag {
const action = getFulfillmentAction(fulfillment);
if (action === "RETURN") return { content: "退货", theme: "success" };
if (action === "REVOKE") return { content: "冲正", theme: "warning" };
return { content: "待配置", theme: "warning" };
}
function getFulfillmentStockTag(fulfillment: OrderFulfillment): ActionTag {
const action = getFulfillmentAction(fulfillment);
if (action === "RETURN") return { content: "退回实物", theme: "success" };
const form = getFulfillmentForm(fulfillment.id, action);
return form?.returnedToStore
? { content: "退回实物", theme: "success" }
: { content: "不退回实物", theme: "warning" };
}
function getFulfillmentPhotoTag(fulfillment: OrderFulfillment): ActionTag {
const action = getFulfillmentAction(fulfillment);
return getActionPhotoTag(getFulfillmentForm(fulfillment.id, action)?.photoItems, props.sharedPhotoItems);
}
function createFulfillmentActionForm(): FulfillmentActionForm {
return { reason: "", remark: "", returnedToStore: true, photoItems: [], requestNo: "" };
}
function getFulfillmentForm(id: string | undefined, action: FulfillmentAction | undefined): FulfillmentActionForm | undefined {
return id && action ? fulfillmentFormMap.value[id]?.[action] : undefined;
}
function setFulfillmentAction(id: string, action: FulfillmentAction): void {
const oldFormMap = fulfillmentFormMap.value[id] || {};
if (!oldFormMap[action]) {
fulfillmentFormMap.value = {
...fulfillmentFormMap.value,
[id]: { ...oldFormMap, [action]: createFulfillmentActionForm() }
};
}
fulfillmentActionMap.value = { ...fulfillmentActionMap.value, [id]: action };
}
function removeFulfillmentSelection(id: string): void {
selectedFulfillmentIdList.value = selectedFulfillmentIdList.value.filter(item => item !== id);
const actionMap = { ...fulfillmentActionMap.value };
delete actionMap[id];
fulfillmentActionMap.value = actionMap;
const formMap = { ...fulfillmentFormMap.value };
delete formMap[id];
fulfillmentFormMap.value = formMap;
}
function toggleFulfillmentSelected(fulfillment: OrderFulfillment): void {
setFulfillmentSelected(fulfillment, !isFulfillmentSelected(fulfillment));
}
function setFulfillmentSelected(fulfillment: OrderFulfillment, selected: boolean): void {
if (!fulfillment.id) return;
if (selected) {
if (!isFulfillmentSelected(fulfillment)) selectedFulfillmentIdList.value = [...selectedFulfillmentIdList.value, fulfillment.id];
return;
}
removeFulfillmentSelection(fulfillment.id);
}
async function loadFulfillmentDetail(fulfillment: OrderFulfillment, errorMessage: string): Promise<OrderFulfillment | undefined> {
const id = fulfillment.id;
if (!id || isFulfillmentDetailLoading(id)) return undefined;
const cached = fulfillmentDetailMap.value[id];
if (cached) return cached;
loadingFulfillmentDetailIdList.value = [...loadingFulfillmentDetailIdList.value, id];
try {
const detail = await FulfillmentAPI.detail(id);
fulfillmentDetailMap.value = { ...fulfillmentDetailMap.value, [id]: detail };
return detail;
} catch (error) {
Message.error(getErrorMessage(error, errorMessage));
return undefined;
} finally {
loadingFulfillmentDetailIdList.value = loadingFulfillmentDetailIdList.value.filter(item => item !== id);
}
}
async function openFulfillmentConfig(fulfillment: OrderFulfillment): Promise<void> {
const id = fulfillment.id;
if (!id || !isFulfillmentSelected(fulfillment) || isFulfillmentDetailLoading(id)) return;
const detail = await loadFulfillmentDetail(fulfillment, "履约单校验失败");
if (!detail) {
removeFulfillmentSelection(id);
return;
}
if (!isFulfillmentSelected(fulfillment)) return;
if (detail.status !== "VERIFIED" || detail.sourceFulfillmentId) {
removeFulfillmentSelection(id);
Message.warning("只有原始已核销履约单可以随订单退货或冲正");
return;
}
const action = fulfillmentActionMap.value[detail.id || ""] || (canReturnFulfillment.value ? "RETURN" : "REVOKE");
if (!detail.id) return;
setFulfillmentAction(detail.id, action);
activeFulfillmentId.value = detail.id;
fulfillmentActionPopupVisible.value = true;
}
async function openFulfillmentDetail(fulfillment: OrderFulfillment): Promise<void> {
const detail = await loadFulfillmentDetail(fulfillment, "履约单详情加载失败");
if (!detail) return;
detailFulfillment.value = detail;
fulfillmentDetailPopupVisible.value = true;
}
function updateActiveFulfillmentAction(action: FulfillmentAction): void {
const id = activeFulfillmentId.value;
if (!id || (action === "RETURN" && !canReturnFulfillment.value) || (action === "REVOKE" && !canRevokeFulfillment.value)) return;
setFulfillmentAction(id, action);
}
function updateActiveFulfillmentForm(form: FulfillmentActionForm): void {
const id = activeFulfillmentId.value;
const action = fulfillmentActionMap.value[id];
if (!id || !action) return;
fulfillmentFormMap.value = {
...fulfillmentFormMap.value,
[id]: { ...fulfillmentFormMap.value[id], [action]: form }
};
}
function isFulfillmentActionComplete(fulfillment: OrderFulfillment): boolean {
const id = fulfillment.id;
const action = id && fulfillmentActionMap.value[id];
const form = id && action ? getFulfillmentForm(id, action) : undefined;
const detail = id && fulfillmentDetailMap.value[id];
return !!form && !!detail && hasActionPhoto(form.photoItems, props.sharedPhotoItems)
&& (action === "RETURN" || !detail.stockRecordList?.length || form.returnedToStore);
}
function buildFulfillmentReturnList(): FulfillmentReturnRequest[] {
return fulfillmentCandidateList.value.flatMap(fulfillment => {
const id = fulfillment.id;
const form = id && fulfillmentActionMap.value[id] === "RETURN" ? getFulfillmentForm(id, "RETURN") : undefined;
return id && form ? [{
fulfillmentId: id,
requestNo: getActionRequestNo(form),
reason: form.reason.trim(),
returnedToStore: true,
attachmentList: buildActionAttachmentList(form.photoItems),
remark: form.remark.trim() || null
}] : [];
});
}
function buildFulfillmentRevokeList(): FulfillmentRevokeRequest[] {
return fulfillmentCandidateList.value.flatMap(fulfillment => {
const id = fulfillment.id;
const form = id && fulfillmentActionMap.value[id] === "REVOKE" ? getFulfillmentForm(id, "REVOKE") : undefined;
return id && form ? [{
fulfillmentId: id,
requestNo: getActionRequestNo(form),
reason: form.reason.trim(),
returnedToStore: form.returnedToStore,
attachmentList: buildActionAttachmentList(form.photoItems),
remark: form.remark.trim() || null
}] : [];
});
}
async function load(salesOrderId: string): Promise<OrderFulfillment[]> {
if (!canManageFulfillment.value) return [];
const list = await loadAllPages(index => FulfillmentAPI.list({ salesOrderId, status: "VERIFIED", index, size: actionPageSize }));
return list.filter(item => !item.sourceFulfillmentId);
}
function setCandidates(list: OrderFulfillment[]): void {
fulfillmentCandidateList.value = list;
}
function getIncompleteIds(): string[] {
return fulfillmentCandidateList.value.flatMap(item => item.id && isFulfillmentSelected(item) && !isFulfillmentActionComplete(item) ? [item.id] : []);
}
async function openIncomplete(id: string): Promise<void> {
const item = fulfillmentCandidateList.value.find(candidate => candidate.id === id);
if (item) await openFulfillmentConfig(item);
}
defineExpose({ load, setCandidates, hasSelected, loadingDetail, getIncompleteIds, openIncomplete, buildFulfillmentReturnList, buildFulfillmentRevokeList });
</script>
<style scoped lang="less">
@import "./salesOrderCancelList.less";
</style>
@@ -0,0 +1,105 @@
<template>
<bottom-popup
:model-value="props.modelValue"
title="履约单详情"
height="70vh"
left-button-text="关闭"
right-button-text=""
:z-index="props.zIndex"
:overlay-props="overlayProps"
@update:model-value="updateVisible"
@left-button-click="updateVisible(false)"
>
<div v-if="props.fulfillment" class="detail-popup">
<t-cell title="发起时间">
<template #note>
<time-label v-if="props.fulfillment.createdAt" :timestamp="props.fulfillment.createdAt" underline />
<span v-else>未知</span></template>
</t-cell>
<t-cell title="提交人" :note="props.fulfillment.operator?.nick || props.fulfillment.operator?.name" />
<t-cell title="处理人" :note="props.fulfillment.verifier?.nick || props.fulfillment.verifier?.name" />
<t-cell title="备注" :note="props.fulfillment.remark || '无'" />
<t-cell class="product" title="产品明细">
<template #description>
<div class="description">
<t-cell-group>
<t-cell v-for="item in props.fulfillment.itemList || []" :key="item.id" :note="getQuantityText(item)">
<template #title>
<div class="title">
<span v-text="item.productNameSnapshot || '未命名产品'" />
<product-sku-tags
:product-name="item.productNameSnapshot"
:snapshot="item.skuSpecSnapshot"
:fallback="item.specSummarySnapshot || item.skuNameSnapshot || '默认 SKU'" />
</div>
</template>
</t-cell>
<t-cell v-if="!props.fulfillment.itemList?.length" title="暂无产品明细" />
</t-cell-group>
</div>
</template>
</t-cell>
<div class="photos">
<attachment-selector :items="photoItems" title="履约照片" readonly />
</div>
</div>
</bottom-popup>
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { OrderFulfillment, OrderFulfillmentItem } from "@/types/Fulfillment";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getPackageQuantityText } from "@/utils/package";
const props = defineProps<{ modelValue: boolean; fulfillment?: OrderFulfillment; zIndex?: number }>();
const emit = defineEmits<{ "update:modelValue": [visible: boolean] }>();
const overlayProps = computed(() => undefined === props.zIndex ? undefined : { zIndex: props.zIndex - 1 });
const photoItems = computed<PhotoItem[]>(() => (props.fulfillment?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
url: getAttachmentReadURL(item.id || "")
})));
function updateVisible(visible: boolean): void {
emit("update:modelValue", visible);
}
function getQuantityText(item: OrderFulfillmentItem): string {
return `${getPackageQuantityText(item.quantity)} ${item.unitSnapshot || "单位"}`;
}
</script>
<style scoped lang="less">
.detail-popup {
.product {
padding-right: 0;
:deep(.t-cell__title) {
margin-right: 0;
}
.description {
padding-left: 1rem;
.title {
gap: .5rem;
display: flex;
flex-wrap: wrap;
align-items: center;
}
}
}
.photos {
padding: 1rem;
}
}
</style>
@@ -0,0 +1,186 @@
<template>
<bottom-popup
:model-value="props.modelValue"
title="配置资金处理"
left-button-text="关闭"
:z-index="actionPopupZIndex"
:overlay-props="{ zIndex: actionPopupZIndex - 1 }"
@update:model-value="updateVisible"
@left-button-click="updateVisible(false)"
>
<template #rightButton>
<t-button theme="primary" variant="text" size="small" content="确认" @click="updateVisible(false)" />
</template>
<div v-if="props.selection" class="action-popup">
<t-form class="form" label-width="7rem">
<t-form-item label="所属资金流水" content-align="right" arrow @click="openDetail">
<span class="red text-bold" v-text="`¥${formatPackageAmount(props.selection.record.amount)}`"></span>
</t-form-item>
<t-form-item label="处理方式" content-align="right">
<t-radio-group
:model-value="props.selection.action"
class="action-selector"
variant="default-filled"
@update:model-value="updateAction"
>
<t-radio v-if="props.canRefund" :block="false" borderless value="REFUND">退款</t-radio>
<t-radio v-if="props.canRevoke" :block="false" borderless value="REVOKE">冲正</t-radio>
</t-radio-group>
</t-form-item>
<t-form-item v-if="props.selection.action === 'REFUND'" label="退款金额" required-mark>
<t-input
:model-value="props.selection.form.amountText"
@update:model-value="updateAmountText"
type="number"
align="right"
borderless
placeholder="输入退款金额"
>
<template #suffix-icon>
<t-button size="extra-small" theme="primary" variant="outline" content="本笔全额" @click="fillAmount" />
</template>
</t-input>
</t-form-item>
<t-form-item :label="`${actionText}原因`">
<t-input
:model-value="props.selection.form.reason"
@update:model-value="updateReason"
borderless
placeholder="未填写时使用订单取消原因"
/>
</t-form-item>
<t-form-item :label="`${actionText}备注`">
<t-textarea
:model-value="props.selection.form.remark"
@update:model-value="updateRemark"
borderless
autosize
maxlength="500"
placeholder="可选"
/>
</t-form-item>
<div class="photo-wrap">
<attachment-selector
:items="props.selection.form.photoItems"
@update:items="updatePhotoItems"
:upload="props.upload"
:title="`专有${actionText}凭证(未添加时使用共用凭证)`"
/>
</div>
</t-form>
</div>
</bottom-popup>
<fund-record-detail-popup
v-model="detailPopupVisible"
:record="props.selection?.record"
:z-index="detailPopupZIndex"
/>
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import FundRecordDetailPopup from "./FundRecordDetailPopup.vue";
import type { PhotoItem } from "@/types/Photo";
import type { FundRecord } from "@/types/SalesOrder";
import { formatPackageAmount, formatPackageAmountInput, parsePackageAmount } from "@/utils/package";
type FundAction = "REFUND" | "REVOKE";
type FundActionForm = {
amountText: string;
reason: string;
remark: string;
photoItems: PhotoItem[];
requestNo: string;
};
type FundActionSelection = {
record: FundRecord;
action: FundAction;
form: FundActionForm;
};
const props = defineProps<{
modelValue: boolean;
selection?: FundActionSelection;
canRefund: boolean;
canRevoke: boolean;
sharedReason: string;
sharedPhotoItems: PhotoItem[];
upload: (files: File[]) => Promise<PhotoItem[]>;
}>();
const actionPopupZIndex = 12000;
const detailPopupZIndex = actionPopupZIndex + 1;
const detailPopupVisible = ref(false);
const emit = defineEmits<{
(event: "update:modelValue", visible: boolean): void;
(event: "update:action", action: FundAction): void;
(event: "update:form", form: FundActionForm): void;
}>();
const actionText = computed(() => props.selection?.action === "REFUND" ? "退款" : "冲正");
const isComplete = computed(() => {
const selection = props.selection;
if (!selection) return false;
const amount = parsePackageAmount(selection.form.amountText);
const hasPhoto = [...selection.form.photoItems, ...props.sharedPhotoItems].some(item => !!item.tempFileId);
return hasPhoto && (selection.action !== "REFUND" || (amount !== undefined && 0 < amount));
});
function updateVisible(visible: boolean): void {
emit("update:modelValue", visible);
}
function openDetail(): void {
if (props.selection) detailPopupVisible.value = true;
}
function updateAction(value: unknown): void {
if (value === "REFUND" || value === "REVOKE") emit("update:action", value);
}
function updateForm(form: Partial<FundActionForm>): void {
if (!props.selection) return;
emit("update:form", { ...props.selection.form, ...form });
}
function updateAmountText(value: string | number): void {
updateForm({ amountText: String(value) });
}
function updateReason(value: string): void {
updateForm({ reason: value });
}
function updateRemark(value: string): void {
updateForm({ remark: value });
}
function updatePhotoItems(items: PhotoItem[]): void {
updateForm({ photoItems: items });
}
function fillAmount(): void {
if (!props.selection) return;
updateForm({ amountText: formatPackageAmountInput(props.selection.record.amount || 0) });
}
watch(() => props.modelValue, visible => {
if (!visible) detailPopupVisible.value = false;
});
</script>
<style scoped lang="less">
.action-popup {
.photo-wrap {
padding: 1rem;
}
.form {
margin: 0;
}
}
</style>
@@ -0,0 +1,401 @@
<template>
<t-cell-group v-if="canManageFund && fundCandidateList.length" title="已核销资金处理" theme="card"
v-entrance-transition>
<t-cell
v-for="item in fundCandidateList"
:key="item.id"
class="action-cell"
:class="{ selected: isFundSelected(item) }"
@click="toggleFundSelected(item)"
>
<template #left-icon>
<t-checkbox
:model-value="isFundSelected(item)"
:aria-label="`选择资金流水 ${item.id}`"
borderless
@click.stop
@update:model-value="(checked: unknown) => setFundSelected(item, Boolean(checked))"
/>
</template>
<template #title>
<div class="title">
<div class="summary">
<time-label v-if="item.occurredAt" :timestamp="item.occurredAt" underline />
<span v-else>流水时间未知</span>
<span class="red text-bold" v-text="`¥${formatPackageAmount(item.amount)}`" />
</div>
<div class="actions">
<t-button
size="extra-small"
variant="outline"
content="详情"
:disabled="!item.id || isFundDetailLoading(item.id)"
@click.stop="openFundDetail(item)"
/>
<t-button
v-if="isFundSelected(item)"
size="extra-small"
theme="primary"
variant="outline"
content="配置"
:disabled="isFundDetailLoading(item.id)"
@click.stop="openFundConfig(item)"
/>
</div>
</div>
</template>
<template #description>
<div class="description">
<t-tag v-if="isFundDetailLoading(item.id)" theme="warning" content="正在校验" size="small"
variant="light-outline" />
<template v-else-if="isFundSelected(item)">
<t-tag v-if="!getFundAction(item)" theme="warning" content="待配置" size="small"
variant="light-outline" />
<template v-else>
<t-tag v-bind="getFundActionTag(item)" size="small" variant="light-outline" />
<t-tag v-if="getFundAction(item) === 'REFUND'" v-bind="getFundRefundAmountTag(item)"
size="small" variant="light-outline" />
<t-tag v-bind="getFundPhotoTag(item)" size="small" variant="light-outline" />
</template>
</template>
</div>
</template>
</t-cell>
</t-cell-group>
<fund-cancel-action-popup
v-model="fundActionPopupVisible"
:selection="activeFundSelection"
:can-refund="canRefundActiveFund"
:can-revoke="canRevokeFund"
:shared-reason="props.sharedReason"
:shared-photo-items="props.sharedPhotoItems"
:upload="props.upload"
@update:action="updateActiveFundAction"
@update:form="updateActiveFundForm"
/>
<fund-record-detail-popup
v-model="fundRecordDetailPopupVisible"
:record="detailFundRecord"
/>
</template>
<script setup lang="ts">
import { TimeLabel } from "timi-web";
import { useUserStore } from "timi-web-api";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import type { PhotoItem } from "@/types/Photo";
import type { FundRecord, OrderPaymentRefundRequest, OrderPaymentRevokeRequest } from "@/types/SalesOrder";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { formatPackageAmount, formatPackageAmountInput, parsePackageAmount } from "@/utils/package";
import { permissionCodes } from "@/utils/permission";
import FundCancelActionPopup from "./FundCancelActionPopup.vue";
import FundRecordDetailPopup from "./FundRecordDetailPopup.vue";
import {
actionPageSize,
buildActionAttachmentList,
getActionPhotoTag,
getActionRequestNo,
hasActionPhoto,
loadAllPages
} from "./salesOrderCancelUtils";
import type { ActionTag } from "./salesOrderCancelUtils";
type FundAction = "REFUND" | "REVOKE";
type FundActionForm = {
amountText: string;
reason: string;
remark: string;
photoItems: PhotoItem[];
requestNo: string;
};
const props = defineProps<{
sharedReason: string;
sharedPhotoItems: PhotoItem[];
upload: (files: File[]) => Promise<PhotoItem[]>;
}>();
const userStore = useUserStore();
const fundCandidateList = ref<FundRecord[]>([]);
const selectedFundIdList = ref<string[]>([]);
const fundActionMap = ref<Record<string, FundAction>>({});
const fundDetailMap = ref<Record<string, FundRecord>>({});
const fundFormMap = ref<Record<string, Partial<Record<FundAction, FundActionForm>>>>({});
const loadingFundDetailIdList = ref<string[]>([]);
const activeFundId = ref("");
const fundActionPopupVisible = ref(false);
const detailFundRecord = ref<FundRecord>();
const fundRecordDetailPopupVisible = ref(false);
const canRefund = computed(() => userStore.hasPermissions(permissionCodes.fund.refund));
const canRevokeFund = computed(() => userStore.hasPermissions(permissionCodes.fund.revoke));
const canManageFund = computed(() => userStore.hasPermissions(permissionCodes.fundRecord.read)
&& (canRefund.value || canRevokeFund.value));
const hasSelected = computed(() => selectedFundIdList.value.length !== 0);
const loadingDetail = computed(() => loadingFundDetailIdList.value.length !== 0);
const activeFundSelection = computed(() => {
const id = activeFundId.value;
const record = fundDetailMap.value[id];
const action = fundActionMap.value[id];
const form = action ? fundFormMap.value[id]?.[action] : undefined;
return record && action && form ? { record, action, form } : undefined;
});
const canRefundActiveFund = computed(() => !!activeFundSelection.value && canRefundFund(activeFundSelection.value.record));
function isFundSelected(record: FundRecord): boolean {
return !!record.id && selectedFundIdList.value.includes(record.id);
}
function isFundDetailLoading(id?: string): boolean {
return !!id && loadingFundDetailIdList.value.includes(id);
}
function getFundAction(record: FundRecord): FundAction | undefined {
return record.id ? fundActionMap.value[record.id] : undefined;
}
function getFundActionTag(record: FundRecord): ActionTag {
const action = getFundAction(record);
if (action === "REFUND") return { content: "退款", theme: "primary" };
if (action === "REVOKE") return { content: "冲正", theme: "warning" };
return { content: "待配置", theme: "warning" };
}
function getFundPhotoTag(record: FundRecord): ActionTag {
const action = getFundAction(record);
return getActionPhotoTag(getFundForm(record.id, action)?.photoItems, props.sharedPhotoItems);
}
function getFundRefundAmountTag(record: FundRecord): ActionTag {
const form = getFundForm(record.id, "REFUND");
const amount = parsePackageAmount(form?.amountText || "");
if (amount === undefined || !(0 < amount)) return { content: "退款金额未填", theme: "danger" };
if (amount === record.amount) return { content: "全额退款", theme: "success" };
if (amount < (record.amount || 0)) return { content: "部分退款", theme: "primary" };
return { content: "超出本笔收款", theme: "danger" };
}
function createFundActionForm(record?: FundRecord): FundActionForm {
return {
amountText: formatPackageAmountInput(record?.amount || 0),
reason: "",
remark: "",
photoItems: [],
requestNo: ""
};
}
function getFundForm(id: string | undefined, action: FundAction | undefined): FundActionForm | undefined {
return id && action ? fundFormMap.value[id]?.[action] : undefined;
}
function setFundAction(id: string, action: FundAction, record?: FundRecord): void {
const oldFormMap = fundFormMap.value[id] || {};
if (!oldFormMap[action]) {
fundFormMap.value = {
...fundFormMap.value,
[id]: { ...oldFormMap, [action]: createFundActionForm(record) }
};
}
fundActionMap.value = { ...fundActionMap.value, [id]: action };
}
function removeFundSelection(id: string): void {
selectedFundIdList.value = selectedFundIdList.value.filter(item => item !== id);
const actionMap = { ...fundActionMap.value };
delete actionMap[id];
fundActionMap.value = actionMap;
const formMap = { ...fundFormMap.value };
delete formMap[id];
fundFormMap.value = formMap;
}
function toggleFundSelected(record: FundRecord): void {
setFundSelected(record, !isFundSelected(record));
}
function setFundSelected(record: FundRecord, selected: boolean): void {
if (!record.id) return;
if (selected) {
if (!isFundSelected(record)) selectedFundIdList.value = [...selectedFundIdList.value, record.id];
return;
}
removeFundSelection(record.id);
}
async function loadFundDetail(record: FundRecord, errorMessage: string): Promise<FundRecord | undefined> {
const id = record.id;
if (!id || isFundDetailLoading(id)) return undefined;
const cached = fundDetailMap.value[id];
if (cached) return cached;
loadingFundDetailIdList.value = [...loadingFundDetailIdList.value, id];
try {
const detail = await SalesOrderAPI.fundRecordDetail(id);
fundDetailMap.value = { ...fundDetailMap.value, [id]: detail };
return detail;
} catch (error) {
Message.error(getErrorMessage(error, errorMessage));
return undefined;
} finally {
loadingFundDetailIdList.value = loadingFundDetailIdList.value.filter(item => item !== id);
}
}
function canRefundFund(record: FundRecord): boolean {
return canRefund.value && record.operationType === "RECEIVE";
}
async function openFundConfig(record: FundRecord): Promise<void> {
const id = record.id;
if (!id || !isFundSelected(record) || isFundDetailLoading(id)) return;
const detail = await loadFundDetail(record, "资金流水校验失败");
if (!detail) {
removeFundSelection(id);
return;
}
if (!isFundSelected(record)) return;
if (detail.status !== "VERIFIED" || detail.operationType === "REVOKE" || detail.revokeRecordId) {
removeFundSelection(id);
Message.warning("只有已生效、未被冲正且不是冲正记录的资金流水可以处理");
return;
}
if (!detail.id) return;
const action = fundActionMap.value[detail.id] || (canRefundFund(detail) ? "REFUND" : "REVOKE");
if (action === "REVOKE" && !canRevokeFund.value) {
Message.warning("当前资金流水只能退款,缺少资金冲正权限");
return;
}
setFundAction(detail.id, action, detail);
activeFundId.value = detail.id;
fundActionPopupVisible.value = true;
}
async function openFundDetail(record: FundRecord): Promise<void> {
const detail = await loadFundDetail(record, "资金流水详情加载失败");
if (!detail) return;
detailFundRecord.value = detail;
fundRecordDetailPopupVisible.value = true;
}
function updateActiveFundAction(action: FundAction): void {
const id = activeFundId.value;
const record = fundDetailMap.value[id];
if (!id || !record || (action === "REFUND" && !canRefundFund(record)) || (action === "REVOKE" && !canRevokeFund.value)) return;
setFundAction(id, action, record);
}
function updateActiveFundForm(form: FundActionForm): void {
const id = activeFundId.value;
const action = fundActionMap.value[id];
if (!id || !action) return;
fundFormMap.value = {
...fundFormMap.value,
[id]: { ...fundFormMap.value[id], [action]: form }
};
}
function isFundActionComplete(record: FundRecord): boolean {
const id = record.id;
const action = id && fundActionMap.value[id];
const form = id && action ? getFundForm(id, action) : undefined;
if (!form || !hasActionPhoto(form.photoItems, props.sharedPhotoItems)) return false;
const amount = parsePackageAmount(form.amountText);
return action !== "REFUND" || (amount !== undefined && 0 < amount);
}
function buildFundRevokeList(): OrderPaymentRevokeRequest[] {
return fundCandidateList.value.flatMap(record => {
const id = record.id;
const form = id && fundActionMap.value[id] === "REVOKE" ? getFundForm(id, "REVOKE") : undefined;
return id && form ? [
{
fundRecordId: id,
requestNo: getActionRequestNo(form),
reason: form.reason.trim(),
attachmentList: buildActionAttachmentList(form.photoItems),
remark: form.remark.trim() || null
}
] : [];
});
}
function buildFundRefundList(salesOrderId: string): OrderPaymentRefundRequest[] {
if (!salesOrderId) return [];
return fundCandidateList.value.flatMap(record => {
const id = record.id;
const form = id && fundActionMap.value[id] === "REFUND" ? getFundForm(id, "REFUND") : undefined;
const amount = form && parsePackageAmount(form.amountText);
return form && amount !== undefined ? [
{
salesOrderId,
requestNo: getActionRequestNo(form),
amount,
reason: form.reason.trim(),
attachmentList: buildActionAttachmentList(form.photoItems),
remark: form.remark.trim() || null
}
] : [];
});
}
function getSelectedRefundAmount(): number {
return fundCandidateList.value.reduce((total, record) => {
const id = record.id;
const form = id && fundActionMap.value[id] === "REFUND" ? getFundForm(id, "REFUND") : undefined;
return total + (form ? parsePackageAmount(form.amountText) || 0 : 0);
}, 0);
}
async function load(salesOrderId: string): Promise<FundRecord[]> {
if (!canManageFund.value) return [];
const list = await loadAllPages(index => SalesOrderAPI.fundRecordList({
salesOrderId,
status: "VERIFIED",
index,
size: actionPageSize
}));
return list.filter(item => item.operationType !== "REVOKE" && !item.revokeRecordId
&& (canRevokeFund.value || canRefundFund(item)));
}
function setCandidates(list: FundRecord[]): void {
fundCandidateList.value = list;
}
function getIncompleteIds(): string[] {
return fundCandidateList.value.flatMap(item => item.id && isFundSelected(item) && !isFundActionComplete(item) ? [item.id] : []);
}
async function openIncomplete(id: string): Promise<void> {
const item = fundCandidateList.value.find(candidate => candidate.id === id);
if (item) await openFundConfig(item);
}
function getRevokeAdjustment(): number {
let result = 0;
for (const record of fundCandidateList.value) {
const id = record.id;
const detail = id && fundDetailMap.value[id];
if (!id || fundActionMap.value[id] !== "REVOKE" || !detail) continue;
if (detail.operationType === "RECEIVE") result -= detail.amount || 0;
if (detail.operationType === "REFUND") result += detail.amount || 0;
}
return result;
}
defineExpose({
load,
setCandidates,
hasSelected,
loadingDetail,
getIncompleteIds,
openIncomplete,
buildFundRevokeList,
buildFundRefundList,
getRevokeAdjustment,
getSelectedRefundAmount
});
</script>
<style scoped lang="less">
@import "./salesOrderCancelList.less";
</style>
@@ -0,0 +1,68 @@
<template>
<bottom-popup
:model-value="props.modelValue"
title="资金流水详情"
left-button-text="关闭"
right-button-text=""
:z-index="props.zIndex"
:overlay-props="overlayProps"
@update:model-value="updateVisible"
@left-button-click="updateVisible(false)"
>
<div v-if="props.record" class="detail-popup">
<t-cell title="操作类型" :note="getFundOperationText(props.record.operationType)" />
<t-cell title="金额">
<template #note>
<span class="red text-bold" v-text="`¥${formatPackageAmount(props.record.amount)}`" />
</template>
</t-cell>
<t-cell title="发起时间">
<template #note>
<time-label v-if="props.record.occurredAt" :timestamp="props.record.occurredAt" underline />
<span v-else>未知</span>
</template>
</t-cell>
<t-cell title="发起人" :note="props.record.operator?.nick || props.record.operator?.name" />
<t-cell title="处理人" :note="props.record.verifier?.nick || props.record.verifier?.name" />
<t-cell title="备注" :note="props.record.remark || '无'" />
<div class="photos">
<attachment-selector :items="photoItems" title="业务照片" readonly />
</div>
</div>
</bottom-popup>
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import type { FundRecord } from "@/types/SalesOrder";
import { getAttachmentReadURL } from "@/utils/attachment";
import { formatPackageAmount } from "@/utils/package";
import { getFundOperationText } from "@/utils/salesOrder";
const props = defineProps<{ modelValue: boolean; record?: FundRecord; zIndex?: number }>();
const emit = defineEmits<{ "update:modelValue": [visible: boolean] }>();
const overlayProps = computed(() => undefined === props.zIndex ? undefined : { zIndex: props.zIndex - 1 });
const photoItems = computed<PhotoItem[]>(() => (props.record?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
url: getAttachmentReadURL(item.id || "")
})));
function updateVisible(visible: boolean): void {
emit("update:modelValue", visible);
}
</script>
<style scoped lang="less">
.detail-popup {
.photos {
padding: 1rem;
}
}
</style>
@@ -71,7 +71,7 @@
</template>
<script setup lang="ts">
import SalesOrderFilterPopup from "@/pages/salesOrder/components/SalesOrderFilterPopup.vue";
import SalesOrderFilterPopup from "@/pages/salesOrder/component/SalesOrderFilterPopup.vue";
import type { GaoSalesOrderStatus, GaoSalesOrderType, GaoSalesRefundStatus } from "@/types/SalesOrder";
import { DATE_FILTER_OPTIONS } from "@/utils/dateFilter";
import {
@@ -177,7 +177,7 @@ const isCancelledPendingRefund = computed(() => isCancelled.value && props.order
const showRefundActions = computed(() => props.canRefund && isCancelledPendingRefund.value);
const showMoreActionMenu = computed(() => props.canCancel || showRefundActions.value);
const showReceiveAction = computed(() => props.canReceive && !isCancelled.value && props.order.paymentStatus !== "PAID");
const canCancelOrder = computed(() => props.order.status === "ACTIVE");
const canCancelOrder = computed(() => props.order.status === "ACTIVE" || props.order.status === "FULFILLED");
const canFulfillByPayment = computed(() => props.order.paymentStatus === "PAID" || props.canStoreManager);
const showFulfillAction = computed(() => props.canFulfill && canFulfillByPayment.value && props.order.status === "ACTIVE");
@@ -0,0 +1,46 @@
.action-cell {
--td-spacer: 0;
--td-checkbox-vertical-padding: 0;
:deep(.t-cell__left) {
display: flex;
align-items: center;
.t-checkbox__icon {
margin: 0;
}
}
:deep(.t-cell__title) {
margin: 0;
min-width: 0;
}
.title {
gap: .5rem;
width: 100%;
display: flex;
font-size: .75rem;
align-items: center;
justify-content: space-between;
}
.summary {
flex: 1;
}
.summary,
.description {
gap: .5rem;
display: flex;
min-width: 0;
flex-wrap: wrap;
align-items: center;
}
.actions {
gap: .5rem;
display: flex;
flex-shrink: 0;
}
}
@@ -0,0 +1,37 @@
import type { Attachment } from "timi-web-api";
import type { PhotoItem } from "@/types/Photo";
import { createPackageRequestNo } from "@/utils/package";
export type ActionTag = { content: string; theme: "default" | "primary" | "success" | "warning" | "danger" };
type ListPage<T> = { list?: T[]; total?: number };
export const actionPageSize = 100;
export async function loadAllPages<T>(requestPage: (index: number) => Promise<ListPage<T>>): Promise<T[]> {
const result: T[] = [];
for (let index = 0; ; index += 1) {
const page = await requestPage(index);
const pageList = page.list || [];
result.push(...pageList);
if (pageList.length < actionPageSize || (typeof page.total === "number" && page.total <= result.length)) return result;
}
}
export function getActionPhotoTag(photoItems: PhotoItem[] | undefined, sharedPhotoItems: PhotoItem[]): ActionTag {
if (photoItems?.some(item => !!item.tempFileId)) return { content: "独立凭证", theme: "success" };
if (sharedPhotoItems.some(item => !!item.tempFileId)) return { content: "共用凭证", theme: "primary" };
return { content: "缺少凭证", theme: "danger" };
}
export function hasActionPhoto(photoItems: PhotoItem[], sharedPhotoItems: PhotoItem[]): boolean {
return photoItems.some(item => !!item.tempFileId) || sharedPhotoItems.some(item => !!item.tempFileId);
}
export function buildActionAttachmentList(photoItems: PhotoItem[]): Partial<Attachment>[] {
return photoItems.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
}
export function getActionRequestNo(form: { requestNo: string }): string {
if (!form.requestNo) form.requestNo = createPackageRequestNo();
return form.requestNo;
}
+2 -2
View File
@@ -145,7 +145,7 @@ const entryGroupList: HomeEntryGroup[] = [
path: "/management/sales-orders/create",
permission: permissionCodes.salesOrder.create,
icon: "task-add",
title: "创建订单"
title: "创建产品订单"
},
{
path: "/management/customer-packages/create",
@@ -163,7 +163,7 @@ const entryGroupList: HomeEntryGroup[] = [
path: "/management/sales-orders",
permission: permissionCodes.salesOrder.read,
icon: "task",
title: "订单列表"
title: "销售订单"
},
{
path: "/management/points/redemptions",
+12 -1
View File
@@ -3,7 +3,7 @@ import type { Customer } from "@/types/Customer";
import type { ProductSkuSpecSnapshot, StockRecord } from "@/types/Product";
import type { GaoSalesPaymentStatus } from "@/types/SalesOrder";
export type GaoFulfillmentStatus = "WAITING_STOCK" | "PENDING" | "VERIFIED" | "REJECTED" | "CANCELLED" | "REVOKED";
export type GaoFulfillmentStatus = "WAITING_STOCK" | "PENDING" | "VERIFIED" | "REJECTED" | "CANCELLED" | "REVOKED" | "RETURNED";
export type OrderFulfillmentItem = {
fulfillmentId?: string;
@@ -36,6 +36,7 @@ export type OrderFulfillment = {
operatorUserId?: string;
customer?: Customer;
deliveredAt?: number;
returnedAt?: number;
verifierUserId?: string;
verifiedAt?: number;
sourceFulfillmentId?: string;
@@ -151,4 +152,14 @@ export type FulfillmentRevokeRequest = {
remark?: string | null;
};
export type FulfillmentReturnRequest = {
fulfillmentId: string;
requestNo: string;
returnedAt?: number;
reason: string;
returnedToStore: boolean;
attachmentList?: Partial<Attachment>[];
remark?: string | null;
};
export type FulfillmentPageResult<T> = PageResult<T> & { pages?: number };
+1
View File
@@ -15,6 +15,7 @@ export type StockOperationType =
| "ORDER_RELEASE"
| "ORDER_OUT"
| "ORDER_REVOKE"
| "ORDER_RETURN_IN"
| "STOCKTAKE_GAIN"
| "STOCKTAKE_LOSS";
export type StockRecordDirection = "IN" | "OUT";
+11 -1
View File
@@ -1,6 +1,7 @@
import type { Attachment, Model, PageResult, User } from "timi-web-api";
import type { Customer } from "@/types/Customer";
import type { EventRecord } from "@/types/EventRecord";
import type { FulfillmentRevokeRequest, FulfillmentReturnRequest } from "@/types/Fulfillment";
import type { ProductSkuSpecSnapshot } from "@/types/Product";
export type GaoSalesOrderType = "PACKAGE" | "DIRECT_PRODUCT";
@@ -170,7 +171,16 @@ export type OrderPaymentRevokeRequest = {
remark?: string | null;
};
export type SalesOrderCancelRequest = { salesOrderId: string; reason: string };
export type SalesOrderCancelRequest = {
salesOrderId: string;
reason: string;
requestNo?: string;
attachmentList?: Partial<Attachment>[];
fulfillmentReturnList?: FulfillmentReturnRequest[];
fulfillmentRevokeList?: FulfillmentRevokeRequest[];
fundRevokeList?: OrderPaymentRevokeRequest[];
fundRefundList?: OrderPaymentRefundRequest[];
};
export type FundRecord = {
storeId?: string;
+2
View File
@@ -96,6 +96,7 @@ export const permissionCodes = {
create: "GAO:ORDER_FULFILLMENT:CREATE",
read: "GAO:ORDER_FULFILLMENT:READ",
verify: "GAO:ORDER_FULFILLMENT:VERIFY",
return: "GAO:ORDER_FULFILLMENT:RETURN",
revoke: "GAO:ORDER_FULFILLMENT:REVOKE"
},
fundReceive: {
@@ -239,6 +240,7 @@ export const gaoStoreScopePermissionCodes = [
permissionCodes.orderFulfillment.create,
permissionCodes.orderFulfillment.read,
permissionCodes.orderFulfillment.verify,
permissionCodes.orderFulfillment.return,
permissionCodes.orderFulfillment.revoke,
permissionCodes.fundReceive.create,
permissionCodes.fundReceive.verify,
+1
View File
@@ -73,6 +73,7 @@ export function getStockOperationText(type?: StockOperationType): string {
ORDER_RELEASE: "履约释放预占",
ORDER_OUT: "履约出库",
ORDER_REVOKE: "履约冲正入库",
ORDER_RETURN_IN: "履约退货入库",
STOCKTAKE_GAIN: "盘盈",
STOCKTAKE_LOSS: "盘亏"
} as Record<string, string>)[type || ""] || "未知操作";
+2 -2
View File
@@ -26,10 +26,10 @@ export function getSalesOrderItemTypeText(type?: GaoSalesOrderItemType): string
return type === "PACKAGE_ENTITLEMENT" ? "套餐权益" : type === "DIRECT_PRODUCT" ? "直接产品" : "未知来源";
}
export function getFulfillmentStatusText(status?: GaoFulfillmentStatus): string {
return ({ WAITING_STOCK: "等待库存", PENDING: "待核销", VERIFIED: "已核销", REJECTED: "已拒绝", CANCELLED: "已撤销", REVOKED: "已冲正" } as Record<string, string>)[status || ""] || "未知";
return ({ WAITING_STOCK: "等待库存", PENDING: "待核销", VERIFIED: "已核销", REJECTED: "已拒绝", CANCELLED: "已撤销", REVOKED: "已冲正", RETURNED: "已退货" } as Record<string, string>)[status || ""] || "未知";
}
export function getStatusTheme(status?: string): "success" | "warning" | "danger" | "default" {
if (["VERIFIED", "PAID", "FULFILLED"].includes(status || "")) return "success";
if (["VERIFIED", "PAID", "FULFILLED", "RETURNED"].includes(status || "")) return "success";
if (["PENDING", "ACTIVE", "WAITING_STOCK"].includes(status || "")) return "warning";
if (["REJECTED", "CANCELLED"].includes(status || "")) return "danger";
return "default";