|
@@ -3,16 +3,18 @@
|
|
<el-row :gutter="5">
|
|
<el-row :gutter="5">
|
|
<el-col :span="9">
|
|
<el-col :span="9">
|
|
<div>
|
|
<div>
|
|
- <TextSelector v-model="modelValue" :options="pieOptions" @change="changePie" style="margin-top: 5px"/>
|
|
|
|
|
|
+ <TextSelector v-model="modelValue" :options="computedPieOptions" @change="changePie" style="margin-top: 5px"/>
|
|
</div>
|
|
</div>
|
|
<div ref="pie" style="height: 400px;"></div>
|
|
<div ref="pie" style="height: 400px;"></div>
|
|
</el-col>
|
|
</el-col>
|
|
<el-col :span="15">
|
|
<el-col :span="15">
|
|
<div style="margin-left: 40%">
|
|
<div style="margin-left: 40%">
|
|
<span style="background: #3a83f7; width: 18px; height: 10px; margin-top: 8px; display: inline-block; border-radius: 3px;"></span>
|
|
<span style="background: #3a83f7; width: 18px; height: 10px; margin-top: 8px; display: inline-block; border-radius: 3px;"></span>
|
|
- <TextSelector v-model="barModelValue1" :options="computedBarOptions1" @change="changeBarOne" style="margin-top: 5px; margin-left: 8px;"/>
|
|
|
|
|
|
+ <TextSelector v-model="barModelValue1" :options="computedBarOptions1" @change="changeBarOne"
|
|
|
|
+ style="margin-top: 5px; margin-left: 8px;"/>
|
|
<span style="background: #f19a37; width: 18px; height: 10px; margin-top: 8px; margin-left: 20px; display: inline-block; border-radius: 3px;"></span>
|
|
<span style="background: #f19a37; width: 18px; height: 10px; margin-top: 8px; margin-left: 20px; display: inline-block; border-radius: 3px;"></span>
|
|
- <TextSelector v-model="barModelValue2" :options="computedBarOptions2" @change="changeBarTwo" style="margin-top: 5px; margin-left: 8px;"/>
|
|
|
|
|
|
+ <TextSelector v-model="barModelValue2" :options="computedBarOptions2" @change="changeBarTwo"
|
|
|
|
+ style="margin-top: 5px; margin-left: 8px;"/>
|
|
</div>
|
|
</div>
|
|
<div ref="bar" style="height: 400px;"></div>
|
|
<div ref="bar" style="height: 400px;"></div>
|
|
</el-col>
|
|
</el-col>
|
|
@@ -21,27 +23,23 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
-import { onMounted, ref, inject, watch, nextTick } from "vue"
|
|
|
|
|
|
+import { computed, inject, onMounted, ref, watch } from "vue"
|
|
import * as echarts from "echarts"
|
|
import * as echarts from "echarts"
|
|
import TextSelector from '/@/components/TextSelector/index.vue'
|
|
import TextSelector from '/@/components/TextSelector/index.vue'
|
|
import { getAdStructureData } from "/@/views/adManage/sp/campaigns/api"
|
|
import { getAdStructureData } from "/@/views/adManage/sp/campaigns/api"
|
|
import { createDisabledOptions } from '../../../utils/dropdowndisable'
|
|
import { createDisabledOptions } from '../../../utils/dropdowndisable'
|
|
|
|
+import { barOptionsMap, metricMap } from '/@/views/adManage/utils/enum'
|
|
|
|
+import { useShopInfo } from '/@/stores/shopInfo'
|
|
|
|
|
|
-
|
|
|
|
|
|
+const shopInfo = useShopInfo()
|
|
let pieChart = ref()
|
|
let pieChart = ref()
|
|
let barChart = ref()
|
|
let barChart = ref()
|
|
const pie = ref()
|
|
const pie = ref()
|
|
const bar = ref()
|
|
const bar = ref()
|
|
const loading = ref(true)
|
|
const loading = ref(true)
|
|
|
|
|
|
-let dateRange = inject('dateRange')
|
|
|
|
-console.log('dateRange', dateRange.value)
|
|
|
|
-watch(
|
|
|
|
- dateRange,
|
|
|
|
- () => {
|
|
|
|
- console.log('-------watch dateRange', dateRange.value)
|
|
|
|
- }
|
|
|
|
-)
|
|
|
|
|
|
+const dateRange = inject('dateRange')
|
|
|
|
+
|
|
// 下拉框相关
|
|
// 下拉框相关
|
|
const pieOptions = [
|
|
const pieOptions = [
|
|
{
|
|
{
|
|
@@ -69,14 +67,6 @@ const pieOptions = [
|
|
label: '点击量',
|
|
label: '点击量',
|
|
},
|
|
},
|
|
]
|
|
]
|
|
-const metricMap = {
|
|
|
|
- 'Spend': '花费',
|
|
|
|
- 'TotalSales': '销售额',
|
|
|
|
- 'TotalPurchases': '订单数',
|
|
|
|
- 'TotalUnitOrdered': '销量',
|
|
|
|
- 'Impression': '曝光量',
|
|
|
|
- 'Click': '点击量',
|
|
|
|
-}
|
|
|
|
let modelValue = ref(pieOptions[0].value)
|
|
let modelValue = ref(pieOptions[0].value)
|
|
|
|
|
|
const barOptions1 = [
|
|
const barOptions1 = [
|
|
@@ -258,7 +248,7 @@ onMounted(async () => {
|
|
let allData = null
|
|
let allData = null
|
|
|
|
|
|
async function setAdStructureData() {
|
|
async function setAdStructureData() {
|
|
- allData = await getAdStructureData({ start: dateRange.value[0], end: dateRange.value[1], profile: '3006125408623189' })
|
|
|
|
|
|
+ allData = await getAdStructureData({ start: dateRange.value[0], end: dateRange.value[1], profile: shopInfo.profile.profile_id })
|
|
console.log('allData.data', allData.data)
|
|
console.log('allData.data', allData.data)
|
|
return allData.data
|
|
return allData.data
|
|
}
|
|
}
|
|
@@ -270,8 +260,8 @@ let pieBarData = null
|
|
// 柱状图初始数据
|
|
// 柱状图初始数据
|
|
let ACOSList
|
|
let ACOSList
|
|
let SpendList
|
|
let SpendList
|
|
-let ClassificationList
|
|
|
|
-let classificationMapList
|
|
|
|
|
|
+let xAxisList
|
|
|
|
+let xAxisMapList
|
|
|
|
|
|
async function initPieBarData() {
|
|
async function initPieBarData() {
|
|
pieBarData = await setAdStructureData()
|
|
pieBarData = await setAdStructureData()
|
|
@@ -284,7 +274,7 @@ async function initPieBarData() {
|
|
ACOSList = barData.map(item => item.ACOS)
|
|
ACOSList = barData.map(item => item.ACOS)
|
|
SpendList = barData.map(item => item.Spend)
|
|
SpendList = barData.map(item => item.Spend)
|
|
// 将x轴映射为中文
|
|
// 将x轴映射为中文
|
|
- ClassificationList = barData.map(item => item.Classification)
|
|
|
|
|
|
+ xAxisList = barData.map(item => item.Classification)
|
|
const classificationMap = {
|
|
const classificationMap = {
|
|
'BROAD': '关键词-广泛',
|
|
'BROAD': '关键词-广泛',
|
|
'category': '品类',
|
|
'category': '品类',
|
|
@@ -296,17 +286,16 @@ async function initPieBarData() {
|
|
'substitutes': '同类商品',
|
|
'substitutes': '同类商品',
|
|
'complements': '关联商品'
|
|
'complements': '关联商品'
|
|
}
|
|
}
|
|
- classificationMapList = ClassificationList.map(item => classificationMap[item])
|
|
|
|
|
|
+ xAxisMapList = xAxisList.map(item => classificationMap[item])
|
|
loading.value = false
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
|
|
// 重置图像
|
|
// 重置图像
|
|
let flag = ref()
|
|
let flag = ref()
|
|
-let barFlag = ref()
|
|
|
|
-let barFlag2 = ref()
|
|
|
|
let option
|
|
let option
|
|
let option2
|
|
let option2
|
|
|
|
|
|
|
|
+// 点击下拉框后重新渲染饼图
|
|
function changePie(newValue) {
|
|
function changePie(newValue) {
|
|
modelValue.value = newValue
|
|
modelValue.value = newValue
|
|
flag.value = modelValue.value
|
|
flag.value = modelValue.value
|
|
@@ -314,46 +303,62 @@ function changePie(newValue) {
|
|
{ value: pieBarData.pie_data[0][flag.value], name: '自动' },
|
|
{ value: pieBarData.pie_data[0][flag.value], name: '自动' },
|
|
{ value: pieBarData.pie_data[1][flag.value], name: '手动' },
|
|
{ value: pieBarData.pie_data[1][flag.value], name: '手动' },
|
|
]
|
|
]
|
|
- // pieChart.clear() // 清除当前饼图的配置
|
|
|
|
- // option2.series[0].data = newPieData // 确保更新的是数组中的正确位置
|
|
|
|
- // pieChart.setOption(option2, true) // 使用 true 强制合并选项
|
|
|
|
pieChart.setOption(option2)
|
|
pieChart.setOption(option2)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 点击下拉框后重新渲染柱状图
|
|
function changeBarOne(newValue) {
|
|
function changeBarOne(newValue) {
|
|
barModelValue1.value = newValue
|
|
barModelValue1.value = newValue
|
|
- barFlag.value = barModelValue1.value
|
|
|
|
- const barValues = []
|
|
|
|
- try {
|
|
|
|
- for (let i = 0; i < barData.length; i++) {
|
|
|
|
- const value = barData[i][barFlag.value]
|
|
|
|
- barValues.push(value)
|
|
|
|
- }
|
|
|
|
- option.series[0].data = barValues
|
|
|
|
- barChart.setOption(option)
|
|
|
|
- } catch (error) {
|
|
|
|
- console.log(error)
|
|
|
|
- }
|
|
|
|
|
|
+ updateBarChart()
|
|
}
|
|
}
|
|
|
|
|
|
function changeBarTwo(newValue) {
|
|
function changeBarTwo(newValue) {
|
|
barModelValue2.value = newValue
|
|
barModelValue2.value = newValue
|
|
- barFlag2.value = barModelValue2.value
|
|
|
|
- const barValues = []
|
|
|
|
- try {
|
|
|
|
- for (let i = 0; i < barData.length; i++) {
|
|
|
|
- const value = barData[i][barFlag2.value]
|
|
|
|
- barValues.push(value)
|
|
|
|
- }
|
|
|
|
- option.series[1].data = barValues
|
|
|
|
- barChart.setOption(option)
|
|
|
|
- } catch (error) {
|
|
|
|
- console.log(error)
|
|
|
|
|
|
+ updateBarChart()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function updateBarChart() {
|
|
|
|
+ const barValues1 = barData.map(item => item[barModelValue1.value])
|
|
|
|
+ const barValues2 = barData.map(item => item[barModelValue2.value])
|
|
|
|
+
|
|
|
|
+ option.series[0].data = barValues1
|
|
|
|
+ option.series[1].data = barValues2
|
|
|
|
+ barChart.setOption(option)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 监听时间变化重新渲染表格
|
|
|
|
+watch(dateRange, async () => {
|
|
|
|
+ if (dateRange.value) {
|
|
|
|
+ loading.value = true
|
|
|
|
+ const resp = await setAdStructureData()
|
|
|
|
+ updatePieChartData(resp)
|
|
|
|
+ updateBarChartData(resp)
|
|
|
|
+ loading.value = false
|
|
}
|
|
}
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+// 根据新数据和当前下拉框选择更新 饼图数据
|
|
|
|
+function updatePieChartData(resp) {
|
|
|
|
+ option2.series[0].data = [
|
|
|
|
+ { value: resp.pie_data[0][modelValue.value], name: '自动' },
|
|
|
|
+ { value: resp.pie_data[1][modelValue.value], name: '手动' },
|
|
|
|
+ ]
|
|
|
|
+ pieChart.setOption(option2)
|
|
}
|
|
}
|
|
|
|
|
|
-const computedBarOptions1 = computed(() => createDisabledOptions(barOptions1, barModelValue2.value))
|
|
|
|
-const computedBarOptions2 = computed(() => createDisabledOptions(barOptions2, barModelValue1.value))
|
|
|
|
|
|
+// 根据新数据和当前下拉框选择更新 柱状图数据
|
|
|
|
+function updateBarChartData(resp) {
|
|
|
|
+ const barValues1 = resp.line_data.map(item => item[barModelValue1.value])
|
|
|
|
+ const barValues2 = resp.line_data.map(item => item[barModelValue2.value])
|
|
|
|
+
|
|
|
|
+ option.series[0].data = barValues1
|
|
|
|
+ option.series[1].data = barValues2
|
|
|
|
+ barChart.setOption(option)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const computedBarOptions1 = computed(() => createDisabledOptions(barOptions1, barModelValue2.value, barModelValue1.value))
|
|
|
|
+const computedBarOptions2 = computed(() => createDisabledOptions(barOptions2, barModelValue1.value, barModelValue2.value))
|
|
|
|
+const computedPieOptions = computed(() => createDisabledOptions(pieOptions, modelValue.value))
|
|
|
|
|
|
// 初始化图表
|
|
// 初始化图表
|
|
function initChart() {
|
|
function initChart() {
|
|
@@ -363,31 +368,32 @@ function initChart() {
|
|
trigger: 'axis',
|
|
trigger: 'axis',
|
|
axisPointer: {
|
|
axisPointer: {
|
|
type: 'shadow',
|
|
type: 'shadow',
|
|
- label: {
|
|
|
|
- backgroundColor: '#6a7985'
|
|
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ rich: {
|
|
|
|
+ b: {
|
|
|
|
+ color: '#4C5058',
|
|
|
|
+ fontSize: 15,
|
|
|
|
+ fontWeight: 'bold',
|
|
|
|
+ lineHeight: 33
|
|
|
|
+ },
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // legend: {data: ['数据1', '数据2'],},
|
|
|
|
toolbox: {
|
|
toolbox: {
|
|
feature: {
|
|
feature: {
|
|
saveAsImage: { yAxisIndex: 'none' }
|
|
saveAsImage: { yAxisIndex: 'none' }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- grid: {
|
|
|
|
- top: 55, right: 60, bottom: 55, left: 55,
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
|
|
+ grid: { top: 55, right: 60, bottom: 55, left: 55, },
|
|
xAxis: [
|
|
xAxis: [
|
|
{
|
|
{
|
|
type: 'category',
|
|
type: 'category',
|
|
boundaryGap: true,
|
|
boundaryGap: true,
|
|
- data: classificationMapList,
|
|
|
|
|
|
+ data: xAxisMapList,
|
|
axisLabel: {
|
|
axisLabel: {
|
|
rotate: -30, // 将标签旋转
|
|
rotate: -30, // 将标签旋转
|
|
fontSize: 13
|
|
fontSize: 13
|
|
- },
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
],
|
|
],
|
|
yAxis: [
|
|
yAxis: [
|
|
{
|
|
{
|
|
@@ -422,7 +428,7 @@ function initChart() {
|
|
],
|
|
],
|
|
series: [
|
|
series: [
|
|
{
|
|
{
|
|
- // name: '数据1',
|
|
|
|
|
|
+ name: barOptionsMap[barModelValue1.value],
|
|
type: 'bar',
|
|
type: 'bar',
|
|
barWidth: '15%',
|
|
barWidth: '15%',
|
|
data: ACOSList,
|
|
data: ACOSList,
|
|
@@ -437,7 +443,7 @@ function initChart() {
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- // name: '数据2',
|
|
|
|
|
|
+ name: barOptionsMap[barModelValue2.value],
|
|
type: 'bar',
|
|
type: 'bar',
|
|
barWidth: '15%',
|
|
barWidth: '15%',
|
|
data: SpendList,
|
|
data: SpendList,
|
|
@@ -462,7 +468,6 @@ function initChart() {
|
|
},
|
|
},
|
|
series: [
|
|
series: [
|
|
{
|
|
{
|
|
- // name: modelValue.value,
|
|
|
|
type: 'pie',
|
|
type: 'pie',
|
|
radius: ['20%', '45%'],
|
|
radius: ['20%', '45%'],
|
|
avoidLabelOverlap: false,
|
|
avoidLabelOverlap: false,
|