feat(统计模式): 添加按月/按期统计切换功能并优化客户阶段显示

- 在CenterOverview组件中添加统计模式切换按钮
- 实现统计模式切换逻辑并触发数据重新加载
- 优化SalesTimelineWithTaskList的客户阶段显示和计算逻辑
- 更新API调用参数以支持不同统计模式
- 调整样式和布局以适应新功能
This commit is contained in:
2025-08-26 11:34:50 +08:00
parent 87cc0e4976
commit 58c6ec1c53
7 changed files with 394 additions and 36 deletions

View File

@@ -1,6 +1,22 @@
<template>
<div class="center-overview">
<h2>整体概览</h2>
<div class="overview-header">
<h2>整体概览</h2>
<div class="stats-toggle">
<button
:class="['toggle-btn', { active: statsMode === 'monthly' }]"
@click="switchStatsMode('monthly')"
>
按月统计
</button>
<button
:class="['toggle-btn', { active: statsMode === 'period' }]"
@click="switchStatsMode('period')"
>
按期统计
</button>
</div>
</div>
<div class="overview-grid">
<div class="overview-card primary">
<div class="card-header">
@@ -87,9 +103,24 @@
</template>
<script setup>
import { computed, reactive } from 'vue'
import { computed, reactive, ref } from 'vue'
import Tooltip from '@/components/Tooltip.vue'
// 统计模式状态
const statsMode = ref('monthly') // 默认按月统计
// 定义emit事件
const emit = defineEmits(['update-check-type'])
// 切换统计模式
const switchStatsMode = (mode) => {
statsMode.value = mode
// 向父组件发送事件修改CheckType的值
const checkTypeValue = mode === 'monthly' ? 'month' : 'period'
emit('update-check-type', checkTypeValue)
console.log('切换统计模式:', mode, '发送CheckType值:', checkTypeValue)
}
// 中心整体概览组件
const props = defineProps({
overallTeamPerformance: {
@@ -193,6 +224,44 @@ const hideTooltip = () => {
padding: 0.5rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
.overview-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
.stats-toggle {
display: flex;
background: #f8fafc;
border-radius: 8px;
padding: 4px;
gap: 2px;
.toggle-btn {
padding: 8px 16px;
border: none;
background: transparent;
border-radius: 6px;
font-size: 0.875rem;
font-weight: 500;
color: #64748b;
cursor: pointer;
transition: all 0.2s ease;
&:hover {
background: #e2e8f0;
color: #475569;
}
&.active {
background: #3b82f6;
color: white;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
}
}
}
h2 {
font-size: 1.3rem;
font-weight: 600;
@@ -365,6 +434,19 @@ const hideTooltip = () => {
.center-overview {
padding: 1rem;
.overview-header {
flex-direction: column;
align-items: flex-start;
gap: 1rem;
.stats-toggle {
.toggle-btn {
padding: 6px 12px;
font-size: 0.8rem;
}
}
}
.overview-grid {
grid-template-columns: repeat(2, 1fr);
gap: 0.75rem;

View File

@@ -18,6 +18,7 @@
<CenterOverview
style="height: 330px;"
:overallTeamPerformance="overallTeamPerformance"
@update-check-type="updateCheckType"
/>
<div class="action-items-compact">
<TeamAlerts style="height: 300px;" :abnormalData="teamAlerts" />
@@ -175,6 +176,29 @@ const averageResponseTime = ref(15)
const timeoutResponseRate = ref(5)
const severeTimeoutRate = ref(2)
const formCompletionRate = ref(90)
const CheckType = ref('month')
// 更新CheckType的方法
const updateCheckType = async (newValue) => {
CheckType.value = newValue
console.log('CheckType已更新为:', newValue)
// 重新获取所有使用CheckType的数据
try {
isLoading.value = true
await fetchOverallTeamPerformance()
await fetchActiveGroups()
await fetchConversionRate()
await fetchTotalCallCount()
await fetchNewCustomers()
await fetchDepositConversions()
console.log('数据已根据新的统计模式重新加载')
} catch (error) {
console.error('重新加载数据失败:', error)
} finally {
isLoading.value = false
}
}
const userStore = useUserStore()
// 路由实例
@@ -216,7 +240,10 @@ async function fetchOverallTeamPerformance() {
const hasParams = params.user_name
// 团队总业绩
try {
const response = await getOverallTeamPerformance(hasParams ? params : undefined)
const response = await getOverallTeamPerformance(hasParams ? {
...params,
check_type: CheckType.value
} : {check_type: CheckType.value})
overallTeamPerformance.value.totalPerformance = response.data
} catch (error) {
console.error('获取整体概览数据失败:', error)
@@ -227,7 +254,10 @@ async function fetchActiveGroups() {
const params = getRequestParams()
const hasParams = params.user_name
try {
const response = await getTotalGroupCount(hasParams ? params : undefined)
const response = await getTotalGroupCount(hasParams ? {
...params,
check_type: CheckType.value
} : {check_type: CheckType.value})
overallTeamPerformance.value.activeGroups = response.data
console.log('活跃组数:', response.data)
@@ -240,7 +270,10 @@ async function fetchConversionRate() {
const params = getRequestParams()
const hasParams = params.user_name
try {
const response = await getConversionRate(hasParams ? params : undefined)
const response = await getConversionRate(hasParams ? {
...params,
check_type: CheckType.value
} : {check_type: CheckType.value})
overallTeamPerformance.value.conversionRate = response.data
} catch (error) {
console.error('获取团队转化率失败:', error)
@@ -251,7 +284,10 @@ async function fetchTotalCallCount() {
const params = getRequestParams()
const hasParams = params.user_name
try {
const response = await getTotalCallCount(hasParams ? params : undefined)
const response = await getTotalCallCount(hasParams ? {
...params,
check_type: CheckType.value
} : {check_type: CheckType.value})
overallTeamPerformance.value.totalCalls = response.data
} catch (error) {
console.error('获取通话次数失败:', error)
@@ -262,7 +298,10 @@ async function fetchNewCustomers() {
const params = getRequestParams()
const hasParams = params.user_name
try {
const response = await getNewCustomer(hasParams ? params : undefined)
const response = await getNewCustomer(hasParams ? {
...params,
check_type: CheckType.value
} : {check_type: CheckType.value})
overallTeamPerformance.value.newCustomers = response.data
} catch (error) {
console.error('获取新增客户失败:', error)
@@ -273,7 +312,10 @@ async function fetchDepositConversions() {
const params = getRequestParams()
const hasParams = params.user_name
try {
const response = await getDepositConversionRate(hasParams ? params : undefined)
const response = await getDepositConversionRate(hasParams ? {
...params,
check_type: CheckType.value
} : {check_type: CheckType.value})
overallTeamPerformance.value.depositConversions = response.data
console.log(99888999,response.data)