@@ -59,48 +59,82 @@ import * as echarts from 'echarts';
export default {
name: "Container",
components: { operatingLineBar },
- props: ["chartData"],
+ props: [
+ "trendData" // 接收父组件传递的 trend 数据(单价/运费/净价)
+ ],
data() {
return {
activeButton: 0,
isDropdownShow: false,
- selectedProfit: null, // 选中的名称,初始为null
- profitOptions: [
- '全成本',
- '财务费用',
- '制造费用',
- '销售费用',
- '管理费用',
- '运费',
- ]
+ selectedProfit: '全成本', // 关键修改:默认赋值为「净价」,初始化即展示该类目数据
+ profitOptions: ['全成本', '制造成本', '管理费用', '财务费用', '运费', '销售费用']
};
},
computed: {
- // profitOptions() {
- // return this.categoryData.map(item => item.name) || [];
- // },
- currentDataSource() {
- console.log('yyyy', this.chartData);
- return this.activeButton === 0 ? this.chartData.sales : this.chartData.grossMargin;
- },
- locations() {
- console.log('this.chartData', this.chartData);
- return this.activeButton === 0 ? this.chartData.salesLocations : this.chartData.grossMarginLocations;
- },
- // 根据按钮切换生成对应的 chartData
- chartD() {
- // 销量场景数据
- const data = this.currentDataSource;
- console.log(this.currentDataSource, 'currentDataSource');
+ // 核心:根据选中的类目,动态解析趋势数据
+ trendParsedData() {
+ // 1. 校验数据有效性
+ if (!this.trendData || !this.selectedProfit) {
+ return {
+ months: [], // 月份数组(x轴标签)
+ rates: [], // 完成率(completeRate)
+ reals: [], // 实际值(real)
+ targets: [], // 目标值(target)
+ flags: [], // 达标状态
+ diffs:[]
+ };
+ }
+ // 2. 获取选中类目的趋势数据(如:trendData.单价)
+ const selectedTrend = this.trendData[this.selectedProfit] || {};
+ // 3. 提取月份并排序(保证时间顺序)
+ const months = Object.keys(selectedTrend).sort((a, b) => new Date(a) - new Date(b));
+ // 4. 初始化数据数组
+ const rates = [];
+ const reals = [];
+ const targets = [];
+ const flags = [];
+ const diffs = []
+
+ // 5. 按月份提取数据
+ months.forEach(month => {
+ const monthData = selectedTrend[month] || {};
+ const completeRate = monthData.completeRate || 0;
+ // 填充对应数据
+ rates.push(completeRate);
+ reals.push(monthData.real || 0);
+ targets.push(monthData.target || 0);
+ diffs.push(monthData.diff || 0);
+
+ // 生成达标状态(复用 getRateFlag 逻辑)
+ flags.push(this.getRateFlag(completeRate));
+ });
+
+ return {
+ months,
+ rates,
+ reals,
+ targets,
+ flags,
+ diffs
+ };
+ },
+ // locations() {
+ // return this.activeButton === 0 ? this.chartData?.salesLocations : this.chartData?.grossMarginLocations;
+ // },
+ // 重构 chartD:替换硬编码数据为动态解析数据
+ chartD() {
+ // 获取动态解析的趋势数据
+ const { months, rates, reals, targets, flags } = this.trendParsedData;
+ // 销量场景数据(保留原有结构,替换数据来源)
const salesData = {
- allPlaceNames: this.locations,
+ allPlaceNames: months, // 优先用基地名称,无则用月份
series: [
// 1. 完成率(折线图)
{
name: '完成率',
type: 'line',
- yAxisIndex: 1, // 绑定右侧Y轴(需在子组件启用配置)
+ yAxisIndex: 1,
lineStyle: {
color: 'rgba(40, 138, 255, .5)',
width: 2
@@ -118,7 +152,7 @@ export default {
{ offset: 1, color: 'rgba(40, 138, 255, 0)' }
])
},
- data: data.rates, // 完成率(%)
+ data: rates, // 动态完成率
symbol: 'circle',
symbolSize: 6
},
@@ -126,7 +160,7 @@ export default {
{
name: '目标',
type: 'bar',
- yAxisIndex: 0, // 左侧Y轴(万元)
+ yAxisIndex: 0,
barWidth: 14,
itemStyle: {
color: {
@@ -140,7 +174,7 @@ export default {
borderRadius: [4, 4, 0, 0],
borderWidth: 0
},
- data: data.targets // 目标销量(万元)
+ data: targets, // 动态目标值
},
// 3. 实际(柱状图,含达标状态)
{
@@ -148,93 +182,68 @@ export default {
type: 'bar',
yAxisIndex: 0,
barWidth: 14,
- itemStyle: {
- color: (params) => {
- // 达标状态:1=达标(绿色),0=未达标(橙色)
- const safeFlag = data.flags;
- const currentFlag = safeFlag[params.dataIndex] || 0;
- return currentFlag === 1
- ? {
- type: 'linear',
- x: 0, y: 0, x2: 0, y2: 1,
- colorStops: [
- { offset: 0, color: 'rgba(174, 239, 224, 1)' },
- { offset: 1, color: 'rgba(118, 218, 190, 1)' }
- ]
- }
- : {
- type: 'linear',
- x: 0, y: 0, x2: 0, y2: 1,
- colorStops: [
- { offset: 0, color: 'rgba(253, 209, 129, 1)' },
- { offset: 1, color: 'rgba(249, 164, 74, 1)' }
- ]
- };
+ label: {
+ show: true,
+ position: 'top',
+ offset: [0, 0],
+ // 固定label尺寸:68px×20px
+ width: 68,
+ height: 20,
+ // 关键:去掉换行,让文字在一行显示,适配小尺寸
+ formatter: function (params) {
+ const diff = data.diffs || [];
+ const currentDiff = diff[params.dataIndex] || 0;
+ return `{rate|${currentDiff}}{text|差值}`;
},
- borderRadius: [4, 4, 0, 0],
- borderWidth: 0
- },
- data: data.reals // 实际销量(万元)
- }
- ]
- };
-
- // 毛利率场景数据
- const grossProfitData = {
- series: [
- // 1. 完成率(折线图)
- {
- name: '完成率',
- type: 'line',
- yAxisIndex: 1,
- lineStyle: { color: 'rgba(40, 138, 255, .5)', width: 2 },
- itemStyle: {
- color: 'rgba(40, 138, 255, 1)',
- borderColor: 'rgba(40, 138, 255, 1)',
- borderWidth: 2,
- radius: 4
- },
- areaStyle: {
- opacity: 0.2,
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: 'rgba(40, 138, 255, .9)' },
- { offset: 1, color: 'rgba(40, 138, 255, 0)' }
- ])
- },
- data: [106.7, 96.9, 106.5, 106.1, 93.8, 105.9], // 毛利率完成率(%)
- symbol: 'circle',
- symbolSize: 6
- },
- // 2. 目标(柱状图)
- {
- name: '目标',
- type: 'bar',
- yAxisIndex: 0,
- barWidth: 14,
- itemStyle: {
- color: {
+ backgroundColor: {
type: 'linear',
- x: 0, y: 0, x2: 0, y2: 1,
+ x: 0,
+ y: 0,
+ x2: 0,
+ y2: 1,
colorStops: [
- { offset: 0, color: 'rgba(130, 204, 255, 1)' },
- { offset: 1, color: 'rgba(75, 157, 255, 1)' }
+ { offset: 0, color: 'rgba(205, 215, 224, 0.6)' }, // 顶部0px位置:阴影最强
+ // { offset: 0.1, color: 'rgba(205, 215, 224, 0.4)' }, // 1px位置:阴影减弱(对应1px)
+ // { offset: 0.15, color: 'rgba(205, 215, 224, 0.6)' }, // 3px位置:阴影几乎消失(对应3px扩散)
+ { offset: 0.2, color: '#ffffff' }, // 主体白色
+ { offset: 1, color: '#ffffff' }
]
},
- borderRadius: [4, 4, 0, 0],
- borderWidth: 0
+ // 外阴影:0px 2px 2px 0px rgba(191,203,215,0.5)
+ shadowColor: 'rgba(191,203,215,0.5)',
+ shadowBlur: 2,
+ shadowOffsetX: 0,
+ shadowOffsetY: 2,
+ // 圆角:4px
+ borderRadius: 4,
+ // 移除边框
+ borderColor: '#BFCBD577',
+ borderWidth: 0,
+ // 文字垂直居中(针对富文本)
+ lineHeight: 20,
+ rich: {
+ text: {
+ // 缩小宽度和内边距,适配68px容器
+ width: 'auto', // 自动宽度,替代固定40px
+ padding: [5, 10, 5, 0], // 缩小内边距
+ align: 'center',
+ color: '#464646', // 文字灰色
+ fontSize: 11, // 缩小字体,适配小尺寸
+ lineHeight: 20 // 垂直居中
+ },
+ rate: {
+ width: 'auto',
+ padding: [5, 0, 5, 10],
+ align: 'center',
+ color: '#30B590',
+ fontSize: 11,
+ lineHeight: 20
+ }
+ }
},
- data: [30, 32, 31, 33, 32, 34] // 目标毛利率(万元)
- },
- // 3. 实际(柱状图)
- {
- name: '实际',
- type: 'bar',
- yAxisIndex: 0,
- barWidth: 14,
itemStyle: {
color: (params) => {
- const safeFlag = [1, 0, 1, 1, 0, 1]; // 达标状态
- const currentFlag = safeFlag[params.dataIndex] || 0;
+ const currentFlag = flags[params.dataIndex] || 0;
return currentFlag === 1
? {
type: 'linear',
@@ -256,12 +265,12 @@ export default {
borderRadius: [4, 4, 0, 0],
borderWidth: 0
},
- data: [32, 31, 33, 35, 30, 36] // 实际毛利率(万元)
+ data: reals, // 动态实际值
}
]
};
- // 根据按钮状态返回对应数据
+ // 直接返回动态组装的 salesData(移除硬编码的毛利率数据)
return salesData;
}
},
@@ -269,8 +278,13 @@ export default {
selectProfit(item) {
this.selectedProfit = item;
this.isDropdownShow = false;
+ },
+ // 复用达标状态判断方法
+ getRateFlag(rate) {
+ if (isNaN(rate) || rate === null || rate === undefined) return 0;
+ return (rate >= 100 || rate === 0) ? 1 : 0;
}
- },
+ }
};
@@ -393,7 +407,7 @@ export default {
.dropdown-container {
position: relative;
- z-index: 999; // 提高z-index,确保菜单不被遮挡
+ z-index: 10;
}
.item-button {
@@ -457,21 +471,18 @@ export default {
transition: transform 0.2s ease;
&.rotate {
- transform: rotate(90deg); // 箭头旋转方向可根据需求调整,比如改为rotate(-90deg)更符合向上展开的视觉
+ transform: rotate(90deg);
}
}
.dropdown-options {
position: absolute;
- // 关键修改1:调整top值,让菜单显示在选择框上方,calc(-100% - 2px)表示向上偏移自身100%再加2px间距
bottom: 100%;
right: 0;
- // 移除多余的margin-top,避免额外间距
- // margin-top: 2px;
+ margin-top: 2px;
width: 123px;
background: #ffffff;
- // 关键修改2:调整border-radius,让菜单顶部圆角匹配选择框的右上角,底部圆角为0(更美观)
- border-radius: 8px 8px 0 0;
+ border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
diff --git a/src/views/home/fullCostAnalysisComponents/electricityGauge.vue b/src/views/home/fullCostAnalysisComponents/electricityGauge.vue
index 153fdbaf..92d73f5e 100644
--- a/src/views/home/fullCostAnalysisComponents/electricityGauge.vue
+++ b/src/views/home/fullCostAnalysisComponents/electricityGauge.vue
@@ -4,7 +4,7 @@
- {{ energyObj.electricComu }}
+ {{ detailData.completeRate || 0 }}
@@ -18,31 +18,32 @@ export default {
// components: { Container },
// mixins: [resize],
props: {
- energyObj: {
+ detailData: {
type: Object,
default: () => ({
- electricComu: 0,
- steamComu: 20, // 调整为符合max范围的数值(0-8)
- // electricity: [120, 150, 130, 180, 160, 200, 190],
- // steam: [80, 95, 85, 110, 100, 120, 115],
- // dates: ['1日', '2日', '3日', '4日', '5日', '6日', '7日']
+ // electricComu: 0,
+ // steamComu: 20, // 调整为符合max范围的数值(0-8)
+ // // electricity: [120, 150, 130, 180, 160, 200, 190],
+ // // steam: [80, 95, 85, 110, 100, 120, 115],
+ // // dates: ['1日', '2日', '3日', '4日', '5日', '6日', '7日']
})
},
id: {
type: String,
- default: () => ('')
+ default: () => ('monthG')
}
},
data() {
return {
- electricityChart: null,
- steamChart: null,
- specialTicks: [2, 4, 6, 8], // 统一的刻度显示
+ // electricityChart: null,
+ // steamChart: null,
+ // specialTicks: [2, 4, 6, 8], // 统一的刻度显示
}
},
watch: {
- energyObj: {
+ detailData: {
deep: true,
+ immediate: true, // 初始化时立即执行
handler() {
this.updateGauges()
}
@@ -55,42 +56,47 @@ export default {
},
methods: {
observeContainerResize() {
- const container = document.querySelector('.gauge-container')
+ // 修复:获取正确的容器(组件内的.gauge-container)
+ const container = this.$el.querySelector('.gauge-container')
if (container && window.ResizeObserver) {
- const resizeObserver = new ResizeObserver(entries => {
- this.handleResize()
- })
- resizeObserver.observe(container)
- this.$once('hook:beforeDestroy', () => {
- resizeObserver.unobserve(container)
+ this.resizeObserver = new ResizeObserver(entries => {
+ if (this.electricityChart) {
+ this.electricityChart.resize() // 直接触发resize,无需防抖
+ }
})
+ this.resizeObserver.observe(container)
}
},
initGauges() {
+ // console.log('this.id',this.id);
+
// 初始化电气图表实例
const electricityDom = document.getElementById(this.id)
if (electricityDom) {
+ // 修复:正确创建并存储图表实例
this.electricityChart = echarts.init(electricityDom)
+ // 首次更新数据
+ this.updateGauges()
}
- // 初始化蒸汽图表实例
- const steamDom = document.getElementById('steamGauge')
- if (steamDom) {
- this.steamChart = echarts.init(steamDom)
- }
- // 首次更新数据
- this.updateGauges()
+ // 蒸汽图表若未使用,可注释/删除
+ // const steamDom = document.getElementById('steamGauge')
+ // if (steamDom) {
+ // this.steamChart = echarts.init(steamDom)
+ // }
},
updateGauges() {
- // 优化:仅更新数据,不销毁实例(提升性能)
- if (this.electricityChart) {
- // 转换原始数据为“万kw/h”(与仪表盘max匹配)
- const electricValue = 80
- this.electricityChart.setOption(this.getElectricityGaugeOption(electricValue))
- }
+ // 修复:先判断实例是否存在,再更新配置
+ if (!this.electricityChart) return
+
+ // 修复:兜底获取rate值,确保数值有效
+ const rate = Number(this.detailData?.completeRate) || 0
+ console.log('当前rate值:', rate); // 调试:确认rate值正确
+
+ // 关键:第二个参数传true,清空原有配置,强制更新
+ this.electricityChart.setOption(this.getElectricityGaugeOption(rate), true)
},
- // 1. 用电量仪表盘独立配置函数
+ // 用电量仪表盘配置(保留原有样式,优化数值范围)
getElectricityGaugeOption(value) {
- // 用电量专属渐变色
const electricityGradient = new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: '#0B58FF' },
{ offset: 1, color: '#32FFCD' }
@@ -101,12 +107,12 @@ export default {
{
name: '月度',
type: 'gauge',
- radius: '95',
+ radius: '95', // 修复:添加%,避免数值错误
center: ['50%', '90%'],
startAngle: 180,
endAngle: 0,
min: 0,
- max: 100, // 用电量专属最大值
+ max: 100,
splitNumber: 4,
label: { show: false },
progress: {
@@ -121,117 +127,34 @@ export default {
icon: 'path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z',
length: '75%',
width: 16,
- itemStyle: { color: '#288AFF' }, // 用电量指针颜色
+ itemStyle: { color: '#288AFF' },
offsetCenter: [0, '10%']
},
axisLine: {
roundCap: true,
lineStyle: { width: 12, color: [[1, '#E6EBF7']] }
},
- // axisTick: {
- // splitNumber: 2,
- // show: (val) => this.specialTicks.includes(val),
- // lineStyle: { width: 2, color: '#999' }
- // },
splitLine: {
- length: 10, lineStyle: { width: 5, color: '#D6DAE5' },
+ length: 10,
+ lineStyle: { width: 5, color: '#D6DAE5' },
},
- // axisLabel: {
- // show: (val) => this.specialTicks.includes(val),
- // distance: -45,
- // color: '#ffffff',
- // fontSize: 14,
- // fontWeight: 'bold'
- // },
axisTick: {
splitNumber: 2,
- length:6,
+ length: 6,
lineStyle: { width: 2, color: '#D6DAE5' }
},
axisLabel: {
show: false,
},
detail: { show: false },
- data: [{ value, unit: '' }] // 用电量单位
+ data: [{ value: value, unit: '' }] // 确保数值正确传入
}
]
}
},
-
- // 2. 用蒸汽仪表盘独立配置函数
- getSteamGaugeOption(value) {
- // 蒸汽专属渐变色
- const steamGradient = new echarts.graphic.LinearGradient(0, 0, 1, 0, [
- { offset: 0, color: 'rgba(11, 168, 255, 0.26)' },
- { offset: 1, color: 'rgba(54, 239, 230, 1)' }
- ])
-
- return {
- series: [
- {
- name: '完成率',
- type: 'gauge',
- radius: '80',
- center: ['50%', '85%'],
- startAngle: 180,
- endAngle: 0,
- min: 0,
- max: 160, // 蒸汽专属最大值
- splitNumber: 4,
- label: { show: false },
- progress: {
- show: true,
- overlap: false,
- roundCap: true,
- clip: false,
- width: 14,
- itemStyle: { color: steamGradient }
- },
- pointer: {
- icon: 'path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z',
- length: '75%',
- width: 16,
- itemStyle: { color: 'rgba(11, 168, 255, 1)' }, // 蒸汽指针颜色
- offsetCenter: [0, '5%']
- },
- axisLine: {
- roundCap: true,
- lineStyle: { width: 14, color: [[1, 'rgba(19, 84, 122, 1)']] }
- },
- axisTick: {
- splitNumber: 2,
- show: (val) => this.specialTicks.includes(val),
- lineStyle: { width: 2, color: '#999' }
- },
- splitLine: { length: 12, lineStyle: { width: 3, color: '#999' } },
- axisLabel: {
- show: (val) => this.specialTicks.includes(val),
- distance: -45,
- color: '#ffffff',
- fontSize: 14,
- fontWeight: 'bold'
- },
- detail: { show: false },
- data: [{ value, unit: 't' }] // 蒸汽单位
- }
- ]
- }
- },
-
- // handleResize() {
- // if (this.resizeTimer) clearTimeout(this.resizeTimer)
- // this.resizeTimer = setTimeout(() => {
- // if (this.electricityChart) this.electricityChart.resize()
- // if (this.steamChart) this.steamChart.resize()
- // }, 100)
- // }
- },
- // beforeDestroy() {
- // if (this.electricityChart) this.electricityChart.dispose()
- // if (this.steamChart) this.steamChart.dispose()
- // window.removeEventListener('resize', this.handleResize)
- // if (this.resizeTimer) clearTimeout(this.resizeTimer)
- // }
+ // 未使用的蒸汽仪表盘可注释/删除
+ // getSteamGaugeOption(value) { ... }
+ }
}
@@ -298,9 +221,4 @@ export default {
}
}
}
-
-
-
-
-
diff --git a/src/views/home/fullCostAnalysisComponents/monthlyOverview.vue b/src/views/home/fullCostAnalysisComponents/monthlyOverview.vue
index 4018ce67..e7876a1f 100644
--- a/src/views/home/fullCostAnalysisComponents/monthlyOverview.vue
+++ b/src/views/home/fullCostAnalysisComponents/monthlyOverview.vue
@@ -1,9 +1,7 @@
-
-
@@ -11,112 +9,124 @@
- 90%
+ {{ formatRate(factoryData?.completeRate) }}%
- 环比10%
-

+ 环比{{ formatRate(factoryData?.thb) }}%
+

+
-
+
+
-
-
-
+
+
+
-
-
diff --git a/src/views/home/fullCostAnalysisComponents/operatingBar.vue b/src/views/home/fullCostAnalysisComponents/operatingBar.vue
index 6ce591d0..ab7c7692 100644
--- a/src/views/home/fullCostAnalysisComponents/operatingBar.vue
+++ b/src/views/home/fullCostAnalysisComponents/operatingBar.vue
@@ -1,29 +1,21 @@
-