|
|
@@ -8,8 +8,10 @@
|
|
|
<div class="legend-item">上月</div>
|
|
|
<div class="legend-item">本月</div>
|
|
|
</div>
|
|
|
- <div id="marketChart" class="chart"></div>
|
|
|
- <div id="marketChart2" class="chart2"></div>
|
|
|
+ <div class="chart-wrap">
|
|
|
+ <div id="marketChart" class="chart"></div>
|
|
|
+ <div id="marketChart2" class="chart2"></div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -28,31 +30,42 @@
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- chartInstance: null,
|
|
|
+ chartInstanceA: null,
|
|
|
+ chartInstanceB: null,
|
|
|
chartData: {
|
|
|
categories: [
|
|
|
- "新增企业",
|
|
|
- "跟进项目",
|
|
|
- "新增联系人",
|
|
|
- "新增合同",
|
|
|
- "新增项目",
|
|
|
"新增户数",
|
|
|
+ "新增项目",
|
|
|
+ "新增合同",
|
|
|
+ "新增联系人",
|
|
|
+ "跟进企业",
|
|
|
+ "新增企业",
|
|
|
],
|
|
|
- lastMonthData: [-9, -9, -9, -9, -3, -12], // 上月数据
|
|
|
- thisMonthData: [9, 9, 1, 1, 9, 10], // 本月数据
|
|
|
},
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState(["entCode", "communityId"]),
|
|
|
+ lastMonthData() {
|
|
|
+ const data = this.data || {}
|
|
|
+ return Object.keys(data).map((key, index) => {
|
|
|
+ return -data[key].last_month
|
|
|
+ }).reverse()
|
|
|
+ },
|
|
|
+ thisMonthData() {
|
|
|
+ const data = this.data || {}
|
|
|
+ return Object.keys(data).map((key, index) => {
|
|
|
+ return data[key].this_month
|
|
|
+ }).reverse()
|
|
|
+ }
|
|
|
},
|
|
|
mounted() {
|
|
|
this.init()
|
|
|
window.addEventListener("resize", this.handleResize)
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
- if (this.chartInstance) {
|
|
|
- this.chartInstance.dispose()
|
|
|
+ if (this.chartInstanceA) {
|
|
|
+ this.chartInstanceA.dispose()
|
|
|
}
|
|
|
window.removeEventListener("resize", this.handleResize)
|
|
|
},
|
|
|
@@ -60,16 +73,18 @@
|
|
|
// 初始化组件
|
|
|
init() {
|
|
|
this.initChart()
|
|
|
- this.loadData()
|
|
|
},
|
|
|
|
|
|
// 初始化图表
|
|
|
initChart() {
|
|
|
- this.chartInstance = echarts.init(
|
|
|
+ this.chartInstanceA = echarts.init(
|
|
|
document.getElementById("marketChart")
|
|
|
)
|
|
|
+ this.chartInstanceB = echarts.init(
|
|
|
+ document.getElementById("marketChart2")
|
|
|
+ )
|
|
|
|
|
|
- const option = {
|
|
|
+ const optionA = {
|
|
|
tooltip: {
|
|
|
trigger: "axis",
|
|
|
axisPointer: {
|
|
|
@@ -96,7 +111,7 @@
|
|
|
},
|
|
|
grid: {
|
|
|
left: "10%",
|
|
|
- right: "10%",
|
|
|
+ right: "1%",
|
|
|
bottom: "5%",
|
|
|
top: "5%",
|
|
|
containLabel: true,
|
|
|
@@ -125,30 +140,13 @@
|
|
|
show: false,
|
|
|
},
|
|
|
},
|
|
|
- {
|
|
|
- type: "category",
|
|
|
- data: this.chartData.categories,
|
|
|
- axisLine: {
|
|
|
- show: false,
|
|
|
- },
|
|
|
- axisTick: {
|
|
|
- show: false,
|
|
|
- },
|
|
|
- axisLabel: {
|
|
|
- show: false,
|
|
|
- color: "#a0b3d6",
|
|
|
- fontSize: 14,
|
|
|
- },
|
|
|
- },
|
|
|
],
|
|
|
series: [
|
|
|
{
|
|
|
name: "上月",
|
|
|
type: "bar",
|
|
|
- stack: "sameStack",
|
|
|
- // stack: "Total",
|
|
|
- barMinHeight: 4,
|
|
|
- data: this.chartData.lastMonthData,
|
|
|
+ barMinHeight: 20,
|
|
|
+ data: this.lastMonthData,
|
|
|
barWidth: 16,
|
|
|
itemStyle: {
|
|
|
// 左侧渐变色:从#F66757到#FCE2B4
|
|
|
@@ -169,13 +167,75 @@
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
+ ],
|
|
|
+ }
|
|
|
+
|
|
|
+ const optionB = {
|
|
|
+ tooltip: {
|
|
|
+ trigger: "axis",
|
|
|
+ axisPointer: {
|
|
|
+ type: "shadow",
|
|
|
+ },
|
|
|
+ backgroundColor: "rgba(17, 28, 49, 0.9)",
|
|
|
+ borderColor: "rgba(64, 158, 255, 0.2)",
|
|
|
+ textStyle: {
|
|
|
+ color: "#ffffff",
|
|
|
+ },
|
|
|
+ formatter: (params) => {
|
|
|
+ // 自定义tooltip格式
|
|
|
+ let result = params[0].name + "<br/>"
|
|
|
+ params.forEach((item) => {
|
|
|
+ result +=
|
|
|
+ item.marker +
|
|
|
+ item.seriesName +
|
|
|
+ ": " +
|
|
|
+ Math.abs(item.value) +
|
|
|
+ "<br/>"
|
|
|
+ })
|
|
|
+ return result
|
|
|
+ },
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ left: "1%",
|
|
|
+ right: "10%",
|
|
|
+ bottom: "5%",
|
|
|
+ top: "5%",
|
|
|
+ containLabel: true,
|
|
|
+ },
|
|
|
+ xAxis: {
|
|
|
+ type: "value",
|
|
|
+ axisLabel: {
|
|
|
+ formatter: (value) => {
|
|
|
+ if (value < 0) return -value //这里是针对取负值
|
|
|
+ else return value
|
|
|
+ },
|
|
|
+ },
|
|
|
+ show: false, // 隐藏x轴
|
|
|
+ },
|
|
|
+ yAxis: [
|
|
|
+ {
|
|
|
+ type: "category",
|
|
|
+ data: this.chartData.categories,
|
|
|
+ axisLine: {
|
|
|
+ show: false,
|
|
|
+ },
|
|
|
+ axisTick: {
|
|
|
+ show: false,
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ show: true,
|
|
|
+ color: "#a0b3d6",
|
|
|
+ fontSize: 14,
|
|
|
+ align: "right",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ series: [
|
|
|
{
|
|
|
name: "本月",
|
|
|
type: "bar",
|
|
|
- stack: "sameStack",
|
|
|
- // stack: "Total",
|
|
|
- barMinHeight: 4,
|
|
|
- data: this.chartData.thisMonthData,
|
|
|
+ barMinHeight: 2,
|
|
|
+ data: this.thisMonthData,
|
|
|
barWidth: 16,
|
|
|
itemStyle: {
|
|
|
// 右侧渐变色:从#1620D4到#3AB3E3
|
|
|
@@ -196,56 +256,19 @@
|
|
|
],
|
|
|
}
|
|
|
|
|
|
- this.chartInstance.setOption(option)
|
|
|
- this.chartInstance.resize()
|
|
|
- },
|
|
|
-
|
|
|
- // 加载数据
|
|
|
- async loadData() {
|
|
|
- try {
|
|
|
- const params = {
|
|
|
- entCode: this.entCode,
|
|
|
- communityId: this.communityId,
|
|
|
- }
|
|
|
- // 这里应该调用实际的API获取数据
|
|
|
- // const res = await api.getMarketExpansionData(params)
|
|
|
- // this.chartData = res.data || this.chartData
|
|
|
-
|
|
|
- // 暂时使用模拟数据
|
|
|
- this.updateChart()
|
|
|
- } catch (error) {
|
|
|
- console.error("获取市场拓展数据失败:", error)
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 更新图表
|
|
|
- updateChart() {
|
|
|
- if (this.chartInstance) {
|
|
|
- this.chartInstance.setOption({
|
|
|
- yAxis: [
|
|
|
- {
|
|
|
- data: this.chartData.categories,
|
|
|
- },
|
|
|
- {
|
|
|
- data: this.chartData.categories,
|
|
|
- },
|
|
|
- ],
|
|
|
- series: [
|
|
|
- {
|
|
|
- data: this.chartData.lastMonthData,
|
|
|
- },
|
|
|
- {
|
|
|
- data: this.chartData.thisMonthData,
|
|
|
- },
|
|
|
- ],
|
|
|
- })
|
|
|
- }
|
|
|
+ this.chartInstanceA.setOption(optionA)
|
|
|
+ this.chartInstanceA.resize()
|
|
|
+ this.chartInstanceB.setOption(optionB)
|
|
|
+ this.chartInstanceB.resize()
|
|
|
},
|
|
|
|
|
|
// 处理窗口大小变化
|
|
|
handleResize() {
|
|
|
- if (this.chartInstance) {
|
|
|
- this.chartInstance.resize()
|
|
|
+ if (this.chartInstanceA) {
|
|
|
+ this.chartInstanceA.resize()
|
|
|
+ }
|
|
|
+ if (this.chartInstanceB) {
|
|
|
+ this.chartInstanceB.resize()
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
@@ -285,9 +308,20 @@
|
|
|
border-bottom: 1px solid rgba(64, 158, 255, 0.2);
|
|
|
}
|
|
|
|
|
|
- .chart {
|
|
|
+ .chart-wrap {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
- background: var(--content-bg);
|
|
|
+ .chart {
|
|
|
+ width: 40%;
|
|
|
+ height: 100%;
|
|
|
+ background: var(--content-bg);
|
|
|
+ }
|
|
|
+ .chart2 {
|
|
|
+ width: 60%;
|
|
|
+ height: 100%;
|
|
|
+ background: var(--content-bg);
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|