groupTime.vue
7 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
<template>
<view>
<headerComp
:leftImgSrc="leftImg"
:title="titleStr"
:rightImgSrc="rightImg"
@leftClick="backFun"
@rightClick="conditionFun"></headerComp>
<view class="prefix-elem"></view>
<view class="main-content">
<scroll-view
:scroll-y="true"
class="content-table">
<!-- 人脸性别统计详情 -->
<text class="table-title" v-show="genderColumns.length > 0">{{ genderTitle }}</text>
<v-table
v-if="genderColumns.length > 0"
is-horizontal-resize
style="width: 100%;"
:columns="genderColumns"
:table-data="genderTableData"
row-hover-color="#eee"
row-click-color="#edf7ff">
</v-table>
<!-- 人脸年龄统计详情 -->
<text class="table-title" v-show="ageColumns.length > 0">{{ ageTitle }}</text>
<v-table
v-if="ageColumns.length > 0"
is-horizontal-resize
style="width: 100%;"
:columns="ageColumns"
:table-data="ageTableData"
row-hover-color="#eee"
row-click-color="#edf7ff">
</v-table>
</scroll-view>
</view>
</view>
</template>
<script>
import headerComp from '../../../components/header.vue'
import leftImg from '../../../static/header/backArrow.png'
import rightImg from '../../../static/header/other.png'
import { mapState } from 'vuex'
export default {
components: {
headerComp,
},
data() {
return {
titleStr: '客流分时统计',
leftImg: leftImg,
rightImg: rightImg,
// 性别统计报表
genderTitle: '',
genderTableData: [],
genderColumns: [],
// 年龄统计报表
ageTitle: '',
ageTableData: [],
ageColumns: [],
accountId: null,
atoken: '',
chartIds: '',
reportLevel: '',
params: {}
}
},
onLoad(options) {
this.atoken = this.getStorage('atoken')
// this.getReportKey(options.analysisLevel)
console.log('onload', options)
this.reportLevel = options.analysisLevel || 'mall';
this.getReportKey(this.reportLevel)
},
created() {
this.accountId = this.getStorage('accountId');
if(!this.checkedMallId) {
this.$store.dispatch('malls/getMallList', {
data: {
accountId:this.accountId,
_t:Date.parse(new Date()) / 1000
},
header: {
'app-code':'mobile',
'Authorization': this.atoken //自定义请求头信息
},
isMultiple: true
})
this.$store.dispatch('malls/getDateData', 15)
}
},
computed: {
i18n() {
return this.$t("index")
},
...mapState({
mallList: state => state.malls.list,
checkedMallId: state => state.malls.checkedMallId,
multiCheckedMallId: state => state.malls.multiCheckedMallId,
timeData: state => state.malls.customTimeData,
selectedTime: state => state.malls.selectedDayTime
})
},
watch: {
checkedMallId(val) {
this.$store.dispatch('malls/getGateList', {
data: {
mallId: val.id,
status: 1,
isHasFace: 1,
_t:Date.parse(new Date()) / 1000
},
header: {
'app-code':'mobile',
'Authorization': this.atoken //自定义请求头信息
},
isMultiple: true
})
if(this.reportLevel !== 'mall') {
this.params['orgId'] = val.id;
this.getReportKey(this.reportLevel)
}
},
multiCheckedMallId(val) {
console.log('watch multiCheckedMallId', val)
if(this.reportLevel === 'mall') {
this.params['orgId'] = val.map(item => item.id).join(',');
this.getReportKey(this.reportLevel)
}
}
},
mounted() {
// console.log('store state', this.mallList, this.checkedMallId, this.multiCheckedMallId)
},
methods: {
backFun() {
uni.reLaunch({
url:"../passenger",
})
},
conditionFun() {
uni.navigateTo({
url: '../conditions/groupTimeOption'
})
},
getReportKey(analysisLevel) {
this.params.orgId = this.reportLevel !== 'mall'
? this.checkedMallId.id
: this.multiCheckedMallId.map(item => item.id).join(',');
if(!this.params.orgId) return;
let keyArr = ['faceGenderDetail', 'faceAgeDetail'];
uni.showLoading({
title: '加载中'
})
uni.request({
url: window.url + '/reportCharts',
data:{
report: 'faceCountAnalyzeSta',
_t: Date.parse(new Date())/1000
},
header: {
'app-code':'mobile',
'Authorization': this.atoken //自定义请求头信息
},
method:'GET',
success:(res) =>{
let result = res.data;
this.chartIds='';
res.data.data.forEach(item => {
if(keyArr.indexOf(item.key) != -1){
this.chartIds += item.id + ','
}
})
this.chartIds = this.chartIds.substring(0, this.chartIds.length - 1);
this.getChartData(analysisLevel);
}
})
},
getChartData(analysisLevel) {
this.genderTableData = this.genderColumns = [];
uni.request({
url: `${window.url}/report/faceCountAnalyzeSta/${analysisLevel}`,
data: {
orgIds: this.params.orgId,
startDate: `${this.selectedTime} 00:00:00`,
endDate: `${this.selectedTime} 23:59:59`,
chartIds: this.chartIds,
_t: Date.parse(new Date()) / 1000
},
header: {
'app-code':'mobile',
'Authorization': this.atoken
},
method: 'GET',
success: (res) => {
uni.hideLoading();
let result = res.data;
//
let bodyData = result.data.body;
let genderResource = result.data.body['faceGenderDetail'];
let columnsKey = this.createKeyObject(genderResource.xaxis.data);
this.genderTitle = genderResource.title;
this.genderColumns = this.createColumns(columnsKey);
this.genderTableData = this.createTableData(columnsKey, genderResource.series);
// 年龄分布
let ageResource = result.data.body['faceAgeDetail'];
let ageColumnsKey = this.createKeyObject(ageResource.xaxis.data);
this.ageTitle = ageResource.title;
this.ageColumns = this.createColumns(ageColumnsKey);
this.ageTableData = this.createTableData(ageColumnsKey, ageResource.series);
}
})
},
createKeyObject(arr) { // 数组转换为key value对象
return arr.map((item, index) => {
return {
key: 'tableKey' + index,
value: item
}
})
},
createColumns(keyObject) { // 生成列数据
return keyObject.map((item, index) => {
return {
field: item.key,
title: item.value,
width: 80,
titleAlign: 'center',
columnAlign: 'center',
isResize: true,
isFrozen: index == 0 ? true : false
}
})
},
createTableData(keyArr, originData) { // 生成表格数据
let result = [], temp = {};
originData.forEach((item, index) => {
if(item.data.length === keyArr.length) {
item.data.forEach((dataItem, dataIndex) => {
temp[keyArr[dataIndex].key] = dataItem || dataItem == 0 ? dataItem : '--';
})
result.push(temp);
temp = {};
}
})
return result;
},
},
}
</script>
<style>
.prefix-elem {
height: 18.11upx;
}
.table-title {
display: block;
background-color: #fff;
font-size: 28.98upx;
padding: 25.36upx 14.49upx;
box-sizing: border-box;
}
</style>