feat: can fulfillment sku order filter

This commit is contained in:
Timi
2026-11-08 01:39:50 +08:00
parent 7315024a8a
commit 998348f5be
8 changed files with 187 additions and 37 deletions
+19 -5
View File
@@ -3,18 +3,19 @@
<t-tag
v-for="tag in tagList"
:key="tag.key"
size="small"
:size="props.size"
theme="primary"
variant="light-outline"
:content="tag.content"
/>
<t-tag v-if="unitText" size="small" :content="unitText" />
<t-tag v-if="unitText" :size="props.size" :content="unitText" />
</div>
</template>
<script setup lang="ts">
import type { ProductSkuSpecSnapshot } from "@/types/Product";
import { getProductSkuSnapshotText } from "@/utils/product";
import type { TagProps } from "tdesign-mobile-vue";
import type { ProductSkuSpecSnapshot, ProductSkuTagSelection } from "@/types/Product";
import { getProductSkuSnapshotText, getProductSkuSpecEntries } from "@/utils/product";
defineOptions({ name: "ProductSkuTags" });
@@ -23,11 +24,24 @@ interface Props {
snapshot?: ProductSkuSpecSnapshot[];
fallback?: string;
unit?: string | null;
selection?: ProductSkuTagSelection;
size?: TagProps["size"];
}
const props = defineProps<Props>();
const props = withDefaults(defineProps<Props>(), { size: "small" });
const tagList = computed(() => {
if (props.selection) {
const { product, sku } = props.selection;
const entries = getProductSkuSpecEntries(sku, product.specList || []);
const name = product.name?.trim() || "未命名产品";
const skuText = getProductSkuSnapshotText(name, sku.name, sku.specSummary);
return [
{ key: "product", content: name },
...entries.map((entry, index) => ({ key: `spec-${index}`, content: entry.valueName })),
...(!entries.length && skuText ? [{ key: "sku", content: skuText }] : [])
];
}
const result = (props.snapshot || []).flatMap((item, index) => {
const content = item.specValueName?.trim() || item.specName?.trim();
return content ? [{ key: `${item.specId || "spec"}-${item.specValueId || index}`, content }] : [];
+2
View File
@@ -82,6 +82,7 @@
:key="item.id"
class="item"
:order="item"
:fulfillable-sku-id="appliedFilter.fulfillableSkuId"
:can-receive="canReceive"
:can-fulfill="canCreateFulfillment"
:can-cancel="canCancel"
@@ -459,6 +460,7 @@ function buildPageFilter(index = pageIndex.value): SalesOrderPage {
return {
customerId: customerId.value || undefined,
packageConfigId: currentPackageConfigId || undefined,
fulfillableSkuId: filter.fulfillableSkuId || undefined,
keyword: keyword.value || undefined,
orderTypeList: currentPackageConfigId ? ["PACKAGE"] : getEffectiveList(filter.orderTypeList, orderTypeOptions.map(item => item.value)),
statusList: getEffectiveList(filter.statusList, statusOptions.map(item => item.value)),
@@ -9,6 +9,15 @@
@reset="reset"
@confirm="confirm"
>
<template #group-fulfillableSku>
<t-cell title="选择 SKU" arrow @click="productSelectorVisible = true">
<template #note>
<product-sku-tags v-if="draftFilter.fulfillableSkuId" :selection="draftFilter.fulfillableSkuSelection" :fallback="draftFilter.fulfillableSkuName" />
<span v-else>全部</span>
</template>
</t-cell>
<t-button v-if="draftFilter.fulfillableSkuId" size="small" variant="text" content="清除 SKU" @click="clearSku" />
</template>
<template #group-date-after>
<t-cell-group
v-if="draftFilter.dateFilterType === 'custom'"
@@ -31,6 +40,7 @@
</t-cell-group>
</template>
</filter-popup>
<product-select-popup v-model:visible="productSelectorVisible" @select="selectSku" />
<t-popup v-model="startVisible" placement="bottom">
<t-date-time-picker
v-if="startVisible"
@@ -60,6 +70,9 @@
<script setup lang="ts">
import { Time } from "timi-web";
import FilterPopup from "@/components/filter-popup/FilterPopup.vue";
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { ProductSelection } from "@/types/Product";
import type { FilterGroup, FilterModel, FilterValueList } from "@/components/filter-popup/FilterPopup";
import { buildPresetDateRange } from "@/utils/date";
import { DATE_FILTER_OPTIONS as dateOptions } from "@/utils/dateFilter";
@@ -67,6 +80,7 @@ import type { GaoSalesOrderStatus, GaoSalesOrderType, GaoSalesRefundStatus } fro
import {
cloneSalesOrderFilter,
createDefaultSalesOrderFilter,
getFulfillableSkuSelection,
type SalesOrderDateFilterType,
type SalesOrderFilterGroupKey,
type SalesOrderListFilter,
@@ -94,6 +108,7 @@ const popupVisible = computed({
const draftFilter = ref<SalesOrderListFilter>(cloneSalesOrderFilter(props.modelValue));
const startVisible = ref(false);
const endVisible = ref(false);
const productSelectorVisible = ref(false);
const startDraft = ref("");
const endDraft = ref("");
let resetRequested = false;
@@ -119,6 +134,13 @@ const refundOptions: Array<{ label: string; value: GaoSalesRefundStatus }> = [
{ label: "已退款", value: "REFUNDED" }
];
const filterGroups = computed<FilterGroup[]>(() => [
{
key: "fulfillableSku",
title: "可履约 SKU",
options: [],
multiple: false,
columns: 1
},
{
key: "date",
title: "下单时间",
@@ -306,6 +328,11 @@ function reset(): void {
function resetFilterGroup(target: SalesOrderListFilter, source: SalesOrderListFilter, filterKey: SalesOrderFilterGroupKey): void {
switch (filterKey) {
case "fulfillableSku":
target.fulfillableSkuId = source.fulfillableSkuId;
target.fulfillableSkuName = source.fulfillableSkuName;
target.fulfillableSkuSelection = source.fulfillableSkuSelection;
break;
case "date":
target.dateFilterType = source.dateFilterType;
target.dateRange = [...source.dateRange];
@@ -325,6 +352,18 @@ function resetFilterGroup(target: SalesOrderListFilter, source: SalesOrderListFi
}
}
function selectSku(selection: ProductSelection): void {
draftFilter.value.fulfillableSkuId = selection.sku.id || "";
draftFilter.value.fulfillableSkuName = [selection.product.name, selection.sku.specSummary || selection.sku.name].filter(Boolean).join(" · ");
draftFilter.value.fulfillableSkuSelection = getFulfillableSkuSelection(selection);
}
function clearSku(): void {
draftFilter.value.fulfillableSkuId = "";
draftFilter.value.fulfillableSkuName = "";
draftFilter.value.fulfillableSkuSelection = undefined;
}
function confirm(): void {
if ((!props.filterKey || props.filterKey === "date")
&& draftFilter.value.dateFilterType === "custom"
@@ -7,9 +7,18 @@
@click="openFilterPopup('date')"
/>
<t-cell v-if="props.filter.dateFilterType === 'custom'" :note="filterDateRangeText" />
<t-cell title="状态" class="filter-cell" arrow @click="openFilterPopup('statusList')">
<t-cell title="可履约 SKU" class="cell" arrow @click="productSelectorVisible = true">
<template #note>
<div class="filter-tags">
<div v-if="props.filter.fulfillableSkuId" class="tags">
<product-sku-tags size="medium" :selection="props.filter.fulfillableSkuSelection" :fallback="props.filter.fulfillableSkuName" />
<t-button size="extra-small" content="清除" @click.stop="clearSku" />
</div>
<span v-else>全部</span>
</template>
</t-cell>
<t-cell title="状态" class="cell roll-note" arrow @click="openFilterPopup('statusList')">
<template #note>
<div class="tags">
<t-tag
v-for="item in selectedStatusTags"
:key="item"
@@ -20,9 +29,9 @@
</div>
</template>
</t-cell>
<t-cell title="订单条件" class="filter-cell" arrow @click="openFilterPopup('orderTypeList')">
<t-cell title="订单条件" class="cell roll-note" arrow @click="openFilterPopup('orderTypeList')">
<template #note>
<div class="filter-tags">
<div class="tags">
<t-tag
v-for="item in selectedOrderTypeTags"
:key="item"
@@ -33,9 +42,23 @@
</div>
</template>
</t-cell>
<t-cell title="资金条件" class="filter-cell" arrow @click="openFilterPopup('paymentStatusList')">
<t-cell title="资金条件" class="cell roll-note" arrow @click="openFilterPopup('paymentStatusList')">
<template #note>
<div class="filter-tags">
<div class="tags">
<t-tag
v-for="item in selectedPaymentTags"
:key="item"
theme="primary"
variant="light-outline"
:content="item"
/>
<t-tag
v-for="item in selectedPaymentTags"
:key="item"
theme="primary"
variant="light-outline"
:content="item"
/>
<t-tag
v-for="item in selectedPaymentTags"
:key="item"
@@ -46,9 +69,9 @@
</div>
</template>
</t-cell>
<t-cell title="退款条件" class="filter-cell" arrow @click="openFilterPopup('refundStatusList')">
<t-cell title="退款条件" class="cell roll-note" arrow @click="openFilterPopup('refundStatusList')">
<template #note>
<div class="filter-tags">
<div class="tags">
<t-tag
v-for="item in selectedRefundTags"
:key="item"
@@ -68,13 +91,18 @@
:package-config-id="props.packageConfigId"
@confirm="confirmFilter"
/>
<product-select-popup v-model:visible="productSelectorVisible" @select="selectSku" />
</template>
<script setup lang="ts">
import SalesOrderFilterPopup from "@/pages/salesOrder/component/SalesOrderFilterPopup.vue";
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { ProductSelection } from "@/types/Product";
import type { GaoSalesOrderStatus, GaoSalesOrderType, GaoSalesRefundStatus } from "@/types/SalesOrder";
import { DATE_FILTER_OPTIONS } from "@/utils/dateFilter";
import {
getFulfillableSkuSelection,
type SalesOrderFilterGroupKey,
type SalesOrderListFilter,
type SalesOrderPaymentFilter
@@ -124,8 +152,22 @@ const selectedOrderTypeTags = computed(() => getSelectedOptionLabels(props.filte
const selectedPaymentTags = computed(() => getSelectedOptionLabels(props.filter.paymentStatusList, paymentOptions));
const selectedRefundTags = computed(() => getSelectedOptionLabels(props.filter.refundStatusList, refundOptions));
const filterPopupVisible = ref(false);
const productSelectorVisible = ref(false);
const activeFilterKey = ref<SalesOrderFilterGroupKey>();
function selectSku(selection: ProductSelection): void {
emit("confirm", {
...props.filter,
fulfillableSkuId: selection.sku.id || "",
fulfillableSkuName: [selection.product.name, selection.sku.specSummary || selection.sku.name].filter(Boolean).join(" · "),
fulfillableSkuSelection: getFulfillableSkuSelection(selection)
});
}
function clearSku(): void {
emit("confirm", { ...props.filter, fulfillableSkuId: "", fulfillableSkuName: "", fulfillableSkuSelection: undefined });
}
function getSelectedOptionLabels<T extends string>(valueList: T[], options: Array<{ label: string; value: T }>): string[] {
const labels = options.filter(item => valueList.includes(item.value)).map(item => item.label);
return labels.length ? labels : ["未选择"];
@@ -152,28 +194,32 @@ function confirmFilter(value: SalesOrderListFilter): void {
margin: 0;
}
:deep(.t-cell__title) {
flex: 0 0 4.5rem;
margin-right: .75rem;
}
.cell {
:deep(.t-cell__note) {
flex: 1 1 0;
min-width: 0;
overflow: hidden;
text-align: right;
text-overflow: ellipsis;
white-space: nowrap;
}
&.roll-note {
.filter-cell {
.filter-tags {
:deep(.t-cell__title) {
flex: 0 0 4.5rem;
margin-right: .75rem;
}
:deep(.t-cell__note) {
flex: 1 1 0;
min-width: 0;
overflow: hidden;
text-align: right;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.tags {
gap: .4rem;
display: flex;
max-width: 100%;
overflow-x: auto;
justify-content: flex-start;
white-space: nowrap;
justify-content: flex-start;
&::-webkit-scrollbar {
display: none;
@@ -50,13 +50,13 @@
<div class="product">
<div class="items">
<t-tag
v-for="(item, index) in itemList"
v-for="(item, index) in displayItemList"
:key="item.id || `${item.skuId}-${item.skuUnitId}-${index}`"
:content="getProductText(item)"
theme="primary"
:theme="props.fulfillableSkuId ? 'warning' : 'primary'"
variant="light"
/>
<t-tag v-if="!itemList.length" content="暂无产品" />
<t-tag v-if="!displayItemList.length" :content="props.fulfillableSkuId ? '暂无可履约产品' : '暂无产品'" />
</div>
</div>
<div class="summary">
@@ -142,7 +142,7 @@
import { TimeLabel } from "timi-web";
import type { GaoSalesPaymentStatus, SalesOrder } from "@/types/SalesOrder";
import { getCustomerPhotoURL } from "@/utils/customer";
import { formatPackageAmount, getPackageQuantityText } from "@/utils/package";
import { comparePackageQuantity, formatPackageAmount, getPackageQuantityText } from "@/utils/package";
import { getSalesOrderStatusText, getSalesOrderTypeText, getSalesPaymentStatusText, getStatusTheme } from "@/utils/salesOrder";
import { getProductSkuSnapshotText } from "@/utils/product";
@@ -150,6 +150,7 @@ defineOptions({ name: "SalesOrderListCell" });
const props = defineProps<{
order: SalesOrder;
fulfillableSkuId?: string;
canReceive: boolean;
canFulfill: boolean;
canCancel: boolean;
@@ -166,6 +167,9 @@ const emit = defineEmits<{
}>();
const moreVisible = ref(false);
const itemList = computed(() => props.order.itemList || []);
const displayItemList = computed(() => props.fulfillableSkuId
? itemList.value.filter(item => item.skuId === props.fulfillableSkuId && 0 < comparePackageQuantity(item.availableBaseQuantity ?? "0", "0"))
: itemList.value);
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));
@@ -230,9 +234,13 @@ function sumProductQuantity(field: "quantity" | "fulfilledBaseQuantity"): string
}
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 ? "赠送 · " : "";
if (props.fulfillableSkuId) {
const quantity = getPackageQuantityText(item.availableBaseQuantity);
return `${giftText}${item.productNameSnapshot || "未命名产品"}${skuText ? `(${skuText})` : ""} · ${quantity} ${item.baseUnitName || "基础单位"}`;
}
const quantity = getPackageQuantityText(item.quantity);
return `${giftText}${item.productNameSnapshot || "未命名产品"}${skuText ? `(${skuText})` : " "}${quantity}${item.unitSnapshot ? ` ${item.unitSnapshot}` : ""}`;
}
</script>
+6
View File
@@ -116,6 +116,12 @@ export type ProductSelection = {
unit: ProductSkuUnit;
};
/** 产品 SKU 标签所需的产品与规格信息。 */
export type ProductSkuTagSelection = {
product: Pick<Product, "name" | "specList">;
sku: Pick<ProductSku, "name" | "specSummary" | "specValueIdList">;
};
export type ProductCategoryPage = {
storeId?: string;
status?: ProductCategoryStatus;
+1
View File
@@ -78,6 +78,7 @@ export type SalesOrderPage = {
storeId?: string;
customerId?: string;
packageConfigId?: string;
fulfillableSkuId?: string;
orderType?: GaoSalesOrderType;
orderTypeList?: GaoSalesOrderType[];
status?: GaoSalesOrderStatus;
+38 -4
View File
@@ -5,6 +5,7 @@ import type {
GaoSalesRefundStatus
} from "@/types/SalesOrder";
import type { DateTimeRange } from "@/utils/date";
import type { ProductSelection, ProductSkuTagSelection } from "@/types/Product";
import { DATE_FILTER_OPTIONS, type DateFilterType } from "@/utils/dateFilter";
/** 销售订单筛选类型别名,保持现有导入路径兼容。 */
@@ -14,7 +15,7 @@ export type SalesOrderDateFilterType = DateFilterType;
export type SalesOrderPaymentFilter = GaoSalesPaymentStatus | "PENDING_RECEIVE";
/** 销售订单筛选组。 */
export type SalesOrderFilterGroupKey = "date" | "orderTypeList" | "statusList" | "paymentStatusList" | "refundStatusList";
export type SalesOrderFilterGroupKey = "date" | "orderTypeList" | "statusList" | "paymentStatusList" | "refundStatusList" | "fulfillableSku";
/** 销售订单列表筛选条件。 */
export type SalesOrderListFilter = {
@@ -24,8 +25,19 @@ export type SalesOrderListFilter = {
statusList: GaoSalesOrderStatus[];
paymentStatusList: SalesOrderPaymentFilter[];
refundStatusList: GaoSalesRefundStatus[];
fulfillableSkuId: string;
fulfillableSkuName: string;
fulfillableSkuSelection?: ProductSkuTagSelection;
};
/** 提取筛选回显需要的产品和 SKU 信息。 */
export function getFulfillableSkuSelection(selection: ProductSelection): ProductSkuTagSelection {
return {
product: { name: selection.product.name, specList: selection.product.specList },
sku: { name: selection.sku.name, specSummary: selection.sku.specSummary, specValueIdList: selection.sku.specValueIdList }
};
}
/** 创建销售订单筛选默认值。 */
export function createDefaultSalesOrderFilter(): SalesOrderListFilter {
return {
@@ -34,7 +46,9 @@ export function createDefaultSalesOrderFilter(): SalesOrderListFilter {
orderTypeList: ["PACKAGE", "DIRECT_PRODUCT"],
statusList: ["ACTIVE"],
paymentStatusList: ["UNPAID", "PARTIALLY_PAID", "PAID"],
refundStatusList: ["NOT_REQUIRED", "PENDING", "REFUNDED"]
refundStatusList: ["NOT_REQUIRED", "PENDING", "REFUNDED"],
fulfillableSkuId: "",
fulfillableSkuName: ""
};
}
@@ -46,7 +60,10 @@ export function cloneSalesOrderFilter(filter: SalesOrderListFilter): SalesOrderL
orderTypeList: [...filter.orderTypeList],
statusList: [...filter.statusList],
paymentStatusList: [...filter.paymentStatusList],
refundStatusList: [...filter.refundStatusList]
refundStatusList: [...filter.refundStatusList],
fulfillableSkuId: filter.fulfillableSkuId,
fulfillableSkuName: filter.fulfillableSkuName,
fulfillableSkuSelection: filter.fulfillableSkuSelection
};
}
@@ -73,7 +90,24 @@ export function normalizeSalesOrderFilter(value: unknown): SalesOrderListFilter
orderTypeList: normalizeList(source.orderTypeList, defaultFilter.orderTypeList),
statusList: normalizeList(source.statusList, defaultFilter.statusList),
paymentStatusList: normalizeList(source.paymentStatusList, defaultFilter.paymentStatusList),
refundStatusList: normalizeList(source.refundStatusList, defaultFilter.refundStatusList)
refundStatusList: normalizeList(source.refundStatusList, defaultFilter.refundStatusList),
fulfillableSkuId: typeof source.fulfillableSkuId === "string" ? source.fulfillableSkuId : "",
fulfillableSkuName: typeof source.fulfillableSkuName === "string" ? source.fulfillableSkuName : "",
fulfillableSkuSelection: normalizeSkuSelection(source.fulfillableSkuSelection)
};
}
function normalizeSkuSelection(value: unknown): ProductSkuTagSelection | undefined {
if (!value || typeof value !== "object") return undefined;
const selection = value as ProductSkuTagSelection;
if (!selection.product || typeof selection.product.name !== "string" || !selection.sku || typeof selection.sku.name !== "string") return undefined;
return {
product: { name: selection.product.name, specList: Array.isArray(selection.product.specList) ? selection.product.specList : [] },
sku: {
name: selection.sku.name,
specSummary: typeof selection.sku.specSummary === "string" ? selection.sku.specSummary : "",
specValueIdList: normalizeList(selection.sku.specValueIdList, [])
}
};
}