|
@@ -0,0 +1,108 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <el-header>
|
|
|
|
|
+ <el-radio-group v-model="query.type" @change="radioChange">
|
|
|
|
|
+ <el-radio-button v-for="(item, key) in radioDic" :key="key" :label="key">{{ item.label }}</el-radio-button>
|
|
|
|
|
+ </el-radio-group>
|
|
|
|
|
+
|
|
|
|
|
+ <el-date-picker v-if="query.type == 'year'" v-model="query.year" type="yearrange" :clearable="false" range-separator="至" @change="getEcharts" />
|
|
|
|
|
+ <el-date-picker v-if="query.type == 'month'" v-model="query.month" type="monthrange" :clearable="false" range-separator="至" @change="getEcharts" />
|
|
|
|
|
+ <el-date-picker v-if="query.type == 'day'" v-model="query.day" type="daterange" :clearable="false" range-separator="至" @change="getEcharts" />
|
|
|
|
|
+ </el-header>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="echart-panel">
|
|
|
|
|
+ <scEcharts clearCache :option="option"></scEcharts>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script setup>
|
|
|
|
|
+import moment from "moment";
|
|
|
|
|
+import XEUtils from "xe-utils";
|
|
|
|
|
+
|
|
|
|
|
+import API from "@/api";
|
|
|
|
|
+import { radioDic, lineSeriesDefault } from "../main";
|
|
|
|
|
+
|
|
|
|
|
+const query = reactive({
|
|
|
|
|
+ type: "year",
|
|
|
|
|
+ year: [moment().subtract(5, "year"), moment()],
|
|
|
|
|
+ month: [moment().startOf("year").format("YYYY-MM-DD"), moment().endOf("year").format("YYYY-MM-DD")],
|
|
|
|
|
+ day: [moment().startOf("month").format("YYYY-MM-DD"), moment().endOf("month").format("YYYY-MM-DD")],
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const radioChange = (e) => {
|
|
|
|
|
+ option.series = []
|
|
|
|
|
+ getEcharts()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const option = reactive({
|
|
|
|
|
+ color: computed(() => query.type == "day" ? ["#36CE9E"] : []),
|
|
|
|
|
+ title: { text: "计划/实际销售额趋势", textStyle: { fontSize: 16 }, top: 15 },
|
|
|
|
|
+ legend: { left: "center", top: 55 },
|
|
|
|
|
+ grid: { top: 120 },
|
|
|
|
|
+ tooltip: {
|
|
|
|
|
+ trigger: "axis",
|
|
|
|
|
+ confine: true,
|
|
|
|
|
+ axisPointer: { type: "cross", crossStyle: { color: "#999" } }
|
|
|
|
|
+ },
|
|
|
|
|
+ xAxis: {
|
|
|
|
|
+ type: "category",
|
|
|
|
|
+ data: [],
|
|
|
|
|
+ axisLabel: { formatter: value => query.type == "day" ? moment(value).format("MM-DD") : value },
|
|
|
|
|
+ axisPointer: { label: { backgroundColor: "#d3d2d3" } }
|
|
|
|
|
+ },
|
|
|
|
|
+ yAxis: {
|
|
|
|
|
+ type: "value",
|
|
|
|
|
+ name: "单位:元",
|
|
|
|
|
+ min: 0,
|
|
|
|
|
+ max: computed(() => XEUtils.max(XEUtils.flatten(XEUtils.map(option.series, item => item.data))) || 100),
|
|
|
|
|
+ axisTick: { show: false },
|
|
|
|
|
+ splitLine: { lineStyle: { type: "dashed", color: ["#efefef"] } } // grid区域中的分隔线 数值轴显示,类目轴不显示
|
|
|
|
|
+ },
|
|
|
|
|
+ series: []
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const getEcharts = () => {
|
|
|
|
|
+ const [beginDate, endDate] = radioDic[query.type].valueFormat(query[query.type]);
|
|
|
|
|
+ option.xAxis.data = radioDic[query.type].generateXAxis(beginDate, endDate);
|
|
|
|
|
+
|
|
|
|
|
+ API.sales.performance.echart({ type: query.type, beginDate, endDate }).then(res => {
|
|
|
|
|
+ if (query.type == "day") {
|
|
|
|
|
+ option.series = [{
|
|
|
|
|
+ ...lineSeriesDefault[1],
|
|
|
|
|
+ data: XEUtils.map(option.xAxis.data, date => XEUtils.get(XEUtils.find(res.actualList, item => item.date == date), "price", 0)),
|
|
|
|
|
+ }];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ option.series = [{
|
|
|
|
|
+ ...lineSeriesDefault[0],
|
|
|
|
|
+ data: XEUtils.map(option.xAxis.data, date => XEUtils.get(XEUtils.find(res.planList, item => item.date2 == date), "price", 0)),
|
|
|
|
|
+ }, {
|
|
|
|
|
+ ...lineSeriesDefault[1],
|
|
|
|
|
+ data: XEUtils.map(option.xAxis.data, date => XEUtils.get(XEUtils.find(res.actualList, item => item.date2 == date), "price", 0)),
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ if (query.type == "day") {
|
|
|
|
|
+ option.series = [{
|
|
|
|
|
+ ...lineSeriesDefault[1],
|
|
|
|
|
+ data: new Array(option.xAxis.data.length).fill(0)
|
|
|
|
|
+ }];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ option.series = [{
|
|
|
|
|
+ ...lineSeriesDefault[0],
|
|
|
|
|
+ data: new Array(option.xAxis.data.length).fill(0),
|
|
|
|
|
+ }, {
|
|
|
|
|
+ ...lineSeriesDefault[1],
|
|
|
|
|
+ data: new Array(option.xAxis.data.length).fill(0),
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+getEcharts();
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+.el-header {height: fit-content;padding: 0;border: none;}
|
|
|
|
|
+.el-header :deep(.el-radio-group) {flex-wrap: nowrap;}
|
|
|
|
|
+.el-header :deep(.el-date-editor.el-range-editor) {flex-grow: 0;width: 260px;}
|
|
|
|
|
+.echart-panel {flex: 1;}
|
|
|
|
|
+</style>
|