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
@@ -0,0 +1,412 @@
<template>
<div class="sales-order-cell" :class="{ cancelled: isCancelled }">
<div class="header">
<div class="left">
<t-image
v-if="photoURL"
:src="photoURL"
:alt="customerName"
fit="cover"
class="avatar"
/>
<div v-else class="avatar fallback" v-text="avatarText" />
</div>
<div class="main">
<div class="customer-status">
<strong class="customer" v-text="customerName" />
<div class="status">
<t-tag
:content="getSalesOrderTypeText(props.order.orderType)"
theme="primary"
size="small"
variant="light-outline"
/>
<t-tag
:content="getSalesOrderStatusText(props.order.status)"
size="small"
variant="light-outline"
:theme="getStatusTheme(props.order.status)"
/>
<t-tag
v-if="isCancelledPendingRefund"
content="待退款"
:theme="getStatusTheme(props.order.refundStatus)"
size="small"
variant="light-outline"
/>
<t-tag
v-else
:content="getSalesPaymentStatusText(props.order.paymentStatus)"
:theme="getPaymentStatusTheme(props.order.paymentStatus)"
size="small"
variant="light-outline"
/>
</div>
</div>
<div class="order-no" v-text="orderNoText" />
</div>
</div>
<t-divider />
<div class="product">
<div class="items">
<t-tag
v-for="(item, index) in itemList"
:key="item.id || `${item.skuId}-${item.skuUnitId}-${index}`"
:content="getProductText(item)"
theme="primary"
variant="light"
/>
<t-tag v-if="!itemList.length" content="暂无产品" />
</div>
</div>
<div class="summary">
<span v-text="productSummaryText" />
</div>
<t-divider />
<div class="time-payment">
<time-label class="time gray" :timestamp="props.order.purchasedAt" underline />
<div class="amount">
<span class="red">¥</span>
<strong class="value red" v-text="formatPackageAmount(props.order.saleAmount)" />
</div>
</div>
<div class="actions" @click.stop>
<t-popover
v-if="showMoreActionMenu"
v-model:visible="moreVisible"
placement="bottom-left"
theme="light"
>
<t-button
class="more"
variant="text"
size="extra-small"
content="更多"
/>
<template #content>
<div class="more-menu">
<t-button
v-if="props.canCancel"
class="item"
size="extra-small"
variant="text"
theme="danger"
type="button"
:disabled="!canCancelOrder"
@click="handleCancel"
>取消订单</t-button>
<template v-if="showRefundActions">
<t-divider />
<t-button
class="item"
size="extra-small"
variant="text"
type="button"
@click="handleConfirmNoRefund"
>确认无需退款</t-button>
</template>
</div>
</template>
</t-popover>
<t-button
v-if="showRefundActions"
variant="outline"
size="extra-small"
theme="danger"
@click.stop="handleRefund"
>登记退款</t-button>
<t-button
v-if="showReceiveAction"
variant="outline"
size="extra-small"
@click.stop="emit('receive')"
>登记收款</t-button>
<t-button
v-if="showFulfillAction"
variant="outline"
size="extra-small"
@click.stop="emit('fulfill')"
>履约产品</t-button>
<t-button
class="detail"
size="extra-small"
theme="primary"
content="详情"
@click="emit('click')"
/>
</div>
</div>
</template>
<script setup lang="ts">
import { TimeLabel } from "timi-web";
import type { GaoSalesPaymentStatus, SalesOrder } from "@/types/SalesOrder";
import { getCustomerPhotoURL } from "@/utils/customer";
import { formatPackageAmount, getPackageQuantityText } from "@/utils/package";
import { getSalesOrderStatusText, getSalesOrderTypeText, getSalesPaymentStatusText, getStatusTheme } from "@/utils/salesOrder";
import { getProductSkuSnapshotText } from "@/utils/product";
defineOptions({ name: "SalesOrderListCell" });
const props = defineProps<{
order: SalesOrder;
canReceive: boolean;
canFulfill: boolean;
canCancel: boolean;
canRefund: boolean;
canStoreManager: boolean;
}>();
const emit = defineEmits<{
click: [];
cancel: [];
receive: [];
fulfill: [];
refund: [];
confirmNoRefund: [];
}>();
const moreVisible = ref(false);
const itemList = computed(() => props.order.itemList || []);
const customerName = computed(() => props.order.customer?.name || props.order.customer?.code || props.order.customerId || "未知客户");
const avatarText = computed(() => customerName.value.slice(0, 1) || "客");
const photoURL = computed(() => getCustomerPhotoURL(props.order.customer, 64));
const orderNoText = computed(() => `订单号:${props.order.orderNo || props.order.id || "未知"}`);
const totalProductQuantity = computed(() => sumProductQuantity("quantity"));
const productSummaryText = computed(() => `共 ${itemList.value.length} 项 · 订单数量 ${totalProductQuantity.value}`);
const isCancelled = computed(() => props.order.status === "CANCELLED");
const isCancelledPendingRefund = computed(() => isCancelled.value && props.order.refundStatus === "PENDING");
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" || props.order.status === "FULFILLED");
const canFulfillByPayment = computed(() => props.order.paymentStatus === "PAID" || props.canStoreManager);
const showFulfillAction = computed(() => props.canFulfill && canFulfillByPayment.value && props.order.status === "ACTIVE");
function handleCancel(): void {
if (!canCancelOrder.value || !props.order.id) {
return;
}
moreVisible.value = false;
emit("cancel");
}
function handleRefund(): void {
if (!showRefundActions.value || !props.order.id) {
return;
}
moreVisible.value = false;
emit("refund");
}
function handleConfirmNoRefund(): void {
if (!showRefundActions.value || !props.order.id) {
return;
}
moreVisible.value = false;
emit("confirmNoRefund");
}
function getPaymentStatusTheme(status?: GaoSalesPaymentStatus): "success" | "warning" | "danger" | "default" {
if (status === "PAID") {
return "success";
}
if (status === "PARTIALLY_PAID") {
return "warning";
}
if (status === "UNPAID") {
return "danger";
}
return "default";
}
function sumProductQuantity(field: "quantity" | "fulfilledBaseQuantity"): string {
let total = 0;
for (const item of itemList.value) {
const quantity = Number(item[field] || 0);
if (Number.isFinite(quantity)) {
total += quantity;
}
}
return getPackageQuantityText(total.toFixed(3));
}
function getProductText(item: NonNullable<SalesOrder["itemList"]>[number]): string {
const quantity = getPackageQuantityText(item.quantity);
const skuText = getProductSkuSnapshotText(item.productNameSnapshot, item.skuNameSnapshot, item.specSummarySnapshot);
const giftText = item.gifted ? "赠送 · " : "";
return `${giftText}${item.productNameSnapshot || "未命名产品"}${skuText ? `(${skuText})` : " "}${quantity}${item.unitSnapshot ? ` ${item.unitSnapshot}` : ""}`;
}
</script>
<style scoped lang="less">
.sales-order-cell {
gap: .5rem;
padding: 10px;
display: flex;
background: var(--td-bg-color-container);
flex-direction: column;
&.cancelled {
background: var(--td-gray-color-2);
.left,
.product,
.time-payment {
filter: grayscale(1);
}
.customer {
color: var(--td-text-color-secondary);
}
}
.header {
gap: .5rem;
display: flex;
.left {
.avatar {
width: 3.5rem;
height: 3.5rem;
}
}
.main {
gap: .5rem;
flex: 1;
display: flex;
flex-direction: column;
.customer-status {
display: flex;
align-items: center;
justify-content: space-between;
.customer {
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.status {
gap: .25rem;
display: flex;
}
}
.order-no {
color: var(--td-text-color-secondary);
font-size: .75rem;
line-height: 1.5;
}
}
}
.product {
gap: .5rem;
display: flex;
align-items: flex-start;
.items {
flex: 1;
gap: .35rem;
display: flex;
min-width: 0;
flex-wrap: nowrap;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
scrollbar-width: none;
-webkit-overflow-scrolling: touch;
:deep(.t-tag) {
flex: 0 0 auto;
}
&::-webkit-scrollbar {
display: none;
}
}
}
.summary {
color: var(--td-text-color-secondary);
font-size: .75rem;
text-align: right;
line-height: 1.5;
}
.time-payment {
gap: 1rem;
display: flex;
align-items: baseline;
justify-content: space-between;
.time {
font-size: .75rem;
}
.amount {
display: flex;
align-items: baseline;
justify-content: end;
.value {
font-size: 1.5rem;
white-space: nowrap;
}
}
}
.actions {
--td-button-border-radius: .5rem;
gap: .5rem;
display: flex;
justify-content: end;
:deep(.t-popover__content) {
padding: .25rem .5rem;
border-radius: .875rem;
}
.more {
font-weight: normal;
}
.detail {
padding-left: 1.5rem;
padding-right: 1.5rem;
}
}
}
.more-menu {
--td-divider-color: var(--td-gray-color-2);
padding: 0;
display: flex;
flex-direction: column;
.item {
width: 100%;
padding: 0 .5rem;
font-weight: normal;
justify-content: flex-start;
}
}
:deep(.sales-order-cell .avatar .t-image__img) {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: inherit;
}
:global(html.theme-dark) .sales-order-cell {
.fallback {
background: #115e59;
}
}
</style>