mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 16:29:20 +08:00
fix(store-overview): 修复重命名后的类型报错
- shopComparisons 类型修正(ShopOverview 非数组) - Segmented options 移除 readonly约束 - 删除未使用的 toggleSort/sortIcon/route/useRoute - 修复 profitAfterTax 可能为 undefined 的比较 - 删除废弃的 product/overview/tabs/OverviewTab.vue
This commit is contained in:
+1
-1
@@ -53,7 +53,7 @@ const modeOptions = [
|
|||||||
{ label: '平台汇总', value: 'platform' },
|
{ label: '平台汇总', value: 'platform' },
|
||||||
{ label: '店铺汇总', value: 'shop' },
|
{ label: '店铺汇总', value: 'shop' },
|
||||||
{ label: '品类汇总', value: 'category' },
|
{ label: '品类汇总', value: 'category' },
|
||||||
] as const;
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
+1
@@ -9,6 +9,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
|
void props; // kept for template compatibility
|
||||||
|
|
||||||
const formatAmount = (amount: number) => {
|
const formatAmount = (amount: number) => {
|
||||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||||
|
|||||||
+1
-13
@@ -85,19 +85,7 @@ const sortedData = computed(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleSort = (field: string) => {
|
|
||||||
if (sortField.value === field) {
|
|
||||||
sortOrder.value = sortOrder.value === 'desc' ? 'asc' : 'desc';
|
|
||||||
} else {
|
|
||||||
sortField.value = field;
|
|
||||||
sortOrder.value = 'desc';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sortIcon = (field: string) => {
|
|
||||||
if (sortField.value !== field) return '';
|
|
||||||
return sortOrder.value === 'desc' ? '↓' : '↑';
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -339,7 +327,7 @@ const sortIcon = (field: string) => {
|
|||||||
{{ totalData.roi !== undefined ? totalData.roi.toFixed(2) : '-' }}
|
{{ totalData.roi !== undefined ? totalData.roi.toFixed(2) : '-' }}
|
||||||
</td>
|
</td>
|
||||||
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base"
|
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base"
|
||||||
:class="totalData.profitAfterTax >= 0 ? 'text-emerald-600' : 'text-rose-600'"
|
:class="(totalData.profitAfterTax ?? 0) >= 0 ? 'text-emerald-600' : 'text-rose-600'"
|
||||||
>
|
>
|
||||||
{{ totalData.profitAfterTax ? formatAmount(totalData.profitAfterTax) : '-' }}
|
{{ totalData.profitAfterTax ? formatAmount(totalData.profitAfterTax) : '-' }}
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
@@ -31,7 +31,6 @@ defineOptions({ name: 'CompanyOverview' });
|
|||||||
|
|
||||||
// 路由
|
// 路由
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
|
||||||
|
|
||||||
// 响应式数据
|
// 响应式数据
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
@@ -356,12 +355,13 @@ const handleExportCompanyOverview = async () => {
|
|||||||
|
|
||||||
let dataToExport: CompanyOverviewVO.ShopComparison[] = [];
|
let dataToExport: CompanyOverviewVO.ShopComparison[] = [];
|
||||||
if (overviewData.value?.shopComparisons) {
|
if (overviewData.value?.shopComparisons) {
|
||||||
|
const shops = overviewData.value.shopComparisons.shops;
|
||||||
dataToExport =
|
dataToExport =
|
||||||
selectedExportShopIds.value.length > 0
|
selectedExportShopIds.value.length > 0
|
||||||
? overviewData.value.shopComparisons.filter((s) =>
|
? shops.filter((s) =>
|
||||||
selectedExportShopIds.value.includes(s.shopId),
|
selectedExportShopIds.value.includes(s.shopId),
|
||||||
)
|
)
|
||||||
: overviewData.value.shopComparisons;
|
: shops;
|
||||||
}
|
}
|
||||||
|
|
||||||
let shopIds: number[] | undefined;
|
let shopIds: number[] | undefined;
|
||||||
|
|||||||
-185
@@ -1,185 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import type { ProductOverviewVO } from '#/api/ecommerce/product-overview/types';
|
|
||||||
|
|
||||||
import { onMounted, ref, watch } from 'vue';
|
|
||||||
|
|
||||||
import { Card, Col, DatePicker, message, Row, Space, Typography } from 'ant-design-vue';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import { getProductOverviewApi } from '#/api/ecommerce/product-overview';
|
|
||||||
|
|
||||||
import ChartCard from '../../../shop/details/components/ChartCard.vue';
|
|
||||||
|
|
||||||
defineOptions({ name: 'ProductOverviewTab' });
|
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
productId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 响应式数据
|
|
||||||
const loading = ref(false);
|
|
||||||
const overviewData = ref<null | ProductOverviewVO.Overview>(null);
|
|
||||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
|
||||||
dayjs().subtract(30, 'day'),
|
|
||||||
dayjs(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 格式化金额
|
|
||||||
function formatCurrency(value: number): string {
|
|
||||||
return `¥${value.toLocaleString('zh-CN', {
|
|
||||||
minimumFractionDigits: 2,
|
|
||||||
maximumFractionDigits: 2,
|
|
||||||
})}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化百分比
|
|
||||||
function formatPercent(value: number): string {
|
|
||||||
return `${(value * 100).toFixed(2)}%`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取商品总览数据
|
|
||||||
async function fetchProductOverview() {
|
|
||||||
if (!props.productId || !dateRange.value) return;
|
|
||||||
try {
|
|
||||||
loading.value = true;
|
|
||||||
const data = await getProductOverviewApi({
|
|
||||||
productId: props.productId,
|
|
||||||
startDate: dateRange.value[0].format('YYYY-MM-DD'),
|
|
||||||
endDate: dateRange.value[1].format('YYYY-MM-DD'),
|
|
||||||
});
|
|
||||||
overviewData.value = data;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取商品总览失败:', error);
|
|
||||||
message.error('获取商品总览失败');
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理日期范围变化
|
|
||||||
function handleDateRangeChange() {
|
|
||||||
fetchProductOverview();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听 productId 变化
|
|
||||||
watch(
|
|
||||||
() => props.productId,
|
|
||||||
(newProductId) => {
|
|
||||||
if (newProductId) {
|
|
||||||
fetchProductOverview();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// 初始化数据
|
|
||||||
onMounted(() => {
|
|
||||||
if (props.productId) {
|
|
||||||
fetchProductOverview();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="flex h-full flex-col">
|
|
||||||
<!-- 日期选择器 -->
|
|
||||||
<Card :loading="loading" class="mb-4 flex-shrink-0">
|
|
||||||
<Space>
|
|
||||||
<span>选择日期范围:</span>
|
|
||||||
<DatePicker.RangePicker
|
|
||||||
v-model:value="dateRange"
|
|
||||||
format="YYYY-MM-DD"
|
|
||||||
@change="handleDateRangeChange"
|
|
||||||
/>
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<!-- 商品名称标题 -->
|
|
||||||
<Card v-if="overviewData" :loading="loading" class="mb-4 flex-shrink-0">
|
|
||||||
<Typography.Title :level="4" style="margin: 0">
|
|
||||||
{{ overviewData.productName }}
|
|
||||||
</Typography.Title>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<!-- 图表展示 -->
|
|
||||||
<div v-if="overviewData" class="min-h-0 flex-1 overflow-auto">
|
|
||||||
<Row :gutter="[16, 16]">
|
|
||||||
<!-- 销售额 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.salesAmount"
|
|
||||||
:formatter="formatCurrency"
|
|
||||||
title="销售额"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<!-- 订单数 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.orderCount"
|
|
||||||
:formatter="(v) => v.toLocaleString()"
|
|
||||||
chart-type="bar"
|
|
||||||
color="#019680"
|
|
||||||
title="订单数"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<!-- 客单价 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.averageOrderValue"
|
|
||||||
:formatter="formatCurrency"
|
|
||||||
color="#ff9800"
|
|
||||||
title="客单价"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<!-- 成本 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.costAmount"
|
|
||||||
:formatter="formatCurrency"
|
|
||||||
color="#f56c6c"
|
|
||||||
title="成本"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<!-- 退款金额 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.refundAmount"
|
|
||||||
:formatter="formatCurrency"
|
|
||||||
color="#e6a23c"
|
|
||||||
title="退款金额"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<!-- 推广费 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.promotionFee"
|
|
||||||
:formatter="formatCurrency"
|
|
||||||
color="#909399"
|
|
||||||
title="推广费"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<!-- 费比 -->
|
|
||||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
|
||||||
<ChartCard
|
|
||||||
:data="overviewData.feeRatio"
|
|
||||||
:formatter="formatPercent"
|
|
||||||
color="#67c23a"
|
|
||||||
title="费比"
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 空状态 -->
|
|
||||||
<div v-else class="flex flex-1 items-center justify-center">
|
|
||||||
<span class="text-gray-400">暂无数据</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
Reference in New Issue
Block a user