mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:09:19 +08:00
feat(company-overview): 品类多维度经营明细对比导出功能
- 新增指定品类导出和导出全部两种模式 - 表头加全选复选框,每行加单选复选框 - CategoryComparisonTable 新增 categoryExportMode/selectedExportCategoryIds props - index.vue 新增品类导出状态和 handleCategoryExport - apis.ts 新增 exportCategoryOverviewApi - 修复空状态 colspan
This commit is contained in:
+98
-2
@@ -1,14 +1,38 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CompanyOverviewVO } from '#/api/ecommerce/company-overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
defineOptions({ name: 'CategoryComparisonTable' });
|
||||
|
||||
interface Props {
|
||||
categoryComparisons?: CompanyOverviewVO.CategoryComparison[];
|
||||
taxRate: number;
|
||||
categoryExportMode?: boolean;
|
||||
selectedExportCategoryIds?: number[];
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
interface Emits {
|
||||
(e: 'update:selectedExportCategoryIds', ids: number[]): void;
|
||||
(e: 'toggleCategoryExportMode', enabled: boolean): void;
|
||||
(e: 'export'): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
categoryExportMode: false,
|
||||
selectedExportCategoryIds: () => [],
|
||||
});
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const allCategoriesSelected = computed(() => {
|
||||
const total = props.categoryComparisons?.length || 0;
|
||||
return total > 0 && props.selectedExportCategoryIds.length === total;
|
||||
});
|
||||
|
||||
const someCategoriesSelected = computed(() => {
|
||||
return props.selectedExportCategoryIds.length > 0;
|
||||
});
|
||||
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
@@ -35,6 +59,37 @@ const formatPercentPlain = (value: number | undefined) => {
|
||||
包含:规模、成本及最终损益所有维度
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<template v-if="categoryExportMode">
|
||||
<button
|
||||
class="rounded-2xl border border-slate-300 bg-white px-4 py-2 text-sm font-bold text-slate-700 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
@click="emit('toggleCategoryExportMode', false)"
|
||||
>
|
||||
取消选择
|
||||
</button>
|
||||
<button
|
||||
class="rounded-2xl bg-blue-600 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
|
||||
:disabled="selectedExportCategoryIds.length === 0"
|
||||
@click="emit('export')"
|
||||
>
|
||||
导出已选品类 ({{ selectedExportCategoryIds.length }})
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<button
|
||||
class="rounded-2xl border border-slate-300 bg-white px-4 py-2 text-sm font-bold text-slate-700 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
@click="emit('toggleCategoryExportMode', true)"
|
||||
>
|
||||
指定品类导出
|
||||
</button>
|
||||
<button
|
||||
class="rounded-2xl bg-slate-900 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
|
||||
@click="emit('export')"
|
||||
>
|
||||
导出全部
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-container overflow-x-auto">
|
||||
@@ -43,6 +98,26 @@ const formatPercentPlain = (value: number | undefined) => {
|
||||
class="bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] text-xs font-black uppercase text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
v-if="categoryExportMode"
|
||||
rowspan="2"
|
||||
class="border-b border-r border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] p-3 text-center"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allCategoriesSelected"
|
||||
:indeterminate="someCategoriesSelected && !allCategoriesSelected"
|
||||
class="h-4 w-4 cursor-pointer accent-blue-600"
|
||||
@change="
|
||||
emit(
|
||||
'update:selectedExportCategoryIds',
|
||||
allCategoriesSelected
|
||||
? []
|
||||
: (categoryComparisons ?? []).map((c) => c.categoryId!)
|
||||
)
|
||||
"
|
||||
/>
|
||||
</th>
|
||||
<th
|
||||
rowspan="2"
|
||||
class="sticky-col border-b p-6 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-sm dark:shadow-none"
|
||||
@@ -103,6 +178,27 @@ const formatPercentPlain = (value: number | undefined) => {
|
||||
:key="cat.categoryId ?? 'uncategorized'"
|
||||
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
|
||||
>
|
||||
<td
|
||||
v-if="categoryExportMode"
|
||||
class="border-b border-r border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-white p-3 text-center dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="selectedExportCategoryIds.includes(cat.categoryId!)"
|
||||
class="h-4 w-4 cursor-pointer accent-blue-600"
|
||||
@change="
|
||||
(e) => {
|
||||
const checked = (e.target as HTMLInputElement).checked;
|
||||
emit(
|
||||
'update:selectedExportCategoryIds',
|
||||
checked
|
||||
? [...selectedExportCategoryIds, cat.categoryId!]
|
||||
: selectedExportCategoryIds.filter((id) => id !== cat.categoryId)
|
||||
);
|
||||
}
|
||||
"
|
||||
/>
|
||||
</td>
|
||||
<td class="sticky-col border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none">
|
||||
<span class="text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline">
|
||||
{{ cat.categoryName }}
|
||||
@@ -142,7 +238,7 @@ const formatPercentPlain = (value: number | undefined) => {
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!categoryComparisons?.length">
|
||||
<td colspan="14" class="p-8 text-center text-gray-400">
|
||||
<td :colspan="categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
|
||||
暂无数据
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Page } from '@vben/common-ui';
|
||||
import { Button, DatePicker, InputNumber, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview';
|
||||
import { getCompanyOverviewApi, exportCompanyOverviewApi, exportCategoryOverviewApi } from '#/api/ecommerce/company-overview/apis';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
import { exportByPost } from '#/utils/export';
|
||||
|
||||
@@ -50,6 +50,26 @@ const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 品类导出相关
|
||||
const categoryExportMode = ref(false);
|
||||
const selectedExportCategoryIds = ref<number[]>([]);
|
||||
|
||||
const handleCategoryExportToggle = (enabled: boolean) => {
|
||||
categoryExportMode.value = enabled;
|
||||
selectedExportCategoryIds.value = [];
|
||||
};
|
||||
|
||||
const handleCategoryExport = async () => {
|
||||
const params = {
|
||||
dateRange: dateRange.value.map((d) => d.format('YYYY-MM-DD')),
|
||||
taxRate: taxRate.value,
|
||||
};
|
||||
if (selectedExportCategoryIds.value.length > 0) {
|
||||
Object.assign(params, { categoryIds: selectedExportCategoryIds.value });
|
||||
}
|
||||
await exportCategoryOverviewApi(params);
|
||||
};
|
||||
|
||||
// 税率(公司/店铺概览共用持久化)
|
||||
const TAX_RATE_KEY = 'overview-tax-rate';
|
||||
const taxRate = ref<number>(0.04);
|
||||
@@ -534,6 +554,11 @@ const navigateToShopOverview = (shopId: number) => {
|
||||
<CategoryComparisonTable
|
||||
:category-comparisons="overviewData?.categoryComparisons"
|
||||
:tax-rate="taxRate"
|
||||
:category-export-mode="categoryExportMode"
|
||||
:selected-export-category-ids="selectedExportCategoryIds"
|
||||
@toggle-category-export-mode="handleCategoryExportToggle"
|
||||
@update:selected-export-category-ids="selectedExportCategoryIds = $event"
|
||||
@export="handleCategoryExport"
|
||||
/>
|
||||
</div>
|
||||
</Spin>
|
||||
|
||||
Reference in New Issue
Block a user