首页费用跳转&页面值绑定问题

This commit is contained in:
2026-09-15 13:33:27 +08:00
parent 8f586cfb23
commit 467eb48cd6
3 changed files with 20 additions and 21 deletions

View File

@@ -100,14 +100,14 @@ export default {
const costMapping = [ const costMapping = [
{ {
key: 'totalCost', name: '总费用·万元', key: 'totalCost', name: '总费用·万元',
path:"/expenseAnalysis/expenseAnalysisBase" path:"/expenseAnalysis/expenseAnalysis"
}, },
{ {
key: 'manageCost', name: '管理费用·万元', key: 'manageCost', name: '管理费用·万元',
path: "/expenseAnalysis/expenseAnalysisBase" path: ""
}, },
{ key: 'saleCost', name: '销售费用·万元', path: "/expenseAnalysis/expenseAnalysisBase" }, { key: 'saleCost', name: '销售费用·万元', path: "" },
{ key: 'financeCost', name: '财务费用·万元', path: "/expenseAnalysis/expenseAnalysisBase" } { key: 'financeCost', name: '财务费用·万元', path: "" }
]; ];
// 遍历映射关系,转换数据 // 遍历映射关系,转换数据

View File

@@ -114,16 +114,18 @@ export default {
}, },
updateChart(data) { updateChart(data) {
// 修复核心:正确获取默认值(调用 factory 函数) // 数据兜底确保是数组且长度≥2否则取 props 默认值
// 错误写法this.$props.ytdAnalysis.default()
// 正确写法this.ytdAnalysis 默认值已通过 factory 函数定义,直接兜底
const validData = Array.isArray(data) && data.length >= 2 const validData = Array.isArray(data) && data.length >= 2
? data ? data
: this.$props.monthAnalysis; // 直接取 props 默认值 : this.$props.monthAnalysis; // 直接取 props 默认值
// 提取累计收入第0项、累计全成本第1项数据 // 按 title 匹配目标项(不依赖数组顺序,兼容后端数据结构顺序变化)
const incomeItem = validData[0] || { title: "营业收入", budget: 0, real: 0, rate: 0, diff: 0 }; const list = Array.isArray(validData) ? validData : []
const costItem = validData[1] || { title: "全成本", budget: 0, real: 0, rate: 0, diff: 0 }; // 营业收入:精确匹配
const incomeItem = list.find(item => item && item.title === '营业收入')
|| { title: "营业收入", budget: 0, real: 0, rate: 0, diff: 0 };
const costItem = list.find(item => item && item.title === '全成本')
|| { title: "全成本", budget: 0, real: 0, rate: 0, diff: 0 };
// 整合flag字段 // 整合flag字段
this.ytdIncomeData = { this.ytdIncomeData = {
@@ -135,9 +137,6 @@ export default {
...costItem, ...costItem,
flag: costItem.rate > 100 ? 1 : 0 flag: costItem.rate > 100 ? 1 : 0
}; };
console.log('累计收入数据:', this.ytdIncomeData);
console.log('累计全成本数据:', this.ytdCostData);
} }
} }
} }

View File

@@ -123,14 +123,18 @@ export default {
}, },
updateChart(data) { updateChart(data) {
// 数据兜底确保是数组且长度≥2 // 数据兜底确保是数组且长度≥2,否则取 props 默认值
const validData = Array.isArray(data) && data.length >= 2 const validData = Array.isArray(data) && data.length >= 2
? data ? data
: this.$props.ytdAnalysis; : this.$props.ytdAnalysis;
// 提取收入第0项、全成本第1项数据 // 按 title 匹配目标项(不依赖数组顺序,兼容后端数据结构顺序变化)
const incomeItem = validData[0] || { title: "营业收入", budget: 0, real: 0, rate: 0, diff: 0 }; const list = Array.isArray(validData) ? validData : []
const totalCostItem = validData[1] || { title: "全成本", budget: 0, real: 0, rate: 0, diff: 0 }; // 营业收入:精确匹配
const incomeItem = list.find(item => item && item.title === '营业收入')
|| { title: "营业收入", budget: 0, real: 0, rate: 0, diff: 0 };
const totalCostItem = list.find(item => item && item.title === '全成本')
|| { title: "全成本", budget: 0, real: 0, rate: 0, diff: 0 };
// 整合flag字段到收入/全成本数据中 // 整合flag字段到收入/全成本数据中
this.incomeData = { this.incomeData = {
@@ -142,10 +146,6 @@ export default {
...totalCostItem, ...totalCostItem,
flag: totalCostItem.rate >= 100 ? 1 : 0 flag: totalCostItem.rate >= 100 ? 1 : 0
}; };
// 调试:确认数据赋值正确
console.log('整合flag后的收入数据', this.incomeData);
console.log('整合flag后的全成本数据', this.totalCostData);
} }
} }
} }