refactor(brush-order,promotion-fee): 重构为左侧店铺列表+右侧记录表格布局,支持快捷新增

This commit is contained in:
小蟑螂
2026-05-15 16:14:00 +08:00
parent 4d1c9e5e8d
commit 61258e8714
4 changed files with 683 additions and 360 deletions
@@ -35,23 +35,25 @@ import { getShopPageApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'BrushOrderFormModal' });
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
// Props
interface Props {
open: boolean;
brushOrderData?: null | BrushOrderVO.Info;
/** 新增时预填店铺(编辑时忽略) */
presetShopId?: number | null;
}
// Emits
interface Emits {
(e: 'update:open', value: boolean): void;
(e: 'success'): void;
(e: 'cancel'): void;
}
const props = withDefaults(defineProps<Props>(), {
presetShopId: null,
});
const emit = defineEmits<Emits>();
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
const [Modal, modalApi] = useVbenModal({
draggable: true,
@@ -152,6 +154,9 @@ watch(
};
} else {
resetFormData();
if (props.presetShopId != null && props.presetShopId !== undefined) {
formData.value.shopId = props.presetShopId;
}
}
await nextTick();
modalApi.open();
@@ -299,7 +304,6 @@ const resetFormData = () => {
productSpecId: undefined,
brushAmount: undefined as any,
brushTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
quantity: 1,
remark: undefined,
};
@@ -1,38 +1,56 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { BrushOrderDTO, BrushOrderVO } from '#/api/ecommerce/brush-order';
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
import {
Button,
Card,
DatePicker,
Empty,
Flex,
InputNumber,
message,
Popconfirm,
Select,
Space,
Spin,
} from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteBrushOrderApi,
getBrushOrderPageApi,
} from '#/api/ecommerce/brush-order';
import { getShopPageApi } from '#/api/ecommerce/shop';
import { getProductPageApi } from '#/api/ecommerce/product';
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
import BrushOrderFormModal from './components/BrushOrderFormModal.vue';
defineOptions({ name: 'BrushOrderManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
const StoreIcon = createIconifyIcon('lucide:store');
// 响应式数据
const loading = ref(false);
const shopsLoading = ref(false);
const shops = ref<ShopVO.Info[]>([]);
/** 未选店铺:undefined 表示全部 */
const selectedShopId = ref<number | undefined>(undefined);
const formModalVisible = ref(false);
const currentBrushOrderData = ref<BrushOrderVO.Info | null>(null);
const presetShopIdForModal = ref<number | null>(null);
// 搜索表单
const searchForm = ref({
shopId: undefined as number | undefined,
productId: undefined as number | undefined,
minBrushAmount: undefined as number | undefined,
maxBrushAmount: undefined as number | undefined,
@@ -40,56 +58,146 @@ const searchForm = ref({
endBrushTime: undefined as string | undefined,
});
// 店铺选项(从搜索表单中获取)
const shopOptions = ref<{ label: string; value: number }[]>([]);
const productOptions = ref<{ label: string; value: number }[]>([]);
const productPage = ref(1);
const productPageSize = 20;
const productTotal = ref(0);
const productLoading = ref(false);
const productSearchKeyword = ref('');
const productLoaded = ref(false);
let productSearchTimer: null | ReturnType<typeof setTimeout> = null;
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
function productOptionLabel(p: ProductVO.Info) {
const code = p.productCode ? ` · ${p.productCode}` : '';
return `${p.name}${code}`;
}
async function fetchProducts(page = 1, append = false) {
if (productLoading.value) return;
productLoading.value = true;
try {
const kw = productSearchKeyword.value.trim();
const params: PageQueryDTO<ProductDTO.Filters> = {
page,
pageSize: productPageSize,
filters: kw ? { keywords: kw } : {},
};
const data = await getProductPageApi(params);
const mapped = data.records.map((p: ProductVO.Info) => ({
label: productOptionLabel(p),
value: p.id,
}));
productOptions.value = append ? [...productOptions.value, ...mapped] : mapped;
productTotal.value = data.total;
productPage.value = page;
productLoaded.value = true;
} catch {
message.error('获取商品列表失败');
if (!append) productOptions.value = [];
} finally {
productLoading.value = false;
}
}
function handleProductSearch(value: string) {
if (productSearchTimer) clearTimeout(productSearchTimer);
productSearchTimer = setTimeout(() => {
productSearchKeyword.value = value;
productPage.value = 1;
void fetchProducts(1, false);
}, 300);
}
function handleProductPopupScroll(e: Event) {
const target = e.target as HTMLElement;
const { scrollTop, scrollHeight, clientHeight } = target;
if (scrollHeight - scrollTop - clientHeight < 50) {
const hasMore = productPage.value * productPageSize < productTotal.value;
if (hasMore && !productLoading.value) {
void fetchProducts(productPage.value + 1, true);
}
}
}
async function loadShops() {
shopsLoading.value = true;
try {
const response = await getShopPageApi({
page: 1,
pageSize: 500,
filters: {},
});
shops.value = response.records ?? [];
} catch {
message.error('获取店铺列表失败');
shops.value = [];
} finally {
shopsLoading.value = false;
}
}
const selectedShopLabel = computed(() => {
if (selectedShopId.value == null) {
return '全部店铺';
}
const s = shops.value.find((x) => x.id === selectedShopId.value);
return s?.name ?? `店铺 #${selectedShopId.value}`;
});
function selectShopAll() {
selectedShopId.value = undefined;
}
function selectShop(id: number) {
selectedShopId.value = id;
}
const gridOptions: VxeGridProps<BrushOrderVO.Info> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
width: 56,
title: '序号',
},
{
field: 'shopName',
title: '店铺名称',
minWidth: 'auto',
minWidth: 120,
showOverflow: 'tooltip' as const,
},
{
title: '商品信息',
minWidth: 'auto',
minWidth: 160,
slots: { default: 'productInfo' },
},
{
field: 'quantity',
title: '刷单数量',
minWidth: 'auto',
width: 100,
},
{
title: '刷单金额',
minWidth: 'auto',
width: 120,
slots: { default: 'brushAmount' },
},
{
field: 'brushTime',
title: '刷单时间',
minWidth: 'auto',
minWidth: 160,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 'auto',
minWidth: 160,
},
{
title: '操作',
minWidth: 'auto',
width: 140,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
height: '100%',
border: true,
stripe: true,
rowConfig: { isHover: true },
@@ -124,7 +232,6 @@ const gridOptions: VxeGridProps<any> = {
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
@@ -134,26 +241,19 @@ const gridOptions: VxeGridProps<any> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: searchForm.value.shopId,
productId: searchForm.value.productId,
shopId: selectedShopId.value,
productId: searchForm.value.productId || undefined,
minBrushAmount: searchForm.value.minBrushAmount,
maxBrushAmount: searchForm.value.maxBrushAmount,
startBrushTime: searchForm.value.startBrushTime,
endBrushTime: searchForm.value.endBrushTime,
startBrushTime: searchForm.value.startBrushTime || undefined,
endBrushTime: searchForm.value.endBrushTime || undefined,
},
};
const data = await getBrushOrderPageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取刷单记录列表失败:', error);
return { items: data.records, total: data.total };
} catch {
message.error('获取刷单记录列表失败');
return {
items: [],
total: 0,
};
return { items: [], total: 0 };
} finally {
loading.value = false;
}
@@ -162,116 +262,60 @@ const gridOptions: VxeGridProps<any> = {
},
};
// 搜索表单配置(避免 formOptions 与 gridApi 循环推断)
const gridReloadRef = ref<(() => void) | null>(null);
const formOptions = computed(() => ({
schema: [
{
component: 'Select',
componentProps: {
placeholder: '请选择店铺',
options: shopOptions,
allowClear: true,
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'shopId',
label: '店铺',
},
{
component: 'InputNumber',
componentProps: {
placeholder: '商品ID(可选)',
min: 1,
precision: 0,
style: { width: '100%' },
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'productId',
label: '商品',
},
{
component: 'InputNumber',
componentProps: {
placeholder: '最小金额',
min: 0,
precision: 2,
style: { width: '100%' },
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'minBrushAmount',
label: '金额范围',
},
{
component: 'InputNumber',
componentProps: {
placeholder: '最大金额',
min: 0,
precision: 2,
style: { width: '100%' },
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'maxBrushAmount',
label: '',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '开始时间',
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
style: { width: '100%' },
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'startBrushTime',
label: '刷单时间',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '结束时间',
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
style: { width: '100%' },
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'endBrushTime',
label: '',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
gridApi?.reload();
}
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '刷单记录管理',
showSearchForm: false,
tableTitle: '刷单记录',
});
gridReloadRef.value = () => gridApi.reload();
// 处理新增
watch(selectedShopId, () => {
gridApi.reload();
});
onMounted(() => {
void loadShops();
});
function resetModalPreset() {
presetShopIdForModal.value = null;
}
function shopRowClass(id: number | 'all') {
const active =
id === 'all'
? selectedShopId.value === undefined
: selectedShopId.value === id;
return [
'flex cursor-pointer items-center gap-2 rounded-lg border px-3 py-2.5 text-sm font-semibold transition-colors',
active
? 'border-primary bg-primary/8 text-primary'
: 'border-transparent bg-muted/30 text-foreground hover:bg-muted/60',
].join(' ');
}
const handleAdd = () => {
currentBrushOrderData.value = null;
resetModalPreset();
formModalVisible.value = true;
};
// 处理编辑
function handleAddForShop(shopId: number) {
selectShop(shopId);
currentBrushOrderData.value = null;
presetShopIdForModal.value = shopId;
formModalVisible.value = true;
}
const handleEdit = (record: BrushOrderVO.Info) => {
resetModalPreset();
currentBrushOrderData.value = record;
formModalVisible.value = true;
};
// 处理删除
const handleDelete = async (id: number) => {
try {
await deleteBrushOrderApi(id);
@@ -282,44 +326,24 @@ const handleDelete = async (id: number) => {
}
};
// 处理表单成功
const handleFormSuccess = () => {
resetModalPreset();
refreshTable();
};
// 格式化金额
const formatAmount = (amount: number) => {
return `¥${amount.toFixed(2)}`;
const handleFormCancel = () => {
resetModalPreset();
formModalVisible.value = false;
};
// 加载店铺选项
const loadShopOptions = async () => {
try {
const response = await getShopPageApi({
page: 1,
pageSize: 1000,
filters: {},
});
shopOptions.value = response.records.map((shop: ShopVO.Info) => ({
label: shop.name,
value: shop.id,
}));
} catch (error) {
console.error('加载店铺列表失败:', error);
}
};
// 组件挂载时加载数据
onMounted(() => {
loadShopOptions();
});
const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
</script>
<template>
<Page title="刷单记录管理" auto-content-height>
<Page title="刷单记录管理" :auto-content-height="true">
<template #description>
<div class="text-foreground/80 mt-2">
管理店铺刷单记录,支持按店铺、商品、金额、时间等维度查询和统计
左侧选择店铺筛选右侧记录;未选店铺时展示全部。可在店铺行快捷新增该店铺刷单记录。
</div>
</template>
@@ -332,55 +356,222 @@ onMounted(() => {
</Space>
</template>
<!-- 数据表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<span class="text-gray-500">
支持按店铺、商品、金额、时间等维度查询刷单记录
<Flex gap="middle" class="h-full min-h-0">
<Card
class="flex h-full w-[420px] shrink-0 flex-col"
:body-style="{
height: '100%',
display: 'flex',
flexDirection: 'column',
gap: '8px',
minHeight: 0,
padding: '12px',
}"
>
<template #title>
<span class="flex items-center gap-2 text-base font-semibold">
<StoreIcon class="h-4 w-4" />
店铺
</span>
</Space>
</template>
</template>
<Spin :spinning="shopsLoading" class="flex min-h-0 flex-1 flex-col">
<div class="flex min-h-0 flex-1 flex-col overflow-y-auto">
<button
type="button"
:class="shopRowClass('all')"
class="mb-1 w-full text-left"
@click="selectShopAll"
>
<span class="min-w-0 flex-1 truncate">全部店铺</span>
<span class="shrink-0 text-xs font-normal text-muted-foreground">
全部记录
</span>
</button>
<Empty
v-if="!shopsLoading && shops.length === 0"
class="py-8"
description="暂无店铺"
/>
<div v-else class="space-y-1">
<div
v-for="shop in shops"
:key="shop.id"
:class="shopRowClass(shop.id)"
class="group w-full"
>
<button
type="button"
class="min-w-0 flex-1 truncate text-left"
@click="selectShop(shop.id)"
>
{{ shop.name }}
</button>
<Button
type="link"
size="small"
class="!h-7 shrink-0 !px-1 !text-xs font-semibold opacity-80 group-hover:opacity-100"
@click.stop="handleAddForShop(shop.id)"
>
<PlusIcon class="mr-0.5 inline h-3.5 w-3.5" />
添加
</Button>
</div>
</div>
</div>
</Spin>
</Card>
<!-- 商品信息列 -->
<template #productInfo="{ row }: { row: any }">
<div v-if="row.productName">
<div style="font-weight: bold">{{ row.productName }}</div>
<div v-if="row.productSpecName" style="color: #666; font-size: 12px">
{{ row.productSpecName }}
<Card
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
:body-style="{
height: '100%',
minHeight: 0,
padding: 0,
display: 'flex',
flexDirection: 'column',
}"
>
<template #title>
<span class="text-base font-semibold">刷单记录</span>
</template>
<div
class="shrink-0 space-y-2 border-t border-border px-4 py-3"
>
<div class="flex flex-wrap items-end gap-2">
<div class="flex min-w-0 flex-col gap-0.5">
<span class="text-xs text-muted-foreground">商品</span>
<Select
v-model:value="searchForm.productId"
allow-clear
show-search
:filter-option="false"
placeholder="名称/编码搜索"
class="min-w-[220px] max-w-[320px]"
:options="productOptions"
:loading="productLoading"
:dropdown-match-select-width="false"
:dropdown-style="{ maxHeight: '300px', overflow: 'auto' }"
@search="handleProductSearch"
@popup-scroll="handleProductPopupScroll"
@focus="
() => {
if (!productLoaded) void fetchProducts(1, false);
}
"
@change="() => refreshTable()"
/>
</div>
<div class="flex flex-col gap-0.5">
<span class="text-xs text-muted-foreground">金额 ≥</span>
<InputNumber
v-model:value="searchForm.minBrushAmount"
:min="0"
:precision="2"
placeholder="最小"
class="!w-[110px]"
allow-clear
@press-enter="refreshTable"
@blur="refreshTable"
/>
</div>
<div class="flex flex-col gap-0.5">
<span class="text-xs text-muted-foreground">金额 ≤</span>
<InputNumber
v-model:value="searchForm.maxBrushAmount"
:min="0"
:precision="2"
placeholder="最大"
class="!w-[110px]"
allow-clear
@press-enter="refreshTable"
@blur="refreshTable"
/>
</div>
<div class="flex flex-col gap-0.5">
<span class="text-xs text-muted-foreground">刷单时间起</span>
<DatePicker
v-model:value="searchForm.startBrushTime"
show-time
value-format="YYYY-MM-DD HH:mm:ss"
format="YYYY-MM-DD HH:mm:ss"
placeholder="开始"
class="w-[180px]"
allow-clear
@change="() => refreshTable()"
/>
</div>
<div class="flex flex-col gap-0.5">
<span class="text-xs text-muted-foreground">刷单时间止</span>
<DatePicker
v-model:value="searchForm.endBrushTime"
show-time
value-format="YYYY-MM-DD HH:mm:ss"
format="YYYY-MM-DD HH:mm:ss"
placeholder="结束"
class="w-[180px]"
allow-clear
@change="() => refreshTable()"
/>
</div>
<Button type="default" size="small" class="mb-0.5" @click="refreshTable">
查询
</Button>
</div>
<div class="text-xs text-muted-foreground">
当前:{{ selectedShopLabel }}
</div>
</div>
<span v-else class="text-gray-400">-</span>
</template>
<!-- 刷单金额列 -->
<template #brushAmount="{ row }: { row: any }">
<span class="font-medium text-green-600">
{{ formatAmount(row.brushAmount || 0) }}
</span>
</template>
<div class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3">
<Grid :loading="loading" class="h-full min-h-0">
<template #toolbar-tools>
<span class="text-xs text-muted-foreground">
修改筛选后点击「查询」或失焦/回车刷新;左侧切换店铺立即刷新
</span>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Popconfirm
title="确定要删除这条刷单记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger> 删除 </Button>
</Popconfirm>
</Space>
</template>
</Grid>
<template #productInfo="{ row }">
<div v-if="row.productName">
<div class="font-semibold">{{ row.productName }}</div>
<div
v-if="row.productSpecName"
class="text-xs text-muted-foreground"
>
{{ row.productSpecName }}
</div>
</div>
<span v-else class="text-muted-foreground">—</span>
</template>
<template #brushAmount="{ row }">
<span class="font-semibold text-green-600">
{{ formatAmount(row.brushAmount ?? 0) }}
</span>
</template>
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">编辑</Button>
<Popconfirm
title="确定要删除这条刷单记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
</Card>
</Flex>
<!-- 表单弹窗 -->
<BrushOrderFormModal
v-model:open="formModalVisible"
:brush-order-data="currentBrushOrderData"
:preset-shop-id="presetShopIdForModal"
@success="handleFormSuccess"
@cancel="formModalVisible = false"
@cancel="handleFormCancel"
/>
</Page>
</template>
@@ -35,23 +35,25 @@ import { getShopPageApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'PromotionFeeFormModal' });
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
// Props
interface Props {
open: boolean;
promotionFeeData?: null | PromotionFeeVO.Info;
/** 新增时预填店铺(编辑时忽略) */
presetShopId?: number | null;
}
// Emits
const props = withDefaults(defineProps<Props>(), {
presetShopId: null,
});
interface Emits {
(e: 'update:open', value: boolean): void;
(e: 'success'): void;
(e: 'cancel'): void;
}
const emit = defineEmits<Emits>();
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[800px]',
@@ -159,6 +161,9 @@ watch(
};
} else {
resetFormData();
if (props.presetShopId != null && props.presetShopId !== undefined) {
formData.value.shopId = props.presetShopId;
}
}
await nextTick();
modalApi.open();
@@ -4,14 +4,26 @@ import type {
PromotionFeeDTO,
PromotionFeeVO,
} from '#/api/ecommerce/promotion-fee/types';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref } from 'vue';
import { computed, onMounted, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
import {
Button,
Card,
DatePicker,
Empty,
Flex,
message,
Popconfirm,
Select,
Space,
Spin,
} from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@@ -26,34 +38,19 @@ import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
defineOptions({ name: 'PromotionFeeManagement' });
const PlusIcon = createIconifyIcon('lucide:plus');
const StoreIcon = createIconifyIcon('lucide:store');
const loading = ref(false);
const shopsLoading = ref(false);
const shops = ref<ShopVO.Info[]>([]);
/** 未选择具体店铺:undefined 表示全部店铺 */
const selectedShopId = ref<number | undefined>(undefined);
const formModalVisible = ref(false);
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
const presetShopIdForModal = ref<number | null>(null);
// 店铺选择器(首次触发时加载)
const shopOptions = ref<{ label: string; value: number }[]>([]);
const shopLoading = ref(false);
const shopFetched = ref(false);
async function fetchShopOptions() {
if (shopFetched.value || shopLoading.value) return;
shopLoading.value = true;
try {
const data = await getShopPageApi({ page: 1, pageSize: 100, filters: {} });
shopOptions.value = (data.records || []).map((shop: any) => ({
label: shop.name,
value: shop.id,
}));
shopFetched.value = true;
} catch (error) {
console.error('获取店铺列表失败:', error);
} finally {
shopLoading.value = false;
}
}
// 推广费类型选择器(首次触发时加载)
const feeTypeOptions = ref<{ label: string; value: number }[]>([]);
const feeTypeLoading = ref(false);
const feeTypeFetched = ref(false);
@@ -63,38 +60,64 @@ async function fetchFeeTypeOptions() {
feeTypeLoading.value = true;
try {
const data = await getAllPromotionFeeTypeListApi();
feeTypeOptions.value = (data || []).map((type: any) => ({
feeTypeOptions.value = (data || []).map((type: { id: number; typeName: string }) => ({
label: type.typeName,
value: type.id,
}));
feeTypeFetched.value = true;
} catch (error) {
console.error('获取推广费类型列表失败:', error);
} catch {
message.error('获取推广费类型失败');
} finally {
feeTypeLoading.value = false;
}
}
// 搜索表单
const searchForm = ref({
shopId: undefined as number | undefined,
feeTypeId: undefined as number | undefined,
feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined,
});
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
async function loadShops() {
shopsLoading.value = true;
try {
const data = await getShopPageApi({ page: 1, pageSize: 500, filters: {} });
shops.value = data.records ?? [];
} catch {
message.error('获取店铺列表失败');
shops.value = [];
} finally {
shopsLoading.value = false;
}
}
const selectedShopLabel = computed(() => {
if (selectedShopId.value == null) {
return '全部店铺';
}
const s = shops.value.find((x) => x.id === selectedShopId.value);
return s?.name ?? `店铺 #${selectedShopId.value}`;
});
function selectShopAll() {
selectedShopId.value = undefined;
}
function selectShop(id: number) {
selectedShopId.value = id;
}
const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
minWidth: 56,
title: '序号',
},
{
field: 'shopName',
title: '店铺',
minWidth: 'auto',
minWidth: 120,
showOverflow: 'tooltip' as const,
},
{
@@ -114,33 +137,33 @@ const gridOptions: VxeGridProps<any> = {
{
field: 'feeTypeName',
title: '推广费类型',
minWidth: 'auto',
minWidth: 110,
showOverflow: 'tooltip' as const,
},
{
field: 'campaignName',
title: '推广活动',
minWidth: 'auto',
minWidth: 120,
showOverflow: 'tooltip' as const,
},
{
title: '推广费金额',
minWidth: 'auto',
minWidth: 110,
slots: { default: 'feeAmount' },
},
{
field: 'feeDate',
title: '发生日期',
minWidth: 'auto',
minWidth: 110,
},
{
title: '操作',
minWidth: 'auto',
minWidth: 140,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
height: '100%',
border: true,
stripe: true,
rowConfig: { isHover: true },
@@ -184,7 +207,7 @@ const gridOptions: VxeGridProps<any> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: searchForm.value.shopId || undefined,
shopId: selectedShopId.value,
feeTypeId: searchForm.value.feeTypeId || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined,
@@ -192,8 +215,7 @@ const gridOptions: VxeGridProps<any> = {
};
const data = await getPromotionFeePageApi(params);
return { items: data.records, total: data.total };
} catch (error) {
console.error('获取推广费记录列表失败:', error);
} catch {
message.error('获取推广费记录列表失败');
return { items: [], total: 0 };
} finally {
@@ -204,90 +226,44 @@ const gridOptions: VxeGridProps<any> = {
},
};
// 搜索表单配置
const gridReloadRef = ref<(() => void) | null>(null);
const formOptions = computed(() => ({
schema: [
{
component: 'Select',
componentProps: {
placeholder: '请选择店铺',
options: shopOptions,
allowClear: true,
showSearch: true,
filterOption: false,
loading: shopLoading,
onFocus: fetchShopOptions,
onChange: (val: any) => {
searchForm.value.shopId = val;
gridReloadRef.value?.();
},
},
fieldName: 'shopId',
label: '店铺',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择推广费类型',
options: feeTypeOptions,
allowClear: true,
showSearch: true,
filterOption: false,
loading: feeTypeLoading,
onFocus: fetchFeeTypeOptions,
onChange: (val: any) => {
searchForm.value.feeTypeId = val;
gridReloadRef.value?.();
},
},
fieldName: 'feeTypeId',
label: '推广费类型',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '开始日期',
style: { width: '100%' },
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'feeDateStart',
label: '发生日期',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '结束日期',
style: { width: '100%' },
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'feeDateEnd',
label: '至',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
function refreshTable() {
gridApi?.reload();
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '推广费管理',
showSearchForm: false,
tableTitle: '推广记录',
});
gridReloadRef.value = () => gridApi.reload();
watch(selectedShopId, () => {
gridApi.reload();
});
onMounted(() => {
void loadShops();
void fetchFeeTypeOptions();
});
function resetModalPreset() {
presetShopIdForModal.value = null;
}
const handleAdd = () => {
currentPromotionFeeData.value = null;
resetModalPreset();
formModalVisible.value = true;
};
function handleAddForShop(shopId: number) {
selectShop(shopId);
currentPromotionFeeData.value = null;
presetShopIdForModal.value = shopId;
formModalVisible.value = true;
}
const handleEdit = (record: PromotionFeeVO.Info) => {
resetModalPreset();
currentPromotionFeeData.value = record;
formModalVisible.value = true;
};
@@ -303,17 +279,36 @@ async function handleDelete(id: number) {
}
const handleFormSuccess = () => {
resetModalPreset();
refreshTable();
};
const handleFormCancel = () => {
resetModalPreset();
formModalVisible.value = false;
};
const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
function shopRowClass(id: number | 'all') {
const active =
id === 'all'
? selectedShopId.value === undefined
: selectedShopId.value === id;
return [
'flex cursor-pointer items-center gap-2 rounded-lg border px-3 py-2.5 text-sm font-semibold transition-colors',
active
? 'border-primary bg-primary/8 text-primary'
: 'border-transparent bg-muted/30 text-foreground hover:bg-muted/60',
].join(' ');
}
</script>
<template>
<Page title="推广费管理" auto-content-height>
<Page title="推广费管理" :auto-content-height="true">
<template #description>
<div class="text-foreground/80 mt-2">
管理店铺推广费用记录,支持按店铺、类型等维度查询和统计
左侧选择店铺筛选右侧推广记录;未选店铺时展示全部记录。可在店铺行快捷新增该店铺推广费。
</div>
</template>
@@ -321,57 +316,185 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="mr-2 h-4 w-4" />
新增推广费记录
新增推广费
</Button>
</Space>
</template>
<Grid :loading="loading">
<template #toolbar-tools>
<Space>
<span class="text-gray-500">
支持按店铺、类型等维度查询推广费记录
<Flex gap="middle" class="h-full min-h-0">
<!-- 左:店铺(与 company-menu-manage 一致:Card + h-full + 内部滚动) -->
<Card
class="flex h-full w-[420px] shrink-0 flex-col"
:body-style="{
height: '100%',
display: 'flex',
flexDirection: 'column',
gap: '8px',
minHeight: 0,
padding: '12px',
}"
>
<template #title>
<span class="flex items-center gap-2 text-base font-semibold">
<StoreIcon class="h-4 w-4" />
店铺
</span>
</Space>
</template>
<template #category="{ row }: { row: any }">
<span>{{ row.categoryName || '—' }}</span>
</template>
<template #feeAmount="{ row }: { row: any }">
<span class="font-medium text-red-600">
{{ formatAmount(row.feeAmount) }}
</span>
</template>
<template #product="{ row }: { row: any }">
<div>
<div>{{ row.productName || '-' }}</div>
<div v-if="row.productCode" class="text-gray-400 text-xs">
{{ row.productCode }}
</template>
<Spin :spinning="shopsLoading" class="flex min-h-0 flex-1 flex-col">
<div class="flex min-h-0 flex-1 flex-col overflow-y-auto">
<button
type="button"
:class="shopRowClass('all')"
class="mb-1 w-full text-left"
@click="selectShopAll"
>
<span class="min-w-0 flex-1 truncate">全部店铺</span>
<span class="shrink-0 text-xs font-normal text-muted-foreground">
全部记录
</span>
</button>
<Empty
v-if="!shopsLoading && shops.length === 0"
class="py-8"
description="暂无店铺"
/>
<div v-else class="space-y-1">
<div
v-for="shop in shops"
:key="shop.id"
:class="shopRowClass(shop.id)"
class="group w-full"
>
<button
type="button"
class="min-w-0 flex-1 truncate text-left"
@click="selectShop(shop.id)"
>
{{ shop.name }}
</button>
<Button
type="link"
size="small"
class="!h-7 shrink-0 !px-1 !text-xs font-semibold opacity-80 group-hover:opacity-100"
@click.stop="handleAddForShop(shop.id)"
>
<PlusIcon class="mr-0.5 inline h-3.5 w-3.5" />
添加
</Button>
</div>
</div>
</div>
</div>
</template>
</Spin>
</Card>
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Popconfirm
title="确定要删除这条推广费记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger> 删除 </Button>
</Popconfirm>
</Space>
</template>
</Grid>
<!-- 右:推广记录 -->
<Card
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
:body-style="{
height: '100%',
minHeight: 0,
padding: 0,
display: 'flex',
flexDirection: 'column',
}"
>
<template #title>
<span class="text-base font-semibold">推广记录</span>
</template>
<template #extra>
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
<Select
v-model:value="searchForm.feeTypeId"
allow-clear
show-search
:options="feeTypeOptions"
:loading="feeTypeLoading"
placeholder="类型"
class="min-w-[120px]"
option-filter-prop="label"
@dropdown-visible-change="
(open: boolean) => open && fetchFeeTypeOptions()
"
@change="() => refreshTable()"
/>
<DatePicker
v-model:value="searchForm.feeDateStart"
value-format="YYYY-MM-DD"
placeholder="开始"
class="w-[118px]"
allow-clear
@change="() => refreshTable()"
/>
<span class="text-muted-foreground">—</span>
<DatePicker
v-model:value="searchForm.feeDateEnd"
value-format="YYYY-MM-DD"
placeholder="结束"
class="w-[118px]"
allow-clear
@change="() => refreshTable()"
/>
</Space>
</template>
<div
class="shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground"
>
当前:{{ selectedShopLabel }}
</div>
<div class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3">
<Grid :loading="loading" class="h-full min-h-0">
<template #toolbar-tools>
<span class="text-xs text-muted-foreground">
使用上方类型与日期筛选;表格在区域内滚动
</span>
</template>
<template #category="{ row }">
<span>{{ row.categoryName || '—' }}</span>
</template>
<template #feeAmount="{ row }">
<span class="font-semibold text-red-600">
{{ formatAmount(row.feeAmount) }}
</span>
</template>
<template #product="{ row }">
<div>
<div>{{ row.productName || '—' }}</div>
<div
v-if="row.productCode"
class="text-xs text-muted-foreground"
>
{{ row.productCode }}
</div>
</div>
</template>
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">编辑</Button>
<Popconfirm
title="确定要删除这条推广费记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
</Card>
</Flex>
<PromotionFeeFormModal
v-model:open="formModalVisible"
:promotion-fee-data="currentPromotionFeeData"
:preset-shop-id="presetShopIdForModal"
@success="handleFormSuccess"
@cancel="formModalVisible = false"
@cancel="handleFormCancel"
/>
</Page>
</template>