index.vue
15.2 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
<template>
<div class="clerk-wrapper queueManagementContainer">
<div class="header manage-head-wrapper">
<el-form class="boxShadow searchFormSocial" ref="form" label-width="100px" inline>
<el-form-item :label="$t('table.mall')">
<el-select v-model="searchForm.mallId" filterable :placeholder="$t('pholder.select')" @change="mallChange">
<el-option v-for="item in mallListForTerm" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="$t('table.areaName')">
<el-select v-model="searchForm.cashierAreaId" :placeholder="$t('pholder.areaSelect')" @change="areaChange">
<el-option v-for="item in areaListData" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="$t('table.date')">
<el-date-picker type="date" :placeholder="$t('pholder.date')" v-model="searchForm.countDate"></el-date-picker>
</el-form-item>
<el-form-item>
<el-time-picker is-range v-model="searchForm.time" :range-separator="$t('dialog.to')" :start-placeholder="$t('pholder.startDate')" :end-placeholder="$t('pholder.endDate')" placeholder="选择时间范围"> </el-time-picker>
</el-form-item>
<!-- <el-form-item :label="$t('table.granularity')">
<el-select v-model="searchForm.granularity" :placeholder="$t('pholder.select')">
<el-option v-for="item in granularityListData" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item> -->
<el-form-item>
<el-button type="primary" class="search-btn" size="mini" plain @click="searchFun">{{$t('button.search')}}</el-button>
<el-button type="primary" class="search-btn" v-if="!playBtnShow" size="mini" plain @click="playFun">{{$t('button.play')}}</el-button>
<el-button type="primary" class="search-btn" v-if="playBtnShow" size="mini" plain @click="pauseFun">{{$t('button.pause')}}</el-button>
</el-form-item>
</el-form>
</div>
<div class="manage-content">
<div class="asis-table-content" v-loading="loading">
<canvas id='container' class="boxShadow"></canvas>
<div class="time-box1" v-show="progressShow">
<span style="float: left;">{{startTime}}</span>
<span style="color: #2774e9;">{{progressTime}}</span>
<span style="float: right;">{{endTime}}</span>
</div>
<div id="colorBox" v-show="progressShow"></div>
</div>
</div>
</div>
</template>
<script>
import moment from 'moment'
export default {
data() {
return {
startTime:'',
endTime:'',
mallListForTerm: [],
areaListData: [],
areaOneObj:{},
loading: false,
searchForm: {
mallId: '',
cashierAreaId: '',
countDate: new Date(),
time:[new Date(), new Date()],
granularity:5
},
canvas: null, //canvas实例
ctx: null, //ctx画笔
widthX: 0, //缩放比例X
heightX: 0, //缩放比例Y
dataList: [], //点位坐标
pic: null,
timeInterval:null,
progressShow:false,
progressTime:'',
playBtnShow:false,
colorBoxWidth:0,
channelNum:0,
granularityListData:[
{
value: 1,
label: '1min'
}, {
value: 2,
label: '2min'
}, {
value: 3,
label: '3min'
}, {
value: 5,
label: '5min'
}, {
value: 10,
label: '10min'
},{
value: 20,
label: '20min'
},{
value: 30,
label: '30min'
},
]
}
},
mounted() {
this.getMallListForTerm();
this.canvas = document.getElementById("container");
this.ctx = this.canvas.getContext("2d");
this.canvas.width = document.body.clientWidth - 248;
this.canvas.height = 400;
this.widthX = (1920 / this.canvas.width).toFixed(2);
this.heightX = (1080 / this.canvas.height).toFixed(2);
window.addEventListener("resize", () => {
this.setCanvasWidth();
});
this.loading = true;
},
computed: {
tableHeight() {
const windowInnerHeight = window.innerHeight;
return windowInnerHeight - windowInnerHeight * 0.24;
},
},
beforeDestroy() {
if (this.timeInterval) {
clearInterval(this.timeInterval);
}
},
methods: {
// 广场
getMallListForTerm() {
this.mallListForTerm = [];
this.searchForm.mallId = "";
this.$api.base.mall({
accountId: this.$cookie.get('accountId'),
status_arr: "1,3"
}).then(data => {
let result = data.data;
if (result.data.length) {
if (this.getSessionLocal("mallId")) {
this.searchForm.mallId = Number(this.getSessionLocal("mallId"));
} else {
this.searchForm.mallId = result.data[0].id;
this.setSessionLocal("mallId", this.searchForm.mallId);
}
this.getOpenTime()
this.mallListForTerm = result.data;
}
this.getAreaList(this.searchForm.mallId);
})
},
mallChange(val) {
this.setSessionLocal("mallId", val);
this.searchForm.cashierAreaId = ''
this.channelNum = 0
this.getAreaList(val)
this.getOpenTime()
},
// 获取门店开门关闭时间
getOpenTime(){
this.$api.base.getOpentimeList({mallId:this.searchForm.mallId}).then(res=>{
let result = res.data;
if(result.code==200){
let data = result.data.list[0]
let endTime = data.endTime
if(endTime.substring(10)=='00:00:00'){
endTime =endTime.substring(0,10)+ '23:59:59'
}
this.searchForm.time = [moment(data.startTime).format('YYYY-MM-DD HH:mm:ss'),moment(endTime).format('YYYY-MM-DD HH:mm:ss')]
}
})
},
// 区域
getAreaList(val) {
this.areaListData = [];
this.$api.queueManagementApi.getAreaList({
mallId: val,
pageNum: 1,
pageSize: 999999
}).then(res => {
let result = res.data;
if (result.code == 200) {
if (result.data.list && result.data.list.length > 0) {
this.searchForm.cashierAreaId = result.data.list[0].id
this.areaListData = result.data.list;
this.areaOneObj = result.data.list[0]
this.getChannelList()
this.pic = new Image();
this.pic.src =this.areaListData[0] && window._vionConfig.picUrl + this.areaListData[0].pic;
this.pic.onload = () => {
this.drawCirlce();
};
this.searchFun()
}
}
})
},
areaChange(val){
this.areaOneObj = this.areaListData.find(item=> item.id==val);
this.pic = new Image();
this.pic.src =this.areaOneObj && window._vionConfig.picUrl + this.areaOneObj.pic;
this.pic.onload = () => {
this.drawCirlce();
};
this.getChannelList()
this.searchFun()
},
// 通道
getChannelList() {
this.$api.queueManagementApi.getChannelList({
areaId: this.searchForm.cashierAreaId,
pageNum: 1,
pageSize: 999999
}).then(res => {
let result = res.data;
if (result.code == 200) {
this.channelNum=result.data.list.length
}
})
},
playFun(){
this.startTime = moment(this.searchForm.time[0]).format('HH:mm:ss')
this.endTime = moment(this.searchForm.time[1]).format('HH:mm:ss')
document.getElementById("colorBox").innerHTML='';
this.playBtnShow = true
this.progressShow = true;
let openT = new Date(this.searchForm.time[0]).getTime();
let closeT = new Date(this.searchForm.time[1]).getTime();
let num = (closeT-openT)/1000/60/this.searchForm.granularity;
this.colorBoxWidth = (this.canvas.width/(num+1)).toFixed(2);
this.colorBoxWidth = this.colorBoxWidth - 0.01
this.getDistribution(moment(openT).format('HH:mm:ss'))
this.timeInterval = setInterval(() => {
openT = openT + 1000 * 60 * this.searchForm.granularity
if(openT > closeT){
clearInterval(this.timeInterval);
return false
}else{
this.progressTime = moment(openT).format('HH:mm:ss')
this.getDistribution(moment(openT).format('HH:mm:ss'))
}
}, 1500);
},
pauseFun(){
this.playBtnShow = false
clearInterval(this.timeInterval);
},
pushBox(color){
var boxParent = document.getElementById("colorBox");
let boxChild = document.createElement("span");
boxChild.style.background = color;
boxChild.style.width = this.colorBoxWidth + 'px';
boxChild.style.height = "50px";
boxChild.style.display = "inline-block";
boxParent.appendChild(boxChild);
},
searchFun() {
clearInterval(this.timeInterval);
this.getDistribution()
},
// 获取主页大屏人员点位分布
async getDistribution(time) {
if(time){
this.searchForm.countDate = moment(this.searchForm.countDate).format('YYYY-MM-DD') +' '+time
}else{
this.searchForm.countDate = moment(this.searchForm.countDate).format('YYYY-MM-DD') +' '+moment(this.searchForm.time[0]).format('HH:mm:ss')
}
let parmas = {
cashierAreaId:this.searchForm.cashierAreaId,
countDate: this.searchForm.countDate,
}
let res = await this.$api.queueManagementApi.getdistribution(parmas);
let { code, data } = res.data;
if (code == 200) {
this.loading = false;
let red = data.red ? data.red : [];
let green = data.green ? data.green : [];
this.dataList = [
...red.map((item) => ({ ...item, status: 1 })),
...green.map((item) => ({ ...item, status: 0 })),
];
if(time){
let color = ''
if(red.length<=this.areaOneObj.safeNum*this.channelNum){
color = 'green'
}else if(red.length>this.areaOneObj.safeNum*this.channelNum && red.length<=this.areaOneObj.warnNum*this.channelNum){
color = 'yellow'
}else{
color = 'red'
}
this.pushBox(color)
}
this.drawCirlce();
}
},
//动态设置canvas的宽度
setCanvasWidth() {
if (this.fullscreen) {
this.canvas.width = document.body.clientWidth - 20;
this.canvas.height = 480;
} else {
this.canvas.width = document.body.clientWidth - 248;
this.canvas.height = 300;
}
this.widthX = (1920 / this.canvas.width).toFixed(2);
this.heightX = (1080 / this.canvas.height).toFixed(2);
this.drawCirlce();
},
// 画圆点
drawCirlce() {
if (!this.pic) return false;
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.ctx.drawImage(this.pic, 0, 0, this.canvas.width, this.canvas.height);
this.dataList.forEach((item) => {
if (item.status == 1) {
this.ctx.fillStyle = "red";
} else {
this.ctx.fillStyle = "green";
}
this.ctx.beginPath();
this.ctx.arc(
(item.x / 100) * this.canvas.width,
(item.y / 100) * this.canvas.height,
5,
0,
2 * Math.PI
);
this.ctx.fill();
});
},
}
}
</script>
<style scoped="scoped" lang="less">
/deep/.el-select{
width: 180px;
}
/deep/.el-date-editor{
width: 180px;
}
/deep/.el-date-editor--timerange.el-input__inner{
width: 220px;
}
/deep/.el-form-item__label{
height: 30px;
line-height: 30px !important;
}
/deep/.el-form-item__content{
height: 30px;
line-height: 30px;
}
/deep/.el-date-editor .el-range-separator{
line-height: 22px;
}
.time-box1{
width: 100%;
text-align: center;
margin-top: 5px;
height: 30px;
line-height: 30px;
}
#container{
margin-top: 10px;
margin-bottom: 10px;
}
#colorBox{
border: 1px solid #ccc;
margin-top: 10px;
height: 52px;
box-sizing: border-box;
}
</style>