timec.vue
14.4 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<template>
<div class="base-analysis">
<el-header height="70px">
<span class="asis-title">{{ asisName }} {{$t('asis.Timecomp')}}</span>
<span class="more-option-wrapper" @click="showCollapse">
<span class="more-option-text">{{$t('asis.moreOp')}}</span>
<i :class="['el-icon-arrow-down', 'more-option-arrow', { 'more-option-up': !moreOptVisible }]"></i>
</span>
</el-header>
<tc-option v-show="moreOptVisible" ref="init" @reportTime="reportHandler" @initData="initTab"></tc-option>
<div class="element-main tc-main">
<!-- 总客流 | 天级对比 -->
<div class="asis-table-wrapper">
<h3 class="asis-table-header single-report-header tf-table-header">
<!-- <span class="asis-table-download" @click="dealExport('domTrafficFlow', i18nFormatter(tc_title))">{{ $t('allPages.load') }}</span> -->
<span class="asis-table-download" @click="exportDataHandle('pieLineChart', i18nFormatter(tc_title))">{{ $t('allPages.load') }}</span>
</h3>
<div class="date-radio-wrapper tf-ratio-group single-ratio-group">
<el-radio-group v-model="radioDate" size="mini" fill="#0069FF" @change="changeTabSelect(radioDate)">
<el-radio-button label="totalTraffic" border>{{ $t('button.totalTraffic') }}</el-radio-button>
<template v-if="isOneDay">
<el-radio-button label="trafficMin" border>{{ $t('button.min') }}</el-radio-button>
<el-radio-button label="trafficHour" border>{{ $t('button.hour') }}</el-radio-button>
</template>
<template v-else>
<el-radio-button label="dayTraffic" border>{{ $t('button.dayTraffic') }}</el-radio-button>
</template>
</el-radio-group>
</div>
<div class="asis-table-content" v-loading="loading">
<mix-charts v-if="radioDate !== 'totalTraffic'" chartId="pieLineChart" :chartData="pieChartData" chartType="AreaLine" />
<el-table
class="asis-table"
id="domTrafficFlow"
:data="trafficTab"
:border="false"
header-row-class-name="asis-table-head"
style="width: 100%"
:max-height="tableHeight">
<el-table-column type="index" align="center" :label="$t('table.order')" width="100" v-if="trafficHead.length > 0">
</el-table-column>
<public-column v-for="(item, index) in trafficHead" :key="index" :col="item" />
<!-- <el-table-column :prop="item.prop" :label="item.label" align="center" v-for="item in trafficHead" :key="item.prop"> -->
</el-table-column>
</el-table>
<mix-charts v-if="radioDate === 'totalTraffic'" chartId="pieLineChart" :chartData="pieChartData" chartType="Ring" />
<!-- <div id="pieLineChart"></div> -->
</div>
</div>
</div>
<export-data-dialog ref="exportDialog" @downloadChange="downloadChange"></export-data-dialog>
</div>
</template>
<script>
import publicChart from '../common/publicChart'
import tcOption from '../common/option/timeCompMoreOption'
import PublicColumn from '@/views/public/myColum'
export default {
data() {
return {
tc_title: 'timeComp',
moreOptVisible: false,
asisName: '',
emitData: {},
tableKeyToId: {},
tableIds: '',
radioDate: 'dayTraffic',
loading: true,
trafficHead: [],
trafficTab: [],
tableHeight: 0,
pieChartData: {},
isOneDay: false,
radioKey: [],
downloadData: {}
}
},
components: {
'tc-option': tcOption,
PublicColumn
},
created() {
let winH = $(window).height(), scale = 0.28;
if (winH <= 720) {
scale = 0.35
} else if (winH <= 768) {
scale = 0.33
} else if (winH <= 900) {
scale = 0.28
} else if (winH <= 1080) {
scale = 0.31
}
this.tableHeight = winH - winH * scale
},
mounted() {
this.getMallOpt();
this.showCollapse()
},
methods: {
i18nFormatter(label) {
let languageLabel = 'echartsTitle.' + label;
return this.$t(languageLabel)
},
i18n(value) {
let name = 'format.' + value;
return this.$t(name)
},
showCollapse() {
// 获取上面元素的高度
let headerH = '', titleH = '', collapseH = '', mt = ''
headerH = this.getStyleFn('.el-header', 'height')
titleH = this.getStyleFn('.analysis-wrapper .el-header', 'height')
if (this.moreOptVisible) {
this.moreOptVisible = false
mt = headerH + titleH + 8 + 'px'
$('.tc-main').animate({ marginTop: mt })
} else {
this.moreOptVisible = true
setTimeout(() => {
collapseH = this.getStyleFn('.analysis-option-wrapper', 'height')
mt = headerH + titleH + collapseH + 8 + 'px'
$('.tc-main').animate({ marginTop: mt })
}, 100)
}
},
getMallOpt() {
this.getCommonMalls()
.then(resolveData => {
let { mallData, localMallId, titleName, multiMallId } = resolveData
this.asisName = titleName
this.$refs.init.initAsis(localMallId, mallData)
}, (rejectData) => {
})
},
initTab(data) {
this.emitData = data
const { asis_time } = data
// 判断是否是同一天的时间段
this.isOneDay = this.handlerSameDay(asis_time)
this.radioDate = this.isOneDay ? 'trafficMin' : 'dayTraffic'
this.getChartIds()
},
getChartIds() {
this.tableKeyToId = {}
this.tableIds = ''
const chartKeyList = [
'totalPassengerCompare',
'totalAndAverageTraffic',
'dayCompareTable',
'dayCompareLine',
'hourCompareLine',
'hourCompareTable',
'minuteCompareLine',
'minuteCompareTable'
]
// const chartKeys = []
this.$api.baseReport.reportChart({
report: 'timeCompareAnalysis'
})
.then(res => {
const { data } = res.data
data.forEach((item, index) => {
this.tableKeyToId[item.key] = item.id
// if (chartKeyList.includes(item.key)) {
// chartKeys.push(item.id)
// }
})
this.tableIds = this.matchKeyId(this.radioDate)
this.getTableData()
})
.catch(err => {
this.catchErrorHandle(err)
})
},
fetchChartData() {
const { emitData, tableIds } = this
const { asis_org, asis_time, asis_kpi } = emitData
const [date1, date2] = asis_time
const param = {
orgIds: asis_org,
startDate: date2[0],
endDate: date2[1],
startDate1: date1[0],
endDate1: date1[1],
kpiType: asis_kpi,
chartIds: tableIds
}
const { params, asisLevel } = this.dealFormat(param, emitData)
return new Promise(resolve => {
this.$api.analysisReport.timeCompareAnalysis(asisLevel, params)
.then(res => {
resolve(res)
})
.catch(err => {
this.catchErrorHandle(err)
})
})
},
async getTableData() {
this.trafficHead = []
this.trafficTab = []
this.pieChartData = {}
try {
const { data } = await this.fetchChartData()
const { body } = data.data
const {
totalPassengerCompare = {},
totalAndAverageTraffic = {},
dayCompareTable = {},
dayCompareLine = {},
hourCompareTable = {},
hourCompareLine = {},
minuteCompareTable = {},
minuteCompareLine = {}
} = body
const [_tableKey, _chartKey] = this.radioKey
if (body[_tableKey] && body[_chartKey]) {
this.matchChart(body[_tableKey], body[_chartKey])
} else {
console.warn(`The ${_tableKey} and ${_chartKey} reports has no data!!`)
this.$message.warning(`The ${_tableKey} and ${_chartKey} reports has no data!!`)
}
this.loading = false
} catch(err) {
this.catchErrorHandle(err)
}
},
matchChart() {
try {
// table
this.trafficHead = this.createHeadColumn(arguments[0].xaxis.data)
this.trafficTab = this.buildTableContent(this.trafficHead, arguments[0].series)
// 创建 download data
// this.downloadData = {
// multiHeader: [],
// header: []
// }
// this.downloadData.data = arguments[0].series.map(item => item.data)
// const multiHeader = []
// this.trafficHead.forEach((item, index) => {
// multiHeader.push(item.label)
// multiHeader.push('')
// multiHeader.push('')
// if (item.children) {
// item.children.forEach(item => {
// this.downloadData.header.push(item.label)
// })
// }
// })
// this.downloadData.multiHeader.push(multiHeader)
// this.downloadData.merges = ['A1:C1', 'D1:F1']
// console.log(this.downloadData)
// chart
console.log(this.radioDate, this.emitData.asis_kpi)
arguments[1].otherConf = this.radioDate === 'totalTraffic'
? {
_color: ['#3BB8FF', '#FFC62E'],
seriesText: 'traffic',
legendBottom: 16
}
: {
_color: ['#3BB8FF', '#FFC62E'], //['#87D14B', '#3BB8FF'],
seriesText: this.emitData.asis_kpi === 'TRAFFIC' ? 'traffic' : 'personNum',
legendShow: false,
hasYaxisName: false,
grid: { top: 16, right: 26, bottom: 60, left: 52 },
periodTime: this.radioDate === 'trafficMin',
nextTimeNum: this.radioDate === 'trafficMin' ? 10 : 0
}
this.pieChartData = arguments[1]
} catch(err) {
console.error(err)
}
},
createHeadColumn(headColumnData) {
let headColumn = []
if (headColumnData.length) {
let i = 0
headColumn = headColumnData.map((item) => {
if (/\[.+\]/g.test(item)) {
// 解析
let evalItem = JSON.parse(item.replace(/\'/g, '"'))
return {
label: evalItem[0],
children: evalItem.map((childItem, childIndex) => {
if (childIndex > 0) {
return {
prop: `defaultOrg${i++}`, label: childItem
}
} else {
return false
}
}).filter(Boolean)
}
} else {
return {
prop: `defaultOrg${i++}`,
label: item
}
}
})
}
return headColumn
},
buildTableContent(headData, data) {
let result = [], temp = {}
if (headData.length) {
data.forEach((item, index) => {
temp = {}
item.data.forEach((dataItem, dataIndex) => {
temp[`defaultOrg${dataIndex}`] = (
(typeof(dataItem) === 'number'
|| typeof(dataItem) === 'string')
&& dataItem !== 'null'
) ? dataItem : '--'
})
result.push(temp)
})
}
return result
},
reportHandler(emitData) {
const { asis_time } = emitData
// 判断是否是同一天的时间段
this.isOneDay = this.handlerSameDay(asis_time)
this.radioDate = this.isOneDay ? 'trafficMin' : 'dayTraffic'
this.emitData = emitData;
this.asisName = emitData.asis_tit
if (Object.keys(this.tableKeyToId).length) {
this.tableIds = this.matchKeyId(this.radioDate)
this.getTableData()
} else {
this.getChartIds()
}
},
matchKeyId(keys) {
const { tableKeyToId } = this
const rules = {
'totalTraffic': () => {
this.radioKey = ['totalPassengerCompare', 'totalAndAverageTraffic']
return tableKeyToId['totalPassengerCompare'] + ',' + tableKeyToId['totalAndAverageTraffic']
},
'dayTraffic': () => {
this.radioKey = ['dayCompareTable', 'dayCompareLine']
return tableKeyToId['dayCompareTable'] + ',' + tableKeyToId['dayCompareLine']
},
'trafficHour': () => {
this.radioKey = ['hourCompareTable', 'hourCompareLine']
return tableKeyToId['hourCompareTable'] + ',' + tableKeyToId['hourCompareLine']
},
'trafficMin': () => {
this.radioKey = ['minuteCompareTable', 'minuteCompareLine']
return tableKeyToId['minuteCompareTable'] + ',' + tableKeyToId['minuteCompareLine']
}
}
return rules[keys]()
},
changeTabSelect(keys) {
this.loading = true
this.tableIds = this.matchKeyId(keys)
this.getTableData()
},
handlerSameDay(times) {
if (times instanceof Array && times.length > 0) {
const [date1, date2] = times
try {
if (date1[0] === date1[1] && date2[0] === date2[1]) {
return true
}
return false
} catch(err) {
console.error(err)
}
}
},
exportDataHandle(domId, title) {
const { emitData, tableIds, radioDate } = this
const { asis_org, asis_time, asis_kpi } = emitData
const chartId = this.tableKeyToId[radioDate === 'totalTraffic' ? 'totalPassengerCompare' : 'dayCompareTable']
const exportNeed = {
domId: domId,
title: title,
data: {
url: `/report/timeCompareAnalysis/${this.emitData.asis_level}/${chartId}/excel`,
params: `orgIds=${asis_org}&startDate=${asis_time[1][0]}&endDate=${asis_time[1][1]}&startDate1=${asis_time[0][0]}&endDate1=${asis_time[0][1]}&kpiType=${asis_kpi}`
}
}
this.$refs.exportDialog.dialogInit(exportNeed, true);
},
downloadChange(type) {
if (type === 'Excel') {
const { i18nFormatter, tc_title } = this
this.dealExport('domTrafficFlow', i18nFormatter(tc_title))
// const { multiHeader, header, data, merges } = downloadData
// if (!header && !data) return
// console.log('header', header)
// console.log('data', data)
// import('@/utils/Export2Excel').then(excel => {
// excel.export_json_to_excel({
// multiHeader,
// header,
// data,
// merges,
// filename: this.i18nFormatter(tc_title),
// // autoWidth: true,
// bookType: 'xlsx'
// })
// })
}
},
}
}
</script>
<style scoped>
#pieLineChart {
height: 450px;
}
</style>