Commit 703db180 by 匡雅琴

数据总览接口联调

1 parent 9310343e
<!--
* @Description: 柱状图
* @Author: huyue
* @Date: 2023-07-07 14:01:42
* @LastEditors: huyue
* @LastEditTime: 2023-08-03 16:43:09
-->
<template>
<div>
<div :id="domId" style="width: 100%" :style="{ height }"></div>
</div>
</template>
<script type="text/ecmascript-6">
import * as echarts from 'echarts'
import BarOptions from './BarOptions'
import utils from '../../../utils/util'
export default {
name: 'BarChart',
props: {
domId: {
type: String,
default: ''
},
dataList: {
type: Array,
default: () => []
},
tooltipFormatterObj: {
type: Object,
default: () => {
return {
label: '数量',
attrName: 'num'
}
}
},
colorList: {
type: Array
},
height: {
type: String,
default: '15vh'
},
barWidth: String,
isMultiple: {
type: Boolean,
default: false
},
formatYAxis: Boolean
},
data() {
return {
barOptions: []
}
},
created() {
this.barOptions = BarOptions({ tooltipFormatter: this.tooltipFormatter }, this.colorList, this.isMultiple, this.barWidth, this.formatYAxis)
},
mounted() {
this.barDom = document.getElementById(this.domId)
this[this.domId] = echarts.init(this.barDom)
this.chartBindEvent()
},
methods: {
tooltipFormatter(obj) {
var _currentItem = this.dataList[obj[0].dataIndex]
var _html = ''
var _txt = ''
_txt += `<div style="display:flex;"><div style="color: #c9c9c9">${this.tooltipFormatterObj.label}:</div><div style="color: #fff;">${utils.numAddSymbol(_currentItem[this.tooltipFormatterObj.attrName])}${this.tooltipFormatterObj.addSymbol || ''}</div></div>`
_html += `<div style="backdrop-filter: blur(4px);background-color: #051526;border: 2px solid;border-image: linear-gradient(90deg, #074989, #30DCFF, #074989) 1;padding: 10px;">
${_txt}
</div>`
return _html
},
drawBar() {
this.barOptions.xAxis.data = this.dataList.map(item => item.statDate)
this.barOptions.series[0].data = this.dataList.map(item => item[this.tooltipFormatterObj.attrName])
this[this.domId].setOption(this.barOptions)
},
chartBindEvent() {
// resize
window.addEventListener('resize', () => {
this[this.domId].resize()
})
}
}
}
</script>
/*
* @Description: 柱状图配置
* @Author: huyue
* @Date: 2023-07-07 14:04:52
* @LastEditors: huyue
* @LastEditTime: 2023-08-03 16:42:12
*/
import * as echarts from 'echarts'
function getBarOptions(obj, colorList, isMultiple, barwidth, formatYAxis) {
const barWidth = barwidth || '14'
const multiple = isMultiple || false
const { tooltipFormatter } = obj
var barLineOption = {
tooltip: {
trigger: 'axis',
borderWidth: 0,
padding: 0,
formatter: tooltipFormatter || '',
confine: true
},
xAxis: {
data: []
},
barWidth: barWidth,
yAxis: {
name: '',
type: 'value',
// min: 0,
// max: 100,
splitLine: {
lineStyle: {
color: '#1d2a38'
}
},
splitNumber: 4,
axisLabel: {
// 这种做法就是在y轴的数据的值旁边拼接单位,貌似也挺方便的
formatter: function(value) {
if (formatYAxis) {
return `${value / 10000}万`
} else {
return value
}
}
}
},
grid: {
left: '0',
right: '4%',
top: '20%',
bottom: '4%',
containLabel: true
},
series: [
{
name: 'bar',
type: 'bar',
data: [],
label: {
show: false
},
itemStyle: {
barBorderRadius: [2, 2, 0, 0], // 柱体圆角
color: function(params) {
var colorItem = []
if (multiple) {
colorItem = params.dataIndex % 2 === 0 ? colorList[0] : colorList[1]
}
return new echarts.graphic.LinearGradient(
0, 0, 0, 1, [{ // 代表渐变色从正上方开始
offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
color: multiple ? colorItem[0] : colorList[0]
}, // 柱图渐变色
{
offset: 0.5, // 指100%处的颜色
color: multiple ? colorItem[1] : colorList[1]
},
{
offset: 1, // 指100%处的颜色
color: multiple ? colorItem[2] : colorList[2]
}]
)
}
}
}
]
}
return barLineOption
}
export default getBarOptions
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</template> </template>
<script> <script>
import BarChart from '../../crowdfunding/components/BarChart.vue' import BarChart from './BarChart.vue'
export default { export default {
name: 'TrendLeft', name: 'TrendLeft',
components: { components: {
...@@ -32,6 +32,7 @@ export default { ...@@ -32,6 +32,7 @@ export default {
tooltips: { tooltips: {
amountTooltip: { amountTooltip: {
label: '单量', label: '单量',
// num --> 提单量;merNum --> 提单门店
attrName: 'num' attrName: 'num'
} }
}, },
...@@ -41,12 +42,25 @@ export default { ...@@ -41,12 +42,25 @@ export default {
] ]
} }
}, },
created() {
mounted() { this.getWholesaleTrend()
this.$refs.orderTrendChartRef.drawBar()
}, },
methods: {} mounted() {},
methods: {
async getWholesaleTrend() {
const params = {
queryItem: 'thisYear',
queryType: 'gh'
}
const _result = await this.api.equity.getWholesaleTrend(params)
this.dataList = _result.data.dataList
this.$nextTick(() => {
this.$refs.orderTrendChartRef.drawBar()
})
}
}
} }
</script> </script>
......
...@@ -16,65 +16,36 @@ export default { ...@@ -16,65 +16,36 @@ export default {
data() { data() {
return { return {
merchantRankList: [ merchantRankList: [],
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
},
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
},
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
},
{
merchantName: '奥迪',
num: 345485
},
{
merchantName: '奥迪',
num: 345485
},
{
merchantName: '奥迪',
num: 345485
},
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
},
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
},
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
},
{
merchantName: 'xxxxxxxxxx门店',
num: 345485
}
],
rankingDataObj: [ rankingDataObj: [
{ {
name: 'merchantName', name: 'merchantName',
width: '10vw' width: '14vw'
}, },
{ {
name: 'num', name: 'num',
width: '8vw', width: '5vw',
type: 'number' type: 'number'
} }
] ]
} }
}, },
created() {
this.getWholesaleRank()
},
mounted() {}, mounted() {},
methods: {} methods: {
async getWholesaleRank() {
const params = {
queryItem: 'thisYear',
queryType: 'gh'
}
const _result = await this.api.equity.getWholesaleRank(params)
this.merchantRankList = _result.data.dataList
}
}
} }
</script> </script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!