bar.vue
5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<template>
<div :id="echartId" :style="'width:'+width+'px'" class="chart-container"></div>
</template>
<script>
import { couponsTotalByDay } from '../../api/modules/rules'
import { converterApi } from '../../api/modules/converter'
import utils from '../../util/util'
import * as echarts from 'echarts'
const base_url = 'https://img01.glsx.com.cn/weapp/resource/saas/scrm/'
export default {
name: '',
data() {
return {
xAxisData: [],
getTotal: [],
usedTotal: [],
upgradeTotal: [],
base_url
}
},
props: {
echartId: {
type: String,
default: ''
},
width: {
type: Number,
default: 400
}
},
mounted() {
this.initTIme()
},
methods: {
getOptions(len) {
var dataZoom = [
//给x轴设置滚动条
{
start: 0, //默认为0
end: 100 - 1500 / 31, //默认为100
type: 'slider',
show: true,
xAxisIndex: [0],
handleSize: 0, //滑动条的 左右2个滑动条的大小
height: 1, //组件高度
left: '10%', //左边的距离
right: '10%', //右边的距离
bottom: 26, //右边的距离
borderColor: '#fff',
fillerColor: '#909399',
borderRadius: 5,
backgroundColor: '#f5f5f5', //两边未选中的滑动条区域的颜色
showDataShadow: false, //是否显示数据阴影 默认auto
showDetail: false, //即拖拽时候是否显示详细数值信息 默认true
realtime: true, //是否实时更新
filterMode: 'filter',
zoomLock: false
},
//下面这个属性是里面拖到
{
type: 'inside',
show: false,
xAxisIndex: [0],
start: 1, //默认为1
end: 100 - 1500 / 31 //默认为100
}
]
var chartDom = document.getElementById(this.echartId)
var myChart = echarts.init(chartDom)
var labelOption = {
show: false
}
var option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
height: '60%',
},
legend: {
data: ['领券数', '核销数', '精品升级订单']
// itemWidth: 12,
// itemHeight: 12,
// data: [
// {
// icon: `image://${base_url}echart_icon_1.png`,
// name: '领券数'
// },
// {
// icon: `image://${base_url}echart_icon_2.png`,
// name: '核销数'
// },
// {
// icon: `image://${base_url}echart_icon_3.png`,
// name: '精品升级订单'
// }
// ]
},
xAxis: [
{
// name: '日期',
type: 'category',
axisTick: { show: false },
data: this.xAxisData.reverse(),
axisLabel: {
interval: 0
},
inverse:true
}
],
yAxis: [
{
type: 'value',
name: '数量'
}
],
series: [
{
name: '领券数',
type: 'bar',
barGap: 0,
label: labelOption,
barWidth: 6,
emphasis: {
focus: 'series'
},
itemStyle: {
normal: {
color: '#B3B3FF'
}
},
data: this.getTotal.reverse()
},
{
name: '核销数',
type: 'bar',
label: labelOption,
emphasis: {
focus: 'series'
},
barWidth: 6,
itemStyle: {
normal: {
color: '#7C7CFF'
}
},
data: this.usedTotal.reverse()
},
{
name: '精品升级订单',
type: 'bar',
label: labelOption,
barWidth: 6,
emphasis: {
focus: 'series'
},
itemStyle: {
normal: {
color: '#5850FF'
}
},
data: this.upgradeTotal.reverse()
}
]
}
if (len > 6) {
option.dataZoom = dataZoom
}
option && myChart.setOption(option)
},
// 初始化时间
initTIme() {
// let openInfo = JSON.parse(localStorage.getItem('openInfo'))
// let startDate = utils.dateFormat(openInfo.openDate)
let startDate = utils.getDateStr(-15)
let endDate = utils.dateFormat(new Date())
this.couponsChartData(startDate, endDate)
},
couponsChartData(startDate, endDate) {
this.xAxisData = []
this.getTotal = []
this.usedTotal = []
this.upgradeTotal = []
let method = couponsTotalByDay()
let para = {
routerMethod: method,
startDate,
endDate
}
converterApi(para).then(res => {
let arr = res || []
if (arr.length) {
arr.map(item => {
item.dataDate = utils.dateFormat(item.dataDate)
this.xAxisData.push(item.dataDate)
this.getTotal.push(item.getTotal)
this.usedTotal.push(item.usedTotal)
this.upgradeTotal.push(item.upgradeTotal)
return item
})
}
this.getOptions(arr.length)
})
}
}
}
</script>
<style>
.chart-container {
width: 100%;
height: 300px;
overflow: hidden;
}
</style>