|
@@ -9,11 +9,10 @@
|
|
|
class="hidden-xs-only"
|
|
class="hidden-xs-only"
|
|
|
style="display: flex; align-items: center; margin: 16px 0"
|
|
style="display: flex; align-items: center; margin: 16px 0"
|
|
|
>
|
|
>
|
|
|
- <el-radio-group v-model="saleSearch.dateType">
|
|
|
|
|
- <el-radio-button label="1">今天</el-radio-button>
|
|
|
|
|
- <el-radio-button label="2">本周</el-radio-button>
|
|
|
|
|
- <el-radio-button label="3">本月</el-radio-button>
|
|
|
|
|
- <el-radio-button label="4">本年</el-radio-button>
|
|
|
|
|
|
|
+ <el-radio-group v-model="saleSearch.dateType" @change="updateDateRange">
|
|
|
|
|
+ <el-radio-button label="2">近7日</el-radio-button>
|
|
|
|
|
+ <el-radio-button label="3">近15日</el-radio-button>
|
|
|
|
|
+ <el-radio-button label="4">近一年</el-radio-button>
|
|
|
</el-radio-group>
|
|
</el-radio-group>
|
|
|
<div class="hidden-md-and-down" style="width: 320px; margin-left: 12px">
|
|
<div class="hidden-md-and-down" style="width: 320px; margin-left: 12px">
|
|
|
<el-date-picker
|
|
<el-date-picker
|
|
@@ -41,7 +40,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
- import { ref, reactive } from 'vue';
|
|
|
|
|
|
|
+ import { ref, reactive, watch, getCurrentInstance } from 'vue';
|
|
|
import { EleMessage } from 'ele-admin-plus/es';
|
|
import { EleMessage } from 'ele-admin-plus/es';
|
|
|
import { use } from 'echarts/core';
|
|
import { use } from 'echarts/core';
|
|
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
@@ -49,7 +48,8 @@
|
|
|
import { GridComponent, TooltipComponent } from 'echarts/components';
|
|
import { GridComponent, TooltipComponent } from 'echarts/components';
|
|
|
import VChart from 'vue-echarts';
|
|
import VChart from 'vue-echarts';
|
|
|
import { useEcharts } from '@/utils/use-echarts';
|
|
import { useEcharts } from '@/utils/use-echarts';
|
|
|
- import { getSaleroomList } from '@/api/dashboard/analysis';
|
|
|
|
|
|
|
+ import dayjs from 'dayjs';
|
|
|
|
|
+ const { proxy } = getCurrentInstance();
|
|
|
|
|
|
|
|
use([CanvasRenderer, BarChart, GridComponent, TooltipComponent]);
|
|
use([CanvasRenderer, BarChart, GridComponent, TooltipComponent]);
|
|
|
|
|
|
|
@@ -60,43 +60,84 @@
|
|
|
/** 销售额柱状图配置 */
|
|
/** 销售额柱状图配置 */
|
|
|
const saleChartOption = reactive({});
|
|
const saleChartOption = reactive({});
|
|
|
|
|
|
|
|
- /** 销售量趋势数据 */
|
|
|
|
|
- const saleroomData1 = ref([]);
|
|
|
|
|
-
|
|
|
|
|
- /** 访问量趋势数据 */
|
|
|
|
|
- const saleroomData2 = ref([]);
|
|
|
|
|
|
|
+ /** 订单数据 */
|
|
|
|
|
+ const orderData = ref([]);
|
|
|
|
|
|
|
|
/** 销售量搜索参数 */
|
|
/** 销售量搜索参数 */
|
|
|
const saleSearch = reactive({
|
|
const saleSearch = reactive({
|
|
|
- type: 'saleroom',
|
|
|
|
|
- dateType: '1',
|
|
|
|
|
- datetime: ['2022-01-01 10:44', '2022-01-03 13:00']
|
|
|
|
|
|
|
+ dateType: '2',
|
|
|
|
|
+ datetime: []
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- /** 获取销售量数据 */
|
|
|
|
|
- const getSaleroomData = () => {
|
|
|
|
|
- getSaleroomList()
|
|
|
|
|
- .then((data) => {
|
|
|
|
|
- saleroomData1.value = data.list1;
|
|
|
|
|
- onSaleTypeChange();
|
|
|
|
|
|
|
+ /** 更新时间范围 */
|
|
|
|
|
+ const updateDateRange = (type) => {
|
|
|
|
|
+ console.log(type, 'type');
|
|
|
|
|
+ const now = dayjs();
|
|
|
|
|
+ let start, end;
|
|
|
|
|
+
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case '2': // 近7日
|
|
|
|
|
+ start = now.subtract(6, 'day').startOf('day');
|
|
|
|
|
+ end = now.endOf('day');
|
|
|
|
|
+ break;
|
|
|
|
|
+ case '3': // 近15日
|
|
|
|
|
+ start = now.subtract(14, 'day').startOf('day');
|
|
|
|
|
+ end = now.endOf('day');
|
|
|
|
|
+ break;
|
|
|
|
|
+ case '4': // 近一年
|
|
|
|
|
+ start = now.subtract(1, 'year').startOf('day');
|
|
|
|
|
+ end = now.endOf('day');
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ saleSearch.datetime = [
|
|
|
|
|
+ start.format('YYYY-MM-DD HH:mm'),
|
|
|
|
|
+ end.format('YYYY-MM-DD HH:mm')
|
|
|
|
|
+ ];
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /** 获取订单数据 */
|
|
|
|
|
+ const getOrderData = async () => {
|
|
|
|
|
+ const [startTime, endTime] = saleSearch.datetime;
|
|
|
|
|
+ proxy.$http
|
|
|
|
|
+ .get('/order/orderstat/orderNumStat', {
|
|
|
|
|
+ params: { startTime, endTime }
|
|
|
})
|
|
})
|
|
|
- .catch((e) => {
|
|
|
|
|
- EleMessage.error(e.message);
|
|
|
|
|
|
|
+ .then((res) => {
|
|
|
|
|
+ if (res.data.code === 200) {
|
|
|
|
|
+ orderData.value = res.data.data;
|
|
|
|
|
+ updateChartOption();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ EleMessage.error(res.data.msg || '获取订单数据失败');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- getSaleroomData();
|
|
|
|
|
|
|
+ /** 更新图表配置 */
|
|
|
|
|
+ const updateChartOption = () => {
|
|
|
|
|
+ const dates = orderData.value.map((item) => item.date);
|
|
|
|
|
+ const values = orderData.value.map((item) => item.orderNum);
|
|
|
|
|
|
|
|
- /** 销售量tab选择改变事件 */
|
|
|
|
|
- const onSaleTypeChange = () => {
|
|
|
|
|
Object.assign(saleChartOption, {
|
|
Object.assign(saleChartOption, {
|
|
|
tooltip: {
|
|
tooltip: {
|
|
|
- trigger: 'axis'
|
|
|
|
|
|
|
+ trigger: 'axis',
|
|
|
|
|
+ axisPointer: {
|
|
|
|
|
+ type: 'shadow'
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ grid: {
|
|
|
|
|
+ left: '3%',
|
|
|
|
|
+ right: '4%',
|
|
|
|
|
+ bottom: '3%',
|
|
|
|
|
+ containLabel: true
|
|
|
},
|
|
},
|
|
|
xAxis: [
|
|
xAxis: [
|
|
|
{
|
|
{
|
|
|
type: 'category',
|
|
type: 'category',
|
|
|
- data: saleroomData1.value.map((d) => d.month)
|
|
|
|
|
|
|
+ data: dates,
|
|
|
|
|
+ axisTick: {
|
|
|
|
|
+ alignWithLabel: true
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
yAxis: [
|
|
yAxis: [
|
|
@@ -106,12 +147,27 @@
|
|
|
],
|
|
],
|
|
|
series: [
|
|
series: [
|
|
|
{
|
|
{
|
|
|
|
|
+ name: '订单数量',
|
|
|
type: 'bar',
|
|
type: 'bar',
|
|
|
- data: saleroomData1.value.map((d) => d.value)
|
|
|
|
|
|
|
+ barWidth: '40px',
|
|
|
|
|
+ data: values
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ // 监听日期范围变化
|
|
|
|
|
+ watch(
|
|
|
|
|
+ () => saleSearch.datetime,
|
|
|
|
|
+ (newDatetime) => {
|
|
|
|
|
+ if (newDatetime && newDatetime.length === 2) {
|
|
|
|
|
+ getOrderData();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化
|
|
|
|
|
+ updateDateRange('2');
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|