content.vue
8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<template>
<div class="daily">
<!-- 小时分钟合并 -->
<div class="asis-table-wrapper">
<h3 class="asis-table-header single-report-header tf-table-header">
<span
v-if="isDTabChart"
class="asis-table-download"
@click="downloadData(i18nFormatter(trafficFlow_title) + '-' + Time(),'custom')"
>{{$t('allPages.load')}}</span>
<span
v-else
style="color: #ccc;"
class="asis-table-download"
:disabled="!isDTabChart"
>{{$t('allPages.load')}}</span>
<span class="report-type-box">
<span :class="barLineIcon" @click="selReport('bar')"></span>
<span
:class="isDTabChart ? 'report-item report-item-tab' : 'report-item'"
@click="selReport('table')"
></span>
</span>
</h3>
<div class="asis-table-content" v-loading="loading">
<el-row v-if="!isDTabChart">
<mix-charts
chart-id="domAgeChart"
class="age-wrapper"
:chart-data="chartData"
chart-type="Line"
/>
</el-row>
<el-row v-else>
<el-table
id="domBaseTrafficFlow"
:data="tabOps"
:max-height="tableHeight"
style="width: 100%"
class="asis-table baseasis-table"
header-row-class-name="asis-table-head"
row-class-name="manage-row"
>
<el-table-column
:prop="item.prop"
:label="item.label"
align="center"
v-for="(item,index) in tabHeadData"
:key="index"
min-width="100"
>
</el-table-column>
</el-table>
</el-row>
<p style="width: 100%;text-align: center;color: red;">注:受数据隐私保护要求,竞品客流分析不提供客流量绝对值,仅提供商场同期内客流走势和相对高低,即客流指数</p>
</div>
</div>
<export-data-dialog ref="exportDialog"></export-data-dialog>
</div>
</template>
<script>
import exportData from "../../public/exportData";
import { columnComputed, rowComputed, curryAvgAndSum, combineHeadAndBody } from '@/utils'
export default {
props: {
propparam: {
type: Object,
default: () => {}
}
},
components: {
"export-data-dialog": exportData,
},
data() {
return {
loading: false,
trafficFlow_title: "competitivePassengerFlowData", //报表
emitData: {},
isDTabChart: false,
chartData: {}, // 图数据
tabHeadData: [],
tabOps: []
};
},
computed: {
barLineIcon() {
if (this.isDTabChart) {
return "report-item line-report";
} else {
return "report-item line-report report-item-line";
}
},
tableHeight() {
let windowHeight = window.innerHeight,
scale = 0.34
scale = windowHeight <= 720
? 0.4
: windowHeight <= 768
? 0.38
: windowHeight <= 900
? 0.36
: windowHeight <= 1080
? 0.34
: 0.34
return windowHeight - windowHeight * scale
}
},
watch: {
propparam: {
handler: "refreshHandle",
// immediate: true,
deep:true
},
emitData: {
handler(){
},
immediate: true,
deep:true
}
},
created() {
},
mounted() {
},
methods: {
refreshHandle(param) {
if(param){
this.emitData = param
this.getData();
}
},
// 获取表格数据
getTableData(resData) {
let originData = JSON.parse(JSON.stringify(resData.series))
let flowHeadData = JSON.parse(JSON.stringify(resData.xaxis && resData.xaxis.data || []));
this.tabHeadData = flowHeadData.reduce((arr, curr, index) => {
arr.push({
prop: `defaultOrg${index}`,
label: curr
})
return arr
}, [])
const tbodyData = originData.reduce((arr, curr) => {
arr.push(curr.data)
return arr
}, [])
this.tabOps = combineHeadAndBody(this.tabHeadData, tbodyData)
},
getData() {
this.tabHeadData = [];
this.chartData = {};
this.tabOps = [];
this.loading = true;
let param = {
mallId: this.emitData.orgId,
startDate: this.emitData.startDate,
endDate: this.emitData.endDate,
type: this.isDTabChart?"table":'line',
}
this.$api.businessAnalysisApi.getPassengerFlow(param).then(res => {
let resData = res.data.data;
this.loading = false;
if (this.isDTabChart) { // 表格
this.getTableData(resData)
} else { // 图
if(resData.series&&resData.series.length>0){
resData.otherConf = {
singleUnit:'%',
yAxisName:'%'
}
}
this.chartData = resData;
}
})
.catch(err => {
this.catchErrorHandle(err);
setTimeout(() => {
this.loading = false;
}, 500);
});
},
// 新增表格回调
/**
* 表头格式化
* @param {array} originHeadData
* @param {string} addColumn { 'avg' | 'sum' | 'avgAndTotal' }
*/
dealTheadData(originHeadData, addColumn) {
if (originHeadData.length === 0) return originHeadData
let copyHeadData = originHeadData.slice(0),
resultHeadData = []
if (addColumn === 'avg') {
copyHeadData.push(this.$t('table.average'))
} else if (addColumn === 'sum') {
copyHeadData.push(this.$t('table.total'))
} else if (addColumn === 'avgAndTotal') {
copyHeadData.push(this.$t('table.average'))
copyHeadData.push(this.$t('table.total'))
}
return copyHeadData.reduce((arr, curr, index) => {
arr.push({
prop: `defaultOrg${index}`,
label: curr
})
return arr
}, [])
},
/**
* 处理表格数据
* @param {array} data
* @param {string} addPlace { 'index' | 'column' | 'row' | 'both' }
* @param {string} addOption { 'avg' | 'sum' | 'avgAndTotal' }
* @param {number} startPostion
* @returns {array} result
*/
dealTableData(data, addPlace, addOption, startPosition = 0) {
if (!addPlace) return data
let result = []
if (addPlace === 'column') {
result = columnComputed({data, addOption, startPosition})
} else if (addPlace === 'row') {
result = rowComputed({data, addOption, startPosition})
} else {
let addColAndRow = curryAvgAndSum(columnComputed, rowComputed)
result = addColAndRow({data, addOption, startPosition})
}
return result
},
indexFormatter({ $index, row }) {
const { createRow, tabOps } = this
const realDataLen = createRow === 'avgAndTotal'
? tabOps.length - 2
: tabOps.length
if ($index < realDataLen) {
return $index + 1
} else {
return ((realDataLen - $index) === 0) ? this.$t('table.average') : this.$t('table.total')
}
},
selReport(iconType) {
if (iconType === "line" || iconType === "bar") {
if (this.isDTabChart) {
this.isDTabChart = false;
this.getData();
}
} else {
if (!this.isDTabChart) {
this.isDTabChart = true;
this.getData();
}
}
},
downloadData(title, chartKey) {
if (this.isDTabChart) {
this.dealExport("domBaseTrafficFlow", title);
} else {
this.exportDataHandle(title, chartKey);
}
},
exportDataHandle(title, chartKey) {
let exportNeed = {
domId: "bdlineChart",
title: title,
data: {
url: `/report/basics/day/${this.emitData.asis_level}/${this.tableKeyToId[chartKey]}/excel`,
params: `orgIds=${this.emitData.asis_org}&date=${
this.emitData.asis_time
}&option=${this.isDTabChart ? "TAB_TABLE" : "TAB_CHART"}`
}
};
this.$refs.exportDialog.dialogInit(exportNeed);
}
}
};
</script>
<style scoped>
.asis-table-wrapper {
position: relative;
}
.bar-report {
background: url("~@/assets/img/asis/bar_icon.svg") no-repeat;
background-size: 100% 100%;
}
.report-item-bar {
background: url("~@/assets/img/asis/active_bar_icon.svg") no-repeat;
background-size: 100% 100%;
}
</style>