496 lines
14 KiB
Vue
496 lines
14 KiB
Vue
<template>
|
||
<div class="coreBar">
|
||
<!-- 新增行容器:包裹“各基地情况”和barTop -->
|
||
<div class="header-row">
|
||
<div class="base-title">
|
||
各基地情况
|
||
</div>
|
||
<div class="barTop">
|
||
<!-- 关键:新增右侧容器,包裹图例和按钮组,实现整体靠右 -->
|
||
<div class="right-container">
|
||
<div class="legend">
|
||
<span class="legend-item">
|
||
<span class="legend-icon line yield"></span>
|
||
完成率
|
||
</span>
|
||
<span class="legend-item">
|
||
<span class="legend-icon square target"></span>
|
||
目标
|
||
</span>
|
||
<span class="legend-item">
|
||
<span class="legend-icon square achieved"></span>
|
||
实际·达标
|
||
</span>
|
||
<span class="legend-item">
|
||
<span class="legend-icon square unachieved"></span>
|
||
实际·未达标
|
||
</span>
|
||
</div>
|
||
<div class="button-group">
|
||
<div class="item-button category-btn">
|
||
<span class="item-text">展示顺序</span>
|
||
</div>
|
||
<div class="dropdown-container">
|
||
<div class="item-button profit-btn active" @click.stop="isDropdownShow = !isDropdownShow">
|
||
<span class="item-text profit-text">{{ selectedProfit || '请选择' }}</span>
|
||
<span class="dropdown-arrow" :class="{ 'rotate': isDropdownShow }"></span>
|
||
</div>
|
||
<div class="dropdown-options" v-if="isDropdownShow">
|
||
<div class="dropdown-option" v-for="(item, index) in profitOptions" :key="index"
|
||
@click.stop="selectProfit(item)">
|
||
{{ item }}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="lineBottom" style="height: 100%; width: 100%">
|
||
<operatingLineBar :chartData="chartD" style="height: 99%; width: 100%" />
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import operatingLineBar from './operatingLineBarSale.vue';
|
||
import * as echarts from 'echarts';
|
||
|
||
export default {
|
||
name: "Container",
|
||
components: { operatingLineBar },
|
||
props: ["chartData"],
|
||
data() {
|
||
return {
|
||
activeButton: 0,
|
||
isDropdownShow: false,
|
||
selectedProfit: null, // 选中的名称,初始为null
|
||
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');
|
||
|
||
const salesData = {
|
||
allPlaceNames: this.locations,
|
||
series: [
|
||
// 1. 完成率(折线图)
|
||
{
|
||
name: '完成率',
|
||
type: 'line',
|
||
yAxisIndex: 1, // 绑定右侧Y轴(需在子组件启用配置)
|
||
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: data.rates, // 完成率(%)
|
||
symbol: 'circle',
|
||
symbolSize: 6
|
||
},
|
||
// 2. 目标(柱状图)
|
||
{
|
||
name: '目标',
|
||
type: 'bar',
|
||
yAxisIndex: 0, // 左侧Y轴(万元)
|
||
barWidth: 14,
|
||
itemStyle: {
|
||
color: {
|
||
type: 'linear',
|
||
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)' }
|
||
]
|
||
},
|
||
borderRadius: [4, 4, 0, 0],
|
||
borderWidth: 0
|
||
},
|
||
data: data.targets // 目标销量(万元)
|
||
},
|
||
// 3. 实际(柱状图,含达标状态)
|
||
{
|
||
name: '实际',
|
||
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)' }
|
||
]
|
||
};
|
||
},
|
||
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: {
|
||
type: 'linear',
|
||
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)' }
|
||
]
|
||
},
|
||
borderRadius: [4, 4, 0, 0],
|
||
borderWidth: 0
|
||
},
|
||
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;
|
||
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)' }
|
||
]
|
||
};
|
||
},
|
||
borderRadius: [4, 4, 0, 0],
|
||
borderWidth: 0
|
||
},
|
||
data: [32, 31, 33, 35, 30, 36] // 实际毛利率(万元)
|
||
}
|
||
]
|
||
};
|
||
|
||
// 根据按钮状态返回对应数据
|
||
return salesData;
|
||
}
|
||
},
|
||
methods: {
|
||
selectProfit(item) {
|
||
this.selectedProfit = item;
|
||
this.isDropdownShow = false;
|
||
}
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.coreBar {
|
||
display: flex;
|
||
flex-direction: column;
|
||
width: 100%;
|
||
padding: 12px;
|
||
|
||
// 新增:头部行容器,实现一行排列
|
||
.header-row {
|
||
display: flex;
|
||
justify-content: space-between; // 左右两端对齐
|
||
align-items: center; // 垂直居中
|
||
width: 100%;
|
||
margin-bottom: 8px; // 与下方图表区保留间距(可根据需求调整)
|
||
}
|
||
|
||
// 各基地情况标题样式
|
||
.base-title {
|
||
font-weight: 400;
|
||
font-size: 18px;
|
||
color: #000000;
|
||
line-height: 18px;
|
||
letter-spacing: 1px;
|
||
font-style: normal;
|
||
padding: 0 0 0 16px; // 保留原有内边距
|
||
white-space: nowrap; // 防止文字换行
|
||
}
|
||
|
||
.barTop {
|
||
// 移除原有flex和justify-content,由header-row控制
|
||
width: auto; // 自适应宽度
|
||
// 保留原有align-items,确保内部元素垂直居中
|
||
align-items: center;
|
||
gap: 16px;
|
||
|
||
// 1. 右侧容器:包裹图例和按钮组,整体靠右
|
||
.right-container {
|
||
display: flex;
|
||
align-items: center; // 图例和按钮组垂直居中
|
||
gap: 24px; // 图例与按钮组的间距,避免贴紧
|
||
margin-right: 46px; // 右侧整体留边,与原按钮组边距一致
|
||
}
|
||
|
||
// 2. 图例:在右侧容器内横向排列
|
||
.legend {
|
||
display: flex;
|
||
gap: 16px; // 图例项之间间距,避免重叠
|
||
align-items: center;
|
||
margin: 0;
|
||
}
|
||
|
||
.legend-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-family: PingFangSC, PingFang SC;
|
||
font-weight: 400;
|
||
font-size: 14px;
|
||
color: rgba(0, 0, 0, 0.8);
|
||
text-align: left;
|
||
font-style: normal;
|
||
white-space: nowrap; // 防止图例文字换行
|
||
}
|
||
|
||
.legend-icon {
|
||
display: inline-block;
|
||
}
|
||
|
||
.legend-icon.line {
|
||
width: 12px;
|
||
height: 2px;
|
||
position: relative;
|
||
|
||
&::before {
|
||
position: absolute;
|
||
content: "";
|
||
top: -2px;
|
||
left: 3px;
|
||
width: 6px;
|
||
border-radius: 50%;
|
||
height: 6px;
|
||
background-color: rgba(40, 138, 255, 1);
|
||
}
|
||
}
|
||
|
||
.legend-icon.square {
|
||
width: 8px;
|
||
height: 8px;
|
||
}
|
||
|
||
// 图例颜色
|
||
.yield {
|
||
background: rgba(40, 138, 255, 1);
|
||
}
|
||
|
||
.target {
|
||
background: #2889FF;
|
||
}
|
||
|
||
.achieved {
|
||
background: rgba(40, 203, 151, 1);
|
||
}
|
||
|
||
.unachieved {
|
||
background: rgba(255, 132, 0, 1);
|
||
}
|
||
|
||
// 3. 按钮组:在右侧容器内,保留原有样式
|
||
.button-group {
|
||
display: flex;
|
||
position: relative;
|
||
gap: 2px;
|
||
align-items: center;
|
||
height: 24px;
|
||
background: #ecf4fe;
|
||
margin: 0;
|
||
|
||
.dropdown-container {
|
||
position: relative;
|
||
z-index: 999; // 提高z-index,确保菜单不被遮挡
|
||
}
|
||
|
||
.item-button {
|
||
cursor: pointer;
|
||
height: 24px;
|
||
font-family: PingFangSC, PingFang SC;
|
||
font-weight: 400;
|
||
font-size: 12px;
|
||
line-height: 24px;
|
||
font-style: normal;
|
||
letter-spacing: 2px;
|
||
|
||
overflow: hidden;
|
||
|
||
.item-text {
|
||
display: inline-block;
|
||
}
|
||
}
|
||
|
||
.category-btn {
|
||
width: 75px;
|
||
border-top-left-radius: 12px;
|
||
border-bottom-left-radius: 12px;
|
||
background: #ffffff;
|
||
color: #0b58ff;
|
||
text-align: center;
|
||
}
|
||
|
||
.profit-btn {
|
||
width: 123px;
|
||
border-top-right-radius: 12px;
|
||
border-bottom-right-radius: 12px;
|
||
position: relative;
|
||
padding: 0 18px 0 8px;
|
||
background: #ffffff;
|
||
color: #0b58ff;
|
||
text-align: left;
|
||
|
||
&.active {
|
||
background: #3071ff;
|
||
color: rgba(249, 252, 255, .8);
|
||
}
|
||
|
||
.profit-text {
|
||
text-align: left;
|
||
width: 100%;
|
||
}
|
||
}
|
||
|
||
.dropdown-arrow {
|
||
position: absolute;
|
||
right: 8px;
|
||
top: 50%;
|
||
transform: translateY(-50%);
|
||
width: 0;
|
||
height: 0;
|
||
border-left: 6px solid currentColor;
|
||
border-top: 4px solid transparent;
|
||
border-bottom: 4px solid transparent;
|
||
border-right: 4px solid transparent;
|
||
transition: transform 0.2s ease;
|
||
|
||
&.rotate {
|
||
transform: rotate(90deg); // 箭头旋转方向可根据需求调整,比如改为rotate(-90deg)更符合向上展开的视觉
|
||
}
|
||
}
|
||
|
||
.dropdown-options {
|
||
position: absolute;
|
||
// 关键修改1:调整top值,让菜单显示在选择框上方,calc(-100% - 2px)表示向上偏移自身100%再加2px间距
|
||
bottom: 100%;
|
||
right: 0;
|
||
// 移除多余的margin-top,避免额外间距
|
||
// margin-top: 2px;
|
||
width: 123px;
|
||
background: #ffffff;
|
||
// 关键修改2:调整border-radius,让菜单顶部圆角匹配选择框的右上角,底部圆角为0(更美观)
|
||
border-radius: 8px 8px 0 0;
|
||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||
overflow: hidden;
|
||
|
||
.dropdown-option {
|
||
padding: 6px 12px;
|
||
font-size: 12px;
|
||
color: #333;
|
||
cursor: pointer;
|
||
text-align: left;
|
||
letter-spacing: 1px;
|
||
|
||
&:hover {
|
||
background: #f5f7fa;
|
||
color: #3071ff;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style>
|