Commit bb82e15f by chenwq

feat(behaviorManage): 添加LTV和属性饼图组件并重构页面

重构行为管理模块页面,移除旧表单逻辑,新增LTVChart和AttributePieChart组件
- 添加LTVChart组件展示LTV数据趋势
- 添加AttributePieChart组件展示客户属性分布
- 优化日期选择器配置
- 移除未使用的代码和样式
1 parent 614ddec2
...@@ -2,84 +2,27 @@ ...@@ -2,84 +2,27 @@
<div> <div>
<div class="scrm-sub-client-container"> <div class="scrm-sub-client-container">
<div class="pageContent"> <div class="pageContent">
<GLCombiForm ref="combiForm" :formObj="searchForm" :formData="clientManageFormList" @handleOk="searchTable" @handleRest="resetTable"></GLCombiForm> <!-- <GLCombiForm ref="combiForm" :formObj="searchForm" :formData="clientManageFormList" @handleOk="searchTable" @handleRest="resetTable"></GLCombiForm> -->
<LTVChart style="margin-top: 20px;" />
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { getDictionaryFun } from '@/api/modules/clientManage' import LTVChart from './components/LTVChart.vue'
export default { export default {
name: 'LTVList', name: 'LTVList',
components: {
LTVChart
},
data() { data() {
return { return {
searchForm: {
addWay: ''
},
clientManageFormList: [
{
type: 'input',
inputType: 'text',
name: 'customerName',
label: '客户名称',
placeholder: '请输入客户名称'
},
{
type: 'select',
name: 'addWay',
label: '添加来源',
optionLabel: 'label',
optionId: 'value',
placeholder: '请选择当前来源',
optionList: [] //this.$Constants.SOURCE_OPTION
},
{
type: 'datePicker',
name: 'purchaseCar',
label: '购车时间',
valueFormat: 'yyyy-MM-dd',
pickerOptions: {
disabledDate(time) {
return time.getTime() > Date.now() || time.getTime() < new Date('2017-12-31').getTime()
}
}
}
],
sourceList: [] sourceList: []
} }
}, },
created() {
this.getDictionaryFun()
},
methods: { methods: {
getDictionaryFun() {
getDictionaryFun({ dictType: 'add_way' }).then(res => {
if (!res) {
return
}
// addWaySource
const id = this.clientManageFormList.findIndex(item => {
return item.name == 'addWay'
})
let data = res.map(item => {
return {
// ...item,
label: item.dictLabel,
value: item.dictValue
}
})
data.unshift({ label: '全部', value: '' })
this.sourceList = data || []
if (data && data.length > 0) {
window.localStorage.setItem('sourceList', JSON.stringify(data))
}
this.$set(this.clientManageFormList[id], 'optionList', data)
})
},
//搜索表格 //搜索表格
searchTable() { searchTable() {
this.$refs.clientManage.refreshTable() this.$refs.clientManage.refreshTable()
...@@ -96,7 +39,7 @@ export default { ...@@ -96,7 +39,7 @@ export default {
}, },
}, },
mounted() {} mounted() { }
} }
</script> </script>
......
...@@ -3,96 +3,88 @@ ...@@ -3,96 +3,88 @@
<div class="scrm-sub-client-container"> <div class="scrm-sub-client-container">
<div class="pageContent"> <div class="pageContent">
<GLCombiForm ref="combiForm" :formObj="searchForm" :formData="clientManageFormList" @handleOk="searchTable" @handleRest="resetTable"></GLCombiForm> <GLCombiForm ref="combiForm" :formObj="searchForm" :formData="clientManageFormList" @handleOk="searchTable" @handleRest="resetTable"></GLCombiForm>
<!-- Pie Chart Component -->
<AttributePieChart style="margin-top: 20px;" :date-filter="searchForm.purchaseCar" />
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { getDictionaryFun } from '@/api/modules/clientManage' import AttributePieChart from './components/AttributePieChart.vue'
export default { export default {
name: 'attributeList', name: 'attributeList',
components: {
AttributePieChart
},
data() { data() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const todayStr = `${year}-${month}-${day}`;
return { return {
searchForm: { searchForm: {
addWay: '' addWay: [],
customerName: '',
purchaseCar: todayStr
}, },
clientManageFormList: [ clientManageFormList: [
{ // {
type: 'input', // type: 'input',
inputType: 'text', // inputType: 'text',
name: 'customerName', // name: 'customerName',
label: '客户名称', // label: '客户名称',
placeholder: '请输入客户名称' // placeholder: '请输入客户名称'
}, // },
{ // {
type: 'select', // type: 'select',
name: 'addWay', // name: 'addWay',
label: '添加来源', // label: '事件选择',
optionLabel: 'label', // multiple: true,
optionId: 'value', // collapseTags: true,
placeholder: '请选择当前来源', // optionLabel: 'label',
optionList: [] //this.$Constants.SOURCE_OPTION // optionId: 'value',
}, // placeholder: '请选择事件',
// optionList: EVENT_OPTIONS
// },
{ {
type: 'datePicker', type: 'datePicker',
name: 'purchaseCar', name: 'purchaseCar',
label: '购车时间', label: '时间选择',
valueFormat: 'yyyy-MM-dd', valueFormat: 'yyyy-MM-dd',
pickerOptions: { dateType: 'week',
attrs: {
format: 'yyyy 第 WW 周'
},
customPickerOptions: {
disabledDate(time) { disabledDate(time) {
return time.getTime() > Date.now() || time.getTime() < new Date('2017-12-31').getTime() return time.getTime() > Date.now() || time.getTime() < new Date('2017-12-31').getTime()
} }
} }
} }
], ]
sourceList: []
} }
}, },
created() {
this.getDictionaryFun()
},
methods: { methods: {
getDictionaryFun() {
getDictionaryFun({ dictType: 'add_way' }).then(res => {
if (!res) {
return
}
// addWaySource
const id = this.clientManageFormList.findIndex(item => {
return item.name == 'addWay'
})
let data = res.map(item => {
return {
// ...item,
label: item.dictLabel,
value: item.dictValue
}
})
data.unshift({ label: '全部', value: '' })
this.sourceList = data || []
if (data && data.length > 0) {
window.localStorage.setItem('sourceList', JSON.stringify(data))
}
this.$set(this.clientManageFormList[id], 'optionList', data)
})
},
//搜索表格 //搜索表格
searchTable() { searchTable() {
this.$refs.clientManage.refreshTable()
}, },
//重置表格 //重置表格
resetTable() { resetTable() {
this.searchForm = {} const now = new Date();
this.$refs.clientManage.refreshTable() const year = now.getFullYear();
// 点击之后强制页面刷新 const month = String(now.getMonth() + 1).padStart(2, '0');
// this.reload() const day = String(now.getDate()).padStart(2, '0');
// this.$forceUpdate() // 没用 const todayStr = `${year}-${month}-${day}`;
// this.$router.go(0)//没有预期效果,会出现一段空白页,用户体验不好
// location.reload() //没有预期效果,会出现一段空白页,用户体验不好 this.searchForm = {
addWay: [],
customerName: '',
purchaseCar: todayStr
}
}, },
}, },
...@@ -101,34 +93,6 @@ export default { ...@@ -101,34 +93,6 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/resetelement.scss';
// /deep/.el-table .el-table__header tr th{
// line-height: 30px;
// }
.expandImg {
display: flex;
// justify-content: center;
.smallFontSize {
margin-left: 2px;
height: 20px;
font-size: 12px;
letter-spacing: 0;
line-height: 20px;
font-weight: 400;
}
.imgEll {
margin-left: 6.5px;
cursor: pointer;
// margin-bottom:3px;
}
}
.pure-green-text {
color: #61cc43;
}
.pure-yello-text {
color: #fb8f28;
}
.scrm-sub-client-container { .scrm-sub-client-container {
.pageTitle { .pageTitle {
margin-bottom: 20px; margin-bottom: 20px;
...@@ -175,23 +139,6 @@ export default { ...@@ -175,23 +139,6 @@ export default {
height: 100% !important; //设置高优先,以覆盖内联样式 height: 100% !important; //设置高优先,以覆盖内联样式
} }
} }
.entmicro {
display: flex;
i {
color: #75acff;
margin-right: 3px;
font-size: 14px;
}
// }
}
.el-tag {
// margin-right: 10px;
max-width: 110px;
cursor: pointer;
background-color: #fff !important;
}
} }
} }
</style> </style>
<template>
<div class="attribute-pie-chart">
<!-- 图表展示区 -->
<div class="section-container">
<div class="section-title">图表展示区</div>
<div class="chart-content">
<!-- 左侧 ECharts -->
<div class="chart-wrapper">
<div ref="pieChart" style="width: 100%; height: 400px;"></div>
</div>
<!-- 右侧自定义图例列表 -->
<div class="legend-list-wrapper">
<div class="legend-header">
<el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
<span class="count-info">{{ selectedItems.length }} / {{ chartData.length }} 项</span>
</div>
<div class="legend-list">
<div v-for="(item, index) in chartData" :key="index" class="legend-item">
<el-checkbox v-model="item.checked" @change="handleCheckedChange"></el-checkbox>
<span class="color-dot" :style="{ backgroundColor: getColor(index) }"></span>
<span class="item-name" :title="item.name">{{ item.name }}</span>
<span class="item-value">{{ item.value }}</span>
<span class="item-percent">{{ item.percent }}%</span>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts';
export default {
name: 'AttributePieChart',
data() {
return {
currentDimension: '基金类型偏好',
displayCount: 10,
chart: null,
checkAll: true,
isIndeterminate: false,
colors: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'],
// Mock Data
chartData: [
{ name: '新客户', value: 0, percent: 0, checked: true },
{ name: '首购客户', value: 0, percent: 0, checked: true },
{ name: '复购客户', value: 0, percent: 0, checked: true },
{ name: '未购买客户', value: 0, percent: 0, checked: true }
]
};
},
computed: {
selectedItems() {
return this.chartData.filter(item => item.checked);
}
},
props: {
dateFilter: {
type: String,
default: ''
}
},
watch: {
dateFilter: {
handler(newVal) {
this.generateRandomData(newVal);
this.updateChart();
},
immediate: true
}
},
mounted() {
// Initial generation is handled by immediate watch
this.initChart();
window.addEventListener('resize', this.handleResize);
},
methods: {
generateRandomData(seed) {
// Reset values
this.chartData.forEach(item => item.value = 0);
let baseDate = new Date();
if (seed) {
// Try to parse the seed date
const parsed = new Date(seed);
if (!isNaN(parsed.getTime())) {
baseDate = parsed;
}
}
// Calculate data only for the current week of baseDate
const d = new Date(baseDate);
// Construct a unique key for this week to ensure deterministic "random" data
const year = d.getFullYear();
// Simple week identifier
const oneJan = new Date(year, 0, 1);
const dayOfYear = Math.floor((d - oneJan) / (24 * 60 * 60 * 1000));
const weekNum = Math.ceil((d.getDay() + 1 + dayOfYear) / 7);
const weekKey = `${year}-W${weekNum}`;
this.chartData.forEach(item => {
// Generate value for this specific week and item
// range: 10 - 200 per week
const weeklySeed = item.name + weekKey;
const weeklyValue = this.getPseudoRandom(weeklySeed, 10, 200);
item.value = weeklyValue;
});
// Recalculate percentages
const total = this.chartData.reduce((sum, item) => sum + item.value, 0);
this.chartData.forEach(item => {
item.percent = total === 0 ? 0 : ((item.value / total) * 100).toFixed(2);
});
},
getPseudoRandom(seed, min = 100, max = 8000) {
let value = 0;
for (let i = 0; i < seed.length; i++) {
value += seed.charCodeAt(i);
}
const sinValue = Math.sin(value) * 10000;
return Math.floor((sinValue - Math.floor(sinValue)) * (max - min) + min);
},
getColor(index) {
return this.colors[index % this.colors.length];
},
handleResize() {
if (this.chart) this.chart.resize();
},
initChart() {
this.chart = echarts.init(this.$refs.pieChart);
this.updateChart();
},
updateChart() {
if (!this.chart) return;
const data = this.chartData.filter(item => item.checked).map((item, index) => ({
value: item.value,
name: item.name,
itemStyle: { color: this.getColor(index) } // Keep color consistent with list index if possible, or dynamic
}));
// To maintain color consistency between list and chart, we should assign colors based on original index
// However, for simplicity here, we'll let echarts handle or map manually.
// Better approach: Assign color to data item first.
const option = {
tooltip: {
trigger: 'item',
formatter: '{b}: {c} ({d}%)'
},
legend: {
show: false // We use custom legend
},
series: [
{
name: 'Access From',
type: 'pie',
radius: ['40%', '70%'], // Donut chart
avoidLabelOverlap: true,
itemStyle: {
borderRadius: 2,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: true,
formatter: '{b}: {c} ({d}%)'
},
emphasis: {
label: {
show: true,
fontSize: 14,
fontWeight: 'bold'
}
},
labelLine: {
show: true
},
data: this.chartData.filter(item => item.checked).map((item, index) => ({
value: item.value,
name: item.name,
itemStyle: { color: this.getColor(this.chartData.indexOf(item)) }
}))
}
]
};
this.chart.setOption(option);
},
handleCheckAllChange(val) {
this.chartData.forEach(item => item.checked = val);
this.isIndeterminate = false;
this.updateChart();
},
handleCheckedChange(value) {
let checkedCount = this.chartData.filter(item => item.checked).length;
this.checkAll = checkedCount === this.chartData.length;
this.isIndeterminate = checkedCount > 0 && checkedCount < this.chartData.length;
this.updateChart();
}
}
};
</script>
<style scoped lang="scss">
.attribute-pie-chart {
background-color: #f5f7fa; // Match page background if needed, or white
padding: 0;
}
.section-container {
background: #fff;
padding: 20px;
border-radius: 4px;
margin-bottom: 20px;
.section-title {
font-size: 16px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
}
.config-row {
display: flex;
align-items: center;
margin-bottom: 15px;
flex-wrap: wrap;
.label {
margin-right: 10px;
color: #606266;
font-size: 14px;
}
.filter-tags, .group-tags {
margin-left: 10px;
.el-tag {
margin-right: 10px;
}
}
}
.chart-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 15px;
}
.chart-content {
display: flex;
align-items: flex-start;
.chart-wrapper {
flex: 2;
min-width: 400px;
}
.legend-list-wrapper {
flex: 1;
min-width: 300px;
margin-left: 20px;
border: 1px solid #eee;
border-radius: 4px;
padding: 10px;
background: #fff;
max-height: 400px;
overflow-y: auto;
.legend-header {
display: flex;
justify-content: space-between;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
margin-bottom: 10px;
.count-info {
color: #909399;
font-size: 12px;
}
}
.legend-item {
display: flex;
align-items: center;
padding: 8px 0;
font-size: 13px;
.color-dot {
width: 8px;
height: 8px;
border-radius: 50%;
margin: 0 8px;
display: inline-block;
}
.item-name {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-right: 10px;
color: #606266;
}
.item-value {
width: 60px;
text-align: right;
margin-right: 10px;
color: #333;
}
.item-percent {
width: 50px;
text-align: right;
color: #909399;
}
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<div class="ltv-chart-container">
<!-- Controls Header -->
<div class="chart-controls">
<div class="control-item">
<span class="label">窗口期</span>
<el-select v-model="windowPeriod" placeholder="请选择" size="small" style="width: 120px;">
<el-option v-for="item in windowOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
</el-select>
</div>
<div class="control-item">
<span class="label">展示指标</span>
<el-select v-model="metric" placeholder="请选择" size="small" style="width: 120px;">
<el-option v-for="item in metricOptions" :key="item" :label="item" :value="item"></el-option>
</el-select>
</div>
<div class="control-item">
<span class="label">展示分组值</span>
<el-select v-model="selectedGroups" multiple collapse-tags placeholder="请选择" size="small" style="width: 200px;">
<el-option v-for="item in groupOptions" :key="item" :label="item" :value="item"></el-option>
</el-select>
</div>
<div class="control-item">
<el-button type="primary" size="small" @click="resetControls">重置</el-button>
</div>
</div>
<!-- Chart Container -->
<div ref="chart" class="chart-body" style="height: 400px; width: 100%;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
export default {
name: 'LTVChart',
data() {
return {
windowPeriod: 'LTV0',
metric: '总营收',
selectedGroups: ['20-30岁', '30-40岁', '40-50岁'],
windowOptions: [
{ label: 'LTV 当天', value: 'LTV0' },
{ label: 'LTV1', value: 'LTV1' },
{ label: 'LTV2', value: 'LTV2' },
{ label: 'LTV3', value: 'LTV3' },
{ label: 'LTV4', value: 'LTV4' },
{ label: 'LTV5', value: 'LTV5' },
{ label: 'LTV6', value: 'LTV6' },
{ label: 'LTV7', value: 'LTV7' }
],
metricOptions: ['总营收', 'ARPU', 'ARPPU'],
groupOptions: ['<20岁', '20-30岁', '30-40岁', '40-50岁', '50-60岁', '≥60岁'],
chart: null
};
},
mounted() {
this.initChart();
window.addEventListener('resize', this.handleResize);
},
beforeDestroy() {
if (this.chart) {
this.chart.dispose();
}
window.removeEventListener('resize', this.handleResize);
},
watch: {
windowPeriod() { this.updateChart(); },
metric() { this.updateChart(); },
selectedGroups() { this.updateChart(); }
},
methods: {
handleResize() {
if (this.chart) {
this.chart.resize();
}
},
resetControls() {
this.windowPeriod = 'LTV0';
this.metric = '总营收';
this.selectedGroups = ['20-30岁', '30-40岁', '40-50岁'];
},
initChart() {
this.chart = echarts.init(this.$refs.chart);
this.updateChart();
},
getLast7Days() {
const dates = [];
const today = new Date();
for (let i = 6; i >= 0; i--) {
const d = new Date(today);
d.setDate(today.getDate() - i);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, '0');
const date = String(d.getDate()).padStart(2, '0');
dates.push(`${year}-${month}-${date}`);
}
return dates;
},
getPseudoRandom(seed) {
let value = 0;
for (let i = 0; i < seed.length; i++) {
value += seed.charCodeAt(i);
}
const sinValue = Math.sin(value) * 10000;
return Math.floor((sinValue - Math.floor(sinValue)) * (280 - 150) + 150);
},
updateChart() {
if (!this.chart) return;
const dates = this.getLast7Days();
// Mock data generation based on selected groups
const series = this.selectedGroups.map(group => {
return {
name: group,
type: 'line',
smooth: false,
data: dates.map(date => {
// Create a deterministic seed based on filter criteria
const seed = `${this.windowPeriod}-${this.metric}-${group}-${date}`;
return this.getPseudoRandom(seed);
})
};
});
const option = {
tooltip: {
trigger: 'axis',
backgroundColor: '#fff',
textStyle: {
color: '#333'
},
formatter: (params) => {
let result = `${params[0].axisValue}: ${this.metric}<br/>`;
params.forEach(param => {
result += `${param.marker} ${param.seriesName} &nbsp;&nbsp;&nbsp; ${param.value}<br/>`;
});
return result;
}
},
legend: {
bottom: 0,
data: this.selectedGroups,
icon: 'rect',
itemWidth: 12,
itemHeight: 12
},
grid: {
left: '3%',
right: '4%',
bottom: '10%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: dates,
axisLine: {
lineStyle: {
color: '#eee'
}
},
axisLabel: {
color: '#666'
}
},
yAxis: {
type: 'value',
min: 150, // Adjust based on mock data range
axisLine: {
show: false
},
axisTick: {
show: false
},
splitLine: {
lineStyle: {
type: 'dashed',
color: '#eee'
}
},
axisLabel: {
color: '#666'
}
},
series: series,
color: ['#409EFF', '#67C23A', '#9b59b6', '#E6A23C', '#73c0de', '#3ba272', '#fc8452', '#9a60b4']
};
this.chart.setOption(option, true);
}
}
};
</script>
<style scoped>
.ltv-chart-container {
background: #fff;
padding: 20px;
border-radius: 4px;
/* margin-top: 20px; */
}
.chart-controls {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.control-item {
display: flex;
align-items: center;
margin-right: 20px;
}
.control-item .label {
margin-right: 10px;
font-size: 14px;
color: #606266;
font-weight: 500;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!