ccy_DIB/pages/DigitalIntelligenceDashboard/components/CustomerConsumptionPreferences.vue
ylj20011123 6e2bd12f8c update
2025-10-29 14:47:21 +08:00

208 lines
6.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="customer-consumption-preferences">
<!-- 客群消费偏好标题 -->
<view class="section-header">
<text class="section-title">客群消费偏好</text>
</view>
<!-- 客群消费偏好图表 -->
<view class="chart-container">
<!-- 图表加载效果 -->
<ChartLoading v-if="!hasChartData" text="数据加载中..." />
<!-- 实际图表 -->
<QiunDataCharts v-else type="column" :opts="chartOpts" :chartData="chartData" :canvas2d="true"
:inScrollView="true" canvasId="customerConsumptionPreferencesChart" :animation="false" :ontap="true"
:ontouch="true" tooltipFormat="customerConsumptionPreferencesChart" />
</view>
</view>
</template>
<script>
import QiunDataCharts from './qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue'
import ChartLoading from './ChartLoading.vue'
import request from "@/util/index.js";
import moment from 'moment'
export default {
components: {
QiunDataCharts,
ChartLoading
},
data() {
return {
// 图表原始数据
rawData: {
category: [],
seriesData: [],
realData: []
}
}
},
props: {
selectTime: {
type: String,
default: ""
},
},
computed: {
// 判断图表数据是否已加载
hasChartData() {
return this.rawData.category && this.rawData.category.length > 0;
},
// 图表数据
chartData() {
return {
categories: this.rawData.category,
series: [
{
name: '客单占比',
data: this.rawData.seriesData
}
]
}
},
// 图表配置
chartOpts() {
return {
padding: [15, 15, 0, 15], // 增加底部padding为X轴文字留空间
dataLabel: false,
enableScroll: true,
xAxis: {
disableGrid: true,
itemCount: 4, // 减少显示数量,避免文字太挤
},
yAxis: {
showTitle: true,
data: [{
min: 0,
title: '百分比(%)',
titleFontSize: 12,
titleOffsetY: -5,
titleOffsetX: 10,
}]
},
legend: {
show: true,
position: 'bottom',
float: 'center',
fontSize: 12,
fontColor: '#333333',
margin: 0,
padding: 0,
itemGap: 10,
textAlign: 'left'
},
extra: {
column: {
type: 'group',
width: 8, // 增加柱子宽度
activeBgColor: '#000000',
activeBgOpacity: 0.08,
seriesGap: 20, // 增加柱子间隔
barBorderRadius: [4, 4, 0, 0]
}
}
}
}
},
onReady() {
this.handleGetCustomerConsumptionPreferencesData()
},
methods: {
// 获取客群消费偏好数据
async handleGetCustomerConsumptionPreferencesData() {
const req = {
ProvinceCode: '530000',
StatisticsDate: this.selectTime ? moment(this.selectTime).subtract(1, 'd').format('YYYY-MM-DD') : moment().subtract(1, 'd').format('YYYY-MM-DD'),
ServerpartId: "" // 暂时为空如果需要传入服务区ID可以在这里添加
}
const data = await this.getBusinessTradeRevenue(req);
// 处理数据
this.processChartData(data.Result_Data)
},
// 发起API请求获取业态客单偏好数据
async getBusinessTradeRevenue(params) {
const data = await request.$webGet(
"CommercialApi/Revenue/GetBusinessTradeRevenue",
params
);
return data || {}
},
// 处理图表数据
processChartData(data) {
let category = []
let seriesData = []
let realData = []
// 处理数据:获取业态客单偏好数据
if (data.BusinessTradeRank && data.BusinessTradeRank.length > 0) {
let list = data.BusinessTradeRank.slice(0, 10) // 只取前10条
list.forEach((item) => {
category.push(item.name)
seriesData.push(Number(item.value))
realData.push(item.value)
})
}
// 更新图表数据
this.rawData = {
category: category,
seriesData: seriesData,
realData: realData
}
},
}
}
</script>
<style scoped lang="less">
@primary-color: #46B8F3;
@secondary-color: #3CD495;
@danger-color: #FF5E5E;
@success-color: #52C41A;
@text-primary: #333;
@text-secondary: #666;
@text-light: #999;
@bg-white: #ffffff;
@border-radius: 16rpx;
@shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
.customer-consumption-preferences {
margin-top: 24rpx;
.section-header {
display: flex;
align-items: center;
margin-bottom: 20rpx;
padding: 0 8rpx;
.section-title {
font-size: 30rpx;
font-weight: 600;
color: @text-primary;
}
}
.chart-container {
background: @bg-white;
border-radius: @border-radius;
padding: 24rpx;
box-shadow: @shadow;
margin-bottom: 24rpx;
width: 100%;
box-sizing: border-box;
height: 400rpx;
}
}
</style>