mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 11:09:20 +08:00
413 lines
11 KiB
Vue
413 lines
11 KiB
Vue
<script lang="ts" setup>
|
||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||
import type {
|
||
PromotionFeeDTO,
|
||
PromotionFeeVO,
|
||
} from '#/api/ec/promotion-fee/types';
|
||
import type { PageQueryDTO } from '#/types/common';
|
||
|
||
import { computed, onMounted, ref, watch } from 'vue';
|
||
|
||
import { Page } from '@vben/common-ui';
|
||
import { createIconifyIcon } from '@vben/icons';
|
||
|
||
import {
|
||
Button,
|
||
Card,
|
||
DatePicker,
|
||
Flex,
|
||
message,
|
||
Popconfirm,
|
||
Select,
|
||
Space,
|
||
} from 'ant-design-vue';
|
||
|
||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||
import {
|
||
deletePromotionFeeApi,
|
||
getPromotionFeePageApi,
|
||
} from '#/api/ec/promotion-fee';
|
||
import { getAllPromotionFeeTypeListApi } from '#/api/ec/promotion-fee/type/apis';
|
||
import ShopSidebarList from '#/views/ec/components/ShopSidebarList.vue';
|
||
|
||
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
|
||
|
||
defineOptions({ name: 'PromotionFeeManagement' });
|
||
|
||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||
|
||
const loading = ref(false);
|
||
|
||
/** 未选择具体店铺:undefined 表示全部店铺 */
|
||
const selectedShopId = ref<number | undefined>(undefined);
|
||
const selectedShopName = ref<string | undefined>(undefined);
|
||
|
||
const formModalVisible = ref(false);
|
||
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
|
||
const presetShopIdForModal = ref<number | null>(null);
|
||
|
||
const feeTypeOptions = ref<{ label: string; value: number }[]>([]);
|
||
const feeTypeLoading = ref(false);
|
||
const feeTypeFetched = ref(false);
|
||
|
||
async function fetchFeeTypeOptions() {
|
||
if (feeTypeFetched.value || feeTypeLoading.value) return;
|
||
feeTypeLoading.value = true;
|
||
try {
|
||
const data = await getAllPromotionFeeTypeListApi();
|
||
feeTypeOptions.value = (data || []).map(
|
||
(type: { id: number; typeName: string }) => ({
|
||
label: type.typeName,
|
||
value: type.id,
|
||
}),
|
||
);
|
||
feeTypeFetched.value = true;
|
||
} catch {
|
||
message.error('获取推广费类型失败');
|
||
} finally {
|
||
feeTypeLoading.value = false;
|
||
}
|
||
}
|
||
|
||
const searchForm = ref({
|
||
feeTypeId: undefined as number | undefined,
|
||
feeDateStart: undefined as string | undefined,
|
||
feeDateEnd: undefined as string | undefined,
|
||
});
|
||
|
||
const selectedShopLabel = computed(() => {
|
||
if (selectedShopId.value == null) {
|
||
return '全部店铺';
|
||
}
|
||
return selectedShopName.value || `店铺 #${selectedShopId.value}`;
|
||
});
|
||
|
||
function onShopSelect(shop: { id: number; name: string } | null) {
|
||
if (!shop) {
|
||
selectedShopId.value = undefined;
|
||
selectedShopName.value = undefined;
|
||
return;
|
||
}
|
||
selectedShopId.value = shop.id;
|
||
selectedShopName.value = shop.name;
|
||
}
|
||
|
||
function handleAddForShop(shopId: number) {
|
||
currentPromotionFeeData.value = null;
|
||
presetShopIdForModal.value = shopId;
|
||
formModalVisible.value = true;
|
||
}
|
||
|
||
const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
|
||
columns: [
|
||
{
|
||
type: 'seq' as const,
|
||
minWidth: 56,
|
||
title: '序号',
|
||
},
|
||
{
|
||
field: 'shopName',
|
||
title: '店铺',
|
||
minWidth: 120,
|
||
showOverflow: 'tooltip' as const,
|
||
},
|
||
{
|
||
field: 'categoryName',
|
||
title: '类目',
|
||
minWidth: 120,
|
||
showOverflow: 'tooltip' as const,
|
||
slots: { default: 'category' },
|
||
},
|
||
{
|
||
field: 'productName',
|
||
title: '商品',
|
||
minWidth: 180,
|
||
showOverflow: 'tooltip' as const,
|
||
slots: { default: 'product' },
|
||
},
|
||
{
|
||
field: 'feeTypeName',
|
||
title: '推广费类型',
|
||
minWidth: 110,
|
||
showOverflow: 'tooltip' as const,
|
||
},
|
||
{
|
||
field: 'campaignName',
|
||
title: '推广活动',
|
||
minWidth: 120,
|
||
showOverflow: 'tooltip' as const,
|
||
},
|
||
{
|
||
title: '推广费金额',
|
||
minWidth: 110,
|
||
slots: { default: 'feeAmount' },
|
||
},
|
||
{
|
||
field: 'feeDate',
|
||
title: '发生日期',
|
||
minWidth: 110,
|
||
},
|
||
{
|
||
title: '操作',
|
||
minWidth: 140,
|
||
fixed: 'right' as const,
|
||
slots: { default: 'action' },
|
||
},
|
||
],
|
||
height: '100%',
|
||
border: true,
|
||
stripe: true,
|
||
rowConfig: { isHover: true },
|
||
showOverflow: true,
|
||
size: 'small',
|
||
toolbarConfig: {
|
||
custom: true,
|
||
refresh: true,
|
||
zoom: true,
|
||
},
|
||
data: [],
|
||
pagerConfig: {
|
||
enabled: true,
|
||
pageSizes: [10, 20, 50, 100],
|
||
layouts: [
|
||
'PrevJump',
|
||
'PrevPage',
|
||
'Number',
|
||
'NextPage',
|
||
'NextJump',
|
||
'Sizes',
|
||
'FullJump',
|
||
'Total',
|
||
] as (
|
||
| 'FullJump'
|
||
| 'NextJump'
|
||
| 'NextPage'
|
||
| 'Number'
|
||
| 'PrevJump'
|
||
| 'PrevPage'
|
||
| 'Sizes'
|
||
| 'Total'
|
||
)[],
|
||
},
|
||
proxyConfig: {
|
||
ajax: {
|
||
query: async ({ page }) => {
|
||
try {
|
||
loading.value = true;
|
||
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
|
||
page: page.currentPage,
|
||
pageSize: page.pageSize,
|
||
filters: {
|
||
shopId: selectedShopId.value,
|
||
feeTypeId: searchForm.value.feeTypeId || undefined,
|
||
feeDateStart: searchForm.value.feeDateStart || undefined,
|
||
feeDateEnd: searchForm.value.feeDateEnd || undefined,
|
||
},
|
||
};
|
||
const data = await getPromotionFeePageApi(params);
|
||
return { items: data.records, total: data.total };
|
||
} catch {
|
||
message.error('获取推广费记录列表失败');
|
||
return { items: [], total: 0 };
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
function refreshTable() {
|
||
gridApi?.reload();
|
||
}
|
||
|
||
const [Grid, gridApi] = useVbenVxeGrid({
|
||
gridOptions,
|
||
showSearchForm: false,
|
||
tableTitle: '推广记录',
|
||
});
|
||
|
||
watch(selectedShopId, () => {
|
||
gridApi.reload();
|
||
});
|
||
|
||
onMounted(() => {
|
||
void fetchFeeTypeOptions();
|
||
});
|
||
|
||
function resetModalPreset() {
|
||
presetShopIdForModal.value = null;
|
||
}
|
||
|
||
const handleAdd = () => {
|
||
currentPromotionFeeData.value = null;
|
||
resetModalPreset();
|
||
formModalVisible.value = true;
|
||
};
|
||
|
||
const handleEdit = (record: PromotionFeeVO.Info) => {
|
||
resetModalPreset();
|
||
currentPromotionFeeData.value = record;
|
||
formModalVisible.value = true;
|
||
};
|
||
|
||
async function handleDelete(id: number) {
|
||
try {
|
||
await deletePromotionFeeApi(id);
|
||
message.success('删除成功');
|
||
refreshTable();
|
||
} catch {
|
||
message.error('删除失败');
|
||
}
|
||
}
|
||
|
||
const handleFormSuccess = () => {
|
||
resetModalPreset();
|
||
refreshTable();
|
||
};
|
||
|
||
const handleFormCancel = () => {
|
||
resetModalPreset();
|
||
formModalVisible.value = false;
|
||
};
|
||
|
||
const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
|
||
</script>
|
||
|
||
<template>
|
||
<Page title="推广费管理" :auto-content-height="true">
|
||
<template #description>
|
||
<div class="text-foreground/80 mt-2">
|
||
左侧选择店铺筛选右侧推广记录;未选店铺时展示全部记录。可在店铺行快捷新增该店铺推广费。
|
||
</div>
|
||
</template>
|
||
|
||
<template #extra>
|
||
<Space>
|
||
<Button type="primary" @click="handleAdd">
|
||
<PlusIcon class="mr-2 h-4 w-4" />
|
||
新增推广费
|
||
</Button>
|
||
</Space>
|
||
</template>
|
||
|
||
<Flex gap="middle" class="h-full min-h-0 overflow-hidden">
|
||
<ShopSidebarList
|
||
:selected-shop-id="selectedShopId"
|
||
@select="onShopSelect"
|
||
@add-for-shop="handleAddForShop"
|
||
/>
|
||
|
||
<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="handleFormCancel"
|
||
/>
|
||
</Page>
|
||
</template>
|