提交 | 用户 | 时间
|
5cc1d9
|
1 |
<template> |
D |
2 |
<el-card shadow="never" class="aui-card--fill"> |
|
3 |
<div class="mod-index-full"> |
|
4 |
<el-form :inline="true" :model="dataForm" label-width="100px"> |
|
5 |
<el-form-item :label="$t('datePicker.date')"> |
|
6 |
<el-date-picker |
|
7 |
v-model="dataForm.dateRange" |
|
8 |
type="datetimerange" |
|
9 |
format="yyyy-MM-dd HH:mm" |
|
10 |
value-format="yyyy-MM-dd HH:mm" |
|
11 |
range-separator="至" |
|
12 |
start-placeholder="开始日期" |
|
13 |
end-placeholder="结束日期"> |
|
14 |
</el-date-picker> |
|
15 |
</el-form-item> |
|
16 |
<el-form-item label="商品煤种"> |
|
17 |
<dict-select-tag style="width: 100%" |
|
18 |
v-model="dataForm.index" |
|
19 |
placeholder="商品煤种" |
|
20 |
dictCode="spmz" |
|
21 |
:clearable="false"/> |
|
22 |
</el-form-item> |
|
23 |
<el-form-item> |
|
24 |
<el-button @click="queryChart()">{{ $t('query') }}</el-button> |
|
25 |
</el-form-item> |
|
26 |
</el-form> |
|
27 |
</div> |
|
28 |
<div id="chartLineBox" style="width: 90%;height: 70vh;"> </div> |
|
29 |
</el-card> |
|
30 |
</template> |
|
31 |
<script> |
|
32 |
import DictSelectTag from "@/components/dict/dict-select-tag"; |
|
33 |
import BarLine from "@/components/chart/bar-line"; |
|
34 |
import {getYMD} from "@/utils/dateUtils"; |
|
35 |
import * as echarts from 'echarts' |
|
36 |
|
|
37 |
export default { |
|
38 |
components: {DictSelectTag, BarLine}, |
|
39 |
data() { |
|
40 |
return { |
|
41 |
loading: false, |
|
42 |
chartOption: {}, |
|
43 |
dataForm: { |
|
44 |
groupType: 'day', |
|
45 |
dateRange: [], |
|
46 |
index: '' |
|
47 |
} |
|
48 |
} |
|
49 |
}, |
|
50 |
mounted() { |
|
51 |
this.chartLine = echarts.init(document.getElementById('chartLineBox')); |
|
52 |
|
|
53 |
// 指定图表的配置项和数据 |
|
54 |
var option = { |
|
55 |
tooltip: { //设置tip提示 |
|
56 |
trigger: 'axis' |
|
57 |
}, |
|
58 |
color: ['#869ad7'], //设置区分(每条线是什么颜色,和 legend 一一对应) |
|
59 |
xAxis: { //设置x轴 |
|
60 |
boundaryGap: false, |
|
61 |
type: 'category', |
|
62 |
boundaryGap: false, //坐标轴两边不留白 |
|
63 |
data: ['2023-5-31', '2023-6-1', '2023-6-2', '2023-6-3', '2023-6-4', '2023-6-5', '2023-6-6','2023-6-7',], |
|
64 |
name: '日期', //X轴 name |
|
65 |
nameTextStyle: { //坐标轴名称的文字样式 |
|
66 |
color: 'black', |
|
67 |
fontSize: 16, |
|
68 |
padding: [0, 0, 0, 20] |
|
69 |
}, |
|
70 |
axisLine: { //坐标轴轴线相关设置。 |
|
71 |
lineStyle: { |
|
72 |
color: 'black', |
|
73 |
} |
|
74 |
} |
|
75 |
}, |
|
76 |
yAxis: { |
|
77 |
nameTextStyle: { |
|
78 |
color: 'black', |
|
79 |
fontSize: 16, |
|
80 |
padding: [0, 0, 10, 0] |
|
81 |
}, |
|
82 |
axisLine: { |
|
83 |
lineStyle: { |
|
84 |
color: 'black', |
|
85 |
} |
|
86 |
}, |
|
87 |
type: 'value' |
|
88 |
}, |
|
89 |
series: [ |
|
90 |
{ |
|
91 |
areaStyle: {}, |
|
92 |
name: '销售数量', |
|
93 |
data: [123,41,144,200,56,74,282,192], |
|
94 |
type: 'line', |
|
95 |
lineStyle: { |
|
96 |
normal: { |
|
97 |
color: '#869ad7', |
|
98 |
} |
|
99 |
}, |
|
100 |
} |
|
101 |
] |
|
102 |
}; |
|
103 |
|
|
104 |
// 使用刚指定的配置项和数据显示图表。 |
|
105 |
this.chartLine.setOption(option); |
|
106 |
|
|
107 |
}, |
|
108 |
methods: { |
|
109 |
init() { |
|
110 |
this.dataForm.dateRange = [] |
|
111 |
this.dataForm.dateRange.push(getYMD(new Date().getTime() - 3600 * 1000 * 24 * 30) + ' 00:00') |
|
112 |
this.dataForm.dateRange.push(getYMD(new Date()) + ' 23:59') |
|
113 |
}, |
|
114 |
|
|
115 |
queryChart() { |
|
116 |
let params = { |
|
117 |
groupType: this.dataForm.groupType, |
|
118 |
startDate: this.dataForm.dateRange[0] + ':00', |
|
119 |
endDate: this.dataForm.dateRange[1] + ':59', |
|
120 |
index: this.dataForm.index |
|
121 |
} |
|
122 |
this.loading = true |
|
123 |
this.$http.post(`/iailab-iems-coal-proddisp/analysis/index/chart`, params).then(({data: res}) => { |
|
124 |
this.loading = false |
|
125 |
if (res.code !== 0) { |
|
126 |
return this.$message.error(res.msg) |
|
127 |
} |
|
128 |
let series = [] |
|
129 |
if (res.data.series) { |
|
130 |
res.data.series.forEach(function (item) { |
|
131 |
series.push( |
|
132 |
{ |
|
133 |
name: item.name, |
|
134 |
data: item.data, |
|
135 |
type: 'line', |
|
136 |
smooth: false |
|
137 |
} |
|
138 |
) |
|
139 |
}) |
|
140 |
} |
|
141 |
|
|
142 |
this.chartOption = { |
|
143 |
grid: { |
|
144 |
top: '8%', |
|
145 |
right: '10%', |
|
146 |
bottom: '12%', |
|
147 |
left: '10%' |
|
148 |
}, |
|
149 |
legend: { |
|
150 |
type: 'scroll', |
|
151 |
orient: 'vertical', |
|
152 |
right: 5, |
|
153 |
top: 20, |
|
154 |
bottom: 20, |
|
155 |
data: res.data.legend |
|
156 |
}, |
|
157 |
toolbox: { |
|
158 |
show: true, |
|
159 |
top: 0, |
|
160 |
right: '10%', |
|
161 |
feature: { |
|
162 |
dataView: {readOnly: false}, |
|
163 |
magicType: {type: ['line', 'bar']}, |
|
164 |
saveAsImage: {} |
|
165 |
} |
|
166 |
}, |
|
167 |
xAxis: { |
|
168 |
type: 'category', |
|
169 |
data: res.data.categories |
|
170 |
}, |
|
171 |
yAxis: { |
|
172 |
type: 'value', |
|
173 |
name: res.data.valueName, |
|
174 |
nameTextStyle: { |
|
175 |
fontWeight: 'bold' |
|
176 |
}, |
|
177 |
axisLine: { |
|
178 |
show: true |
|
179 |
} |
|
180 |
}, |
|
181 |
series: series |
|
182 |
} |
|
183 |
|
|
184 |
}).catch(() => { |
|
185 |
this.loading = false |
|
186 |
}) |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
</script> |