| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container indicator-stats"> |
| | | <el-card class="box-card"> |
| | | <!-- KPI æ±æ» --> |
| | | <el-row :gutter="20" class="stats-row"> |
| | | <el-col :span="8"> |
| | | <div class="stat-card"> |
| | | <div class="stat-icon" style="background: #ecf5ff;"> |
| | | <el-icon :size="30" color="#409eff"><Document /></el-icon> |
| | | </div> |
| | | <div class="stat-content"> |
| | | <div class="stat-value">{{ indicatorKpis.orderCount.toLocaleString() }}</div> |
| | | <div class="stat-label">è®¢åæ°é</div> |
| | | </div> |
| | | </div> |
| | | </el-col> |
| | | <el-col :span="8"> |
| | | <div class="stat-card"> |
| | | <div class="stat-icon" style="background: #f0f9ff;"> |
| | | <el-icon :size="30" color="#67c23a"><Tickets /></el-icon> |
| | | </div> |
| | | <div class="stat-content"> |
| | | <div class="stat-value">Â¥{{ indicatorKpis.salesAmount.toLocaleString() }}</div> |
| | | <div class="stat-label">éå®é¢</div> |
| | | </div> |
| | | </div> |
| | | </el-col> |
| | | <el-col :span="8"> |
| | | <div class="stat-card"> |
| | | <div class="stat-icon" style="background: #fef0f0;"> |
| | | <el-icon :size="30" color="#e6a23c"><Van /></el-icon> |
| | | </div> |
| | | <div class="stat-content"> |
| | | <div class="stat-value">{{ indicatorKpis.shipRate }}%</div> |
| | | <div class="stat-label">åè´§ç</div> |
| | | </div> |
| | | </div> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 维度çé --> |
| | | <el-row :gutter="20" class="search-row"> |
| | | <el-col :span="6"> |
| | | <el-tree-select v-model="indicatorFilter.productCategory" placeholder="产åç±»å«" clearable check-strictly |
| | | :data="productOptions" :render-after-expand="false" style="width: 100%" /> |
| | | </el-col> |
| | | <el-col :span="6"> |
| | | <el-select v-model="indicatorFilter.customerName" placeholder="客æ·" clearable filterable> |
| | | <el-option v-for="item in customerOption" :key="item.id" :label="item.customerName" :value="item.customerName" /> |
| | | </el-select> |
| | | </el-col> |
| | | <el-col :span="6"> |
| | | <el-date-picker v-model="indicatorFilter.dateRange" type="daterange" range-separator="è³" |
| | | start-placeholder="å¼å§æ¥æ" end-placeholder="ç»ææ¥æ" value-format="YYYY-MM-DD" style="width: 100%" /> |
| | | </el-col> |
| | | <el-col :span="6" style="text-align: right;"> |
| | | <el-button type="primary" @click="applyIndicatorFilter">æ¥è¯¢</el-button> |
| | | <el-button @click="resetIndicatorFilter">éç½®</el-button> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- å¾è¡¨åº --> |
| | | <div class="chart-container"> |
| | | <div ref="indicatorChartRef" class="chart-wrapper"></div> |
| | | </div> |
| | | |
| | | <!-- ä¸ç»©ç»è®¡ï¼å¢éç»´åº¦ï¼æ 个人å§åï¼ --> |
| | | <el-table v-if="showTeamPerformance" :data="teamPerformanceList" border stripe style="margin-top: 20px;"> |
| | | <el-table-column prop="team" label="éå®å¢é"/> |
| | | <el-table-column prop="orderCount" label="è®¢åæ°"/> |
| | | <el-table-column prop="salesAmount" label="éå®é¢"> |
| | | <template #default="scope">Â¥{{ scope.row.salesAmount.toLocaleString() }}</template> |
| | | </el-table-column> |
| | | <el-table-column prop="shipRate" label="åè´§ç"> |
| | | <template #default="scope">{{ scope.row.shipRate }}</template> |
| | | </el-table-column> |
| | | <el-table-column prop="attainment" label="ç®æ è¾¾æç"> |
| | | <template #default="scope"> |
| | | <el-tag :type="scope.row.attainment >= 100 ? 'success' : scope.row.attainment >= 80 ? 'warning' : 'danger'"> |
| | | {{ scope.row.attainment }}% |
| | | </el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </el-card> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, onMounted, onUnmounted, nextTick } from 'vue' |
| | | import { Document, Van, Tickets } from '@element-plus/icons-vue' |
| | | import * as echarts from 'echarts' |
| | | import { getTotalStatistics, getStatisticsTable } from '@/api/salesManagement/indicatorStats' |
| | | import { productTreeList } from '@/api/basicData/product.js' |
| | | import { customerList } from '@/api/salesManagement/salesLedger.js' |
| | | import { ElMessage } from 'element-plus' |
| | | |
| | | const indicatorKpis = reactive({ |
| | | orderCount: 0, |
| | | salesAmount: 0, |
| | | shipRate: 0 |
| | | }) |
| | | |
| | | // æ¯å¦å±ç¤ºéå®å¢éæç»è¡¨ï¼æéå¼å¯ |
| | | const showTeamPerformance = ref(false) |
| | | const loading = ref(false) |
| | | |
| | | const indicatorFilter = reactive({ |
| | | productCategory: '', |
| | | customerName: '', |
| | | dateRange: [] |
| | | }) |
| | | |
| | | const indicatorChartRef = ref(null) |
| | | let indicatorChart = null |
| | | |
| | | const productOptions = ref([]) |
| | | const customerOption = ref([]) |
| | | |
| | | const teamPerformanceList = ref([ |
| | | { team: 'åä¸å¤§åº', orderCount: 320, salesAmount: 2850000, shipRate: 90, attainment: 105 }, |
| | | { team: 'åå大åº', orderCount: 280, salesAmount: 2150000, shipRate: 86, attainment: 92 }, |
| | | { team: 'åå大åº', orderCount: 210, salesAmount: 1850000, shipRate: 88, attainment: 78 }, |
| | | { team: '西å大åº', orderCount: 180, salesAmount: 1500000, shipRate: 83, attainment: 74 } |
| | | ]) |
| | | |
| | | // 转æ¢äº§åæ æ°æ®ï¼å° id æ¹ä¸º value |
| | | function convertIdToValue(data) { |
| | | return data.map((item) => { |
| | | const { id, children, ...rest } = item |
| | | const newItem = { |
| | | ...rest, |
| | | value: id, // å° id æ¹ä¸º value |
| | | } |
| | | if (children && children.length > 0) { |
| | | newItem.children = convertIdToValue(children) |
| | | } |
| | | return newItem |
| | | }) |
| | | } |
| | | |
| | | // è·åäº§åæ æ°æ® |
| | | const getProductOptions = () => { |
| | | return productTreeList().then((res) => { |
| | | productOptions.value = convertIdToValue(res) |
| | | }).catch((error) => { |
| | | console.error('è·åäº§åæ å¤±è´¥:', error) |
| | | ElMessage.error('è·å产åç±»å«å¤±è´¥') |
| | | }) |
| | | } |
| | | |
| | | // è·å客æ·å表 |
| | | const getCustomerList = () => { |
| | | return customerList().then((res) => { |
| | | customerOption.value = res || [] |
| | | }).catch((error) => { |
| | | console.error('è·å客æ·å表失败:', error) |
| | | ElMessage.error('è·å客æ·å表失败') |
| | | }) |
| | | } |
| | | |
| | | // æ ¹æ® id æ¥æ¾äº§åç±»å«åç§° |
| | | const findNodeLabelById = (nodes, id) => { |
| | | if (!id) return null |
| | | for (let i = 0; i < nodes.length; i++) { |
| | | if (nodes[i].value === id) { |
| | | return nodes[i].label |
| | | } |
| | | if (nodes[i].children && nodes[i].children.length > 0) { |
| | | const found = findNodeLabelById(nodes[i].children, id) |
| | | if (found) return found |
| | | } |
| | | } |
| | | return null |
| | | } |
| | | |
| | | // è·å头é¨ç»è®¡æ°æ® |
| | | const fetchTotalStatistics = async () => { |
| | | try { |
| | | loading.value = true |
| | | const params = {} |
| | | if (indicatorFilter.customerName) { |
| | | params.customerName = indicatorFilter.customerName |
| | | } |
| | | if (indicatorFilter.productCategory) { |
| | | // æ ¹æ® id æ¥æ¾äº§åç±»å«åç§° |
| | | const categoryName = findNodeLabelById(productOptions.value, indicatorFilter.productCategory) |
| | | if (categoryName) { |
| | | params.productCategory = categoryName |
| | | } |
| | | } |
| | | if (indicatorFilter.dateRange && indicatorFilter.dateRange.length === 2) { |
| | | params.entryDateStart = indicatorFilter.dateRange[0] |
| | | params.entryDateEnd = indicatorFilter.dateRange[1] |
| | | } |
| | | const res = await getTotalStatistics(params) |
| | | if (res && res.data) { |
| | | indicatorKpis.orderCount = res.data.total || 0 |
| | | indicatorKpis.salesAmount = res.data.contractAmountTotal || 0 |
| | | // åè´§ç妿æ¥å£æ²¡æè¿åï¼ä¿æåå¼æè®¾ä¸º0 |
| | | // indicatorKpis.shipRate = res.data.shipRate || 0 |
| | | } |
| | | } catch (error) { |
| | | console.error('è·å头é¨ç»è®¡å¤±è´¥:', error) |
| | | ElMessage.error('è·åç»è®¡æ°æ®å¤±è´¥') |
| | | } finally { |
| | | loading.value = false |
| | | } |
| | | } |
| | | |
| | | // è·åæ±ç¶å¾æ°æ® |
| | | const fetchStatisticsTable = async () => { |
| | | try { |
| | | loading.value = true |
| | | const params = {} |
| | | if (indicatorFilter.customerName) { |
| | | params.customerName = indicatorFilter.customerName |
| | | } |
| | | if (indicatorFilter.productCategory) { |
| | | // æ ¹æ® id æ¥æ¾äº§åç±»å«åç§° |
| | | const categoryName = findNodeLabelById(productOptions.value, indicatorFilter.productCategory) |
| | | if (categoryName) { |
| | | params.productCategory = categoryName |
| | | } |
| | | } |
| | | if (indicatorFilter.dateRange && indicatorFilter.dateRange.length === 2) { |
| | | params.entryDateStart = indicatorFilter.dateRange[0] |
| | | params.entryDateEnd = indicatorFilter.dateRange[1] |
| | | } |
| | | const res = await getStatisticsTable(params) |
| | | if (res && res.data) { |
| | | updateChart(res.data) |
| | | } |
| | | } catch (error) { |
| | | console.error('è·åå¾è¡¨æ°æ®å¤±è´¥:', error) |
| | | ElMessage.error('è·åå¾è¡¨æ°æ®å¤±è´¥') |
| | | } finally { |
| | | loading.value = false |
| | | } |
| | | } |
| | | |
| | | // æ´æ°å¾è¡¨ |
| | | const updateChart = (chartData) => { |
| | | if (!indicatorChartRef.value) return |
| | | if (indicatorChart) indicatorChart.dispose() |
| | | indicatorChart = echarts.init(indicatorChartRef.value) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åçæ°æ®ç»ææ´æ°å¾è¡¨ |
| | | // æ¥å£è¿å: dateList, orderCountList, salesAmountList |
| | | const option = { |
| | | title: { text: 'å¤ç»´åº¦é宿æ è¶å¿', left: 'center' }, |
| | | tooltip: { trigger: 'axis' }, |
| | | legend: { data: ['è®¢åæ°', 'éå®é¢'], top: 30 }, |
| | | grid: { left: '3%', right: '8%', bottom: '3%', containLabel: true }, |
| | | xAxis: { |
| | | type: 'category', |
| | | data: chartData.dateList || [] |
| | | }, |
| | | yAxis: [ |
| | | { type: 'value', name: 'éé¢', position: 'left', axisLabel: { formatter: '{value}' } }, |
| | | { |
| | | type: 'value', |
| | | name: 'æ°é', |
| | | position: 'right', |
| | | minInterval: 1, |
| | | axisLabel: { |
| | | formatter: (value) => { |
| | | const intValue = Math.round(value) |
| | | return intValue.toString() |
| | | } |
| | | } |
| | | } |
| | | ], |
| | | series: [ |
| | | { |
| | | name: 'è®¢åæ°', |
| | | type: 'line', |
| | | yAxisIndex: 1, |
| | | data: chartData.orderCountList || [], |
| | | itemStyle: { color: '#409eff' } |
| | | }, |
| | | { |
| | | name: 'éå®é¢', |
| | | type: 'bar', |
| | | yAxisIndex: 0, |
| | | data: chartData.salesAmountList || [], |
| | | itemStyle: { color: '#67c23a' } |
| | | } |
| | | ] |
| | | } |
| | | indicatorChart.setOption(option) |
| | | } |
| | | |
| | | const initIndicatorChart = () => { |
| | | if (!indicatorChartRef.value) return |
| | | if (indicatorChart) indicatorChart.dispose() |
| | | indicatorChart = echarts.init(indicatorChartRef.value) |
| | | const option = { |
| | | title: { text: 'å¤ç»´åº¦é宿æ è¶å¿', left: 'center' }, |
| | | tooltip: { trigger: 'axis' }, |
| | | legend: { data: ['è®¢åæ°', 'éå®é¢'], top: 30 }, |
| | | grid: { left: '3%', right: '8%', bottom: '3%', containLabel: true }, |
| | | xAxis: { type: 'category', data: [] }, |
| | | yAxis: [ |
| | | { type: 'value', name: 'éé¢', position: 'left', axisLabel: { formatter: '{value}' } }, |
| | | { |
| | | type: 'value', |
| | | name: 'æ°é', |
| | | position: 'right', |
| | | minInterval: 1, |
| | | axisLabel: { |
| | | formatter: (value) => { |
| | | const intValue = Math.round(value) |
| | | return intValue.toString() |
| | | } |
| | | } |
| | | } |
| | | ], |
| | | series: [ |
| | | { name: 'è®¢åæ°', type: 'line', yAxisIndex: 1, data: [], itemStyle: { color: '#409eff' } }, |
| | | { name: 'éå®é¢', type: 'bar', yAxisIndex: 0, data: [], itemStyle: { color: '#67c23a' } } |
| | | ] |
| | | } |
| | | indicatorChart.setOption(option) |
| | | } |
| | | |
| | | const applyIndicatorFilter = async () => { |
| | | await Promise.all([ |
| | | fetchTotalStatistics(), |
| | | fetchStatisticsTable() |
| | | ]) |
| | | } |
| | | |
| | | const resetIndicatorFilter = () => { |
| | | indicatorFilter.productCategory = '' |
| | | indicatorFilter.customerName = '' |
| | | indicatorFilter.dateRange = [] |
| | | applyIndicatorFilter() |
| | | } |
| | | |
| | | // çªå£å¤§å°ååæ¶è°æ´å¾è¡¨å¤§å° |
| | | const handleResize = () => { |
| | | if (indicatorChart) { |
| | | indicatorChart.resize() |
| | | } |
| | | } |
| | | |
| | | onMounted(() => { |
| | | nextTick(() => { |
| | | initIndicatorChart() |
| | | getProductOptions() |
| | | getCustomerList() |
| | | fetchTotalStatistics() |
| | | fetchStatisticsTable() |
| | | }) |
| | | // çå¬çªå£å¤§å°åå |
| | | window.addEventListener('resize', handleResize) |
| | | }) |
| | | |
| | | onUnmounted(() => { |
| | | // ç§»é¤çªå£å¤§å°ååçå¬å¨ |
| | | window.removeEventListener('resize', handleResize) |
| | | // 鿝å¾è¡¨å®ä¾ |
| | | if (indicatorChart) { |
| | | indicatorChart.dispose() |
| | | indicatorChart = null |
| | | } |
| | | }) |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .indicator-stats { |
| | | padding: 0; |
| | | } |
| | | .box-card { border: none; box-shadow: none; } |
| | | .search-row { margin-bottom: 20px; } |
| | | .stats-row { margin-bottom: 24px; } |
| | | .stat-card { display: flex; align-items: center; padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } |
| | | .stat-icon { width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 8px; margin-right: 16px; } |
| | | .stat-content { flex: 1; } |
| | | .stat-value { font-size: 28px; font-weight: bold; color: #303133; margin-bottom: 4px; } |
| | | .stat-label { font-size: 14px; color: #909399; } |
| | | .chart-container { |
| | | margin: 20px 0; |
| | | padding: 20px; |
| | | background: #fff; |
| | | border-radius: 8px; |
| | | box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); |
| | | width: 100%; |
| | | overflow: hidden; |
| | | } |
| | | .chart-wrapper { |
| | | width: 100%; |
| | | height: 360px; |
| | | min-width: 0; |
| | | } |
| | | </style> |
| | | |
| | | |