2025-06-03 11:53:46 +08:00
|
|
|
<template>
|
2025-06-07 15:51:05 +08:00
|
|
|
<el-card style="margin: 20px 20px; font-size: 14px">
|
|
|
|
<template v-slot:header>
|
|
|
|
<div class="clearfix">
|
|
|
|
<el-row>
|
|
|
|
<el-col :span="6">
|
|
|
|
<div style="font-weight: bold; font-size: 16px">订单统计</div>
|
|
|
|
</el-col>
|
|
|
|
<el-col :span="18">
|
|
|
|
<div style="text-align: right">
|
|
|
|
<el-radio-group v-model="params.type" size="small" @change="orderStat">
|
|
|
|
<el-radio-button label="1">近七日</el-radio-button>
|
|
|
|
<el-radio-button label="2">近三十日</el-radio-button>
|
|
|
|
</el-radio-group>
|
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div :style="{ minHeight: height, minWidth: width }">
|
|
|
|
<div ref="chart" class="chart" :style="{ height: height, width: width }" />
|
2025-06-03 11:53:46 +08:00
|
|
|
</div>
|
|
|
|
</el-card>
|
|
|
|
</template>
|
|
|
|
<script>
|
2025-06-07 15:51:05 +08:00
|
|
|
import { orderStatistics } from '@/api/statistics';
|
2025-06-04 10:23:45 +08:00
|
|
|
import * as echarts from 'echarts';
|
2025-06-03 11:53:46 +08:00
|
|
|
|
2025-06-07 15:51:05 +08:00
|
|
|
require('echarts/theme/macarons'); // echarts theme
|
|
|
|
import resize from './mixins/resize';
|
2025-06-03 11:53:46 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [resize],
|
2025-06-07 15:51:05 +08:00
|
|
|
name: 'OrderLineChart',
|
2025-06-03 11:53:46 +08:00
|
|
|
props: {
|
|
|
|
width: {
|
|
|
|
type: String,
|
|
|
|
default: '100%'
|
|
|
|
},
|
|
|
|
height: {
|
|
|
|
type: String,
|
|
|
|
default: '440px'
|
|
|
|
},
|
|
|
|
autoResize: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2025-06-07 15:51:05 +08:00
|
|
|
}
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
pickerOptions: {
|
2025-06-07 15:51:05 +08:00
|
|
|
shortcuts: [
|
|
|
|
{
|
|
|
|
text: '最近一周',
|
|
|
|
onClick(picker) {
|
|
|
|
const end = new Date();
|
|
|
|
const start = new Date();
|
|
|
|
start.setFullYear(2018);
|
|
|
|
start.setMonth(10);
|
|
|
|
start.setDate(1);
|
|
|
|
end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
|
|
|
|
picker.$emit('pick', [start, end]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: '最近一月',
|
|
|
|
onClick(picker) {
|
|
|
|
const end = new Date();
|
|
|
|
const start = new Date();
|
|
|
|
start.setFullYear(2018);
|
|
|
|
start.setMonth(10);
|
|
|
|
start.setDate(1);
|
|
|
|
end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
|
|
|
|
picker.$emit('pick', [start, end]);
|
|
|
|
}
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
]
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
orderCountDate: '',
|
|
|
|
params: {
|
|
|
|
type: 2
|
|
|
|
},
|
2025-06-07 15:51:05 +08:00
|
|
|
chartData: {}
|
|
|
|
};
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$nextTick(() => {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.initChart();
|
|
|
|
});
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
2025-06-07 15:51:05 +08:00
|
|
|
beforeUnmount() {
|
2025-06-03 11:53:46 +08:00
|
|
|
if (!this.chart) {
|
2025-06-07 15:51:05 +08:00
|
|
|
return;
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
this.chart.dispose();
|
|
|
|
this.chart = null;
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
created() {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.orderStat();
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
initChart() {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.chart = echarts.init(this.$refs.chart, 'macarons');
|
|
|
|
this.setOptions(this.chartData);
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
2025-06-07 15:51:05 +08:00
|
|
|
setOptions({ dateList, orderAmount, orderCount } = {}) {
|
2025-06-03 11:53:46 +08:00
|
|
|
this.chart.setOption({
|
|
|
|
title: {
|
|
|
|
text: '订单量趋势',
|
|
|
|
textStyle: {
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: 'bolder',
|
2025-06-07 15:51:05 +08:00
|
|
|
color: '#000000' // 主标题文字颜色
|
|
|
|
}
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
data: dateList,
|
|
|
|
type: 'category',
|
|
|
|
boundaryGap: false,
|
|
|
|
axisLabel: {
|
|
|
|
rotate: 40
|
|
|
|
},
|
|
|
|
textStyle: {
|
2025-06-07 15:51:05 +08:00
|
|
|
fontSize: 12
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
axisTick: {
|
|
|
|
show: false
|
|
|
|
},
|
|
|
|
axisLine: {
|
|
|
|
lineStyle: {
|
2025-06-07 15:51:05 +08:00
|
|
|
color: '#000000'
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
}
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
type: 'cross'
|
|
|
|
},
|
|
|
|
padding: [5, 10]
|
|
|
|
},
|
|
|
|
yAxis: [
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: '金额',
|
|
|
|
position: 'left',
|
|
|
|
alignTicks: true,
|
2025-06-07 15:51:05 +08:00
|
|
|
splitLine: {
|
2025-06-03 11:53:46 +08:00
|
|
|
show: false
|
|
|
|
},
|
2025-06-07 15:51:05 +08:00
|
|
|
axisTick: {
|
2025-06-03 11:53:46 +08:00
|
|
|
show: false
|
|
|
|
},
|
|
|
|
axisLine: {
|
|
|
|
show: false,
|
|
|
|
lineStyle: {
|
2025-06-07 15:51:05 +08:00
|
|
|
color: '#000000'
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
}
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: '数量',
|
2025-06-07 15:51:05 +08:00
|
|
|
minInterval: 1,
|
2025-06-03 11:53:46 +08:00
|
|
|
position: 'right',
|
2025-06-07 15:51:05 +08:00
|
|
|
splitLine: {
|
2025-06-03 11:53:46 +08:00
|
|
|
show: false
|
|
|
|
},
|
2025-06-07 15:51:05 +08:00
|
|
|
axisTick: {
|
2025-06-03 11:53:46 +08:00
|
|
|
show: false
|
|
|
|
},
|
|
|
|
axisLine: {
|
|
|
|
show: false,
|
|
|
|
lineStyle: {
|
2025-06-07 15:51:05 +08:00
|
|
|
color: '#000000'
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
}
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
legend: {
|
|
|
|
data: ['订单金额', '订单数']
|
|
|
|
},
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
name: '订单金额',
|
|
|
|
itemStyle: {
|
|
|
|
normal: {
|
2025-06-07 15:51:05 +08:00
|
|
|
color: '#5b8ff9'
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'bar',
|
|
|
|
barMaxWidth: 20,
|
|
|
|
data: orderAmount,
|
|
|
|
animationDuration: 2800,
|
|
|
|
animationEasing: 'cubicInOut'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '订单数',
|
|
|
|
smooth: true,
|
|
|
|
type: 'line',
|
|
|
|
itemStyle: {
|
|
|
|
normal: {
|
2025-06-07 15:51:05 +08:00
|
|
|
color: '#5ccfd9'
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
yAxisIndex: 1,
|
|
|
|
data: orderCount,
|
|
|
|
animationDuration: 2800,
|
|
|
|
animationEasing: 'quadraticOut'
|
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
]
|
|
|
|
});
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
handleDateChange() {
|
|
|
|
this.getData();
|
|
|
|
},
|
2025-06-07 15:51:05 +08:00
|
|
|
orderStat() {
|
|
|
|
orderStatistics(this.params).then((res) => {
|
|
|
|
const orderAmount = res.map((it) => {
|
|
|
|
return it.orderAmount;
|
|
|
|
});
|
|
|
|
const orderCount = res.map((it) => {
|
|
|
|
return it.orderCount;
|
|
|
|
});
|
|
|
|
const dateList = res.map((it) => {
|
|
|
|
return it.date.substr(5);
|
|
|
|
});
|
|
|
|
this.chartData = { dateList, orderAmount, orderCount };
|
|
|
|
this.initChart();
|
|
|
|
});
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
};
|
2025-06-03 11:53:46 +08:00
|
|
|
</script>
|
2025-06-07 15:51:05 +08:00
|
|
|
<style scoped lang="scss"></style>
|