index.vue
4.84 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
<template>
<div class="canvas-image">
<canvas id="editXycanvas" class="xycanvas"></canvas>
<img :src="floorImage" class="editFloorimg" id="editFloorimg" />
</div>
</template>
<script>
export default {
data() {
return {
accountId: "",
mallId: '',
floorId: '',
floorImage: '',
floorPlanUrl: window._vionConfig.picUrl,
malls: [],
floors: [],
zones: [],
editZoneVal: []
}
},
mounted() {
this.getAccountList();
},
methods: {
init() {
let floorImage = new Image();
floorImage.src = this.floorImage;
floorImage.onload = () => {
let [width, height] = [0, 0];
let editFloorimg = document.getElementById('editFloorimg');
let _width = this.getStyleFn('.editFloorimg', 'width');
let _height = this.getStyleFn('.editFloorimg', 'height');
let _xy = this.getStyleFn('.canvas-image', 'width');
if (_width >= _xy) {
width = _xy
height = parseInt(_xy * _height / _width)
} else {
width = _width
height = _height
}
editFloorimg.style.width = width + 'px';
editFloorimg.style.height = height + 'px';
let coordinates = this.zones;
let canvas = document.getElementById('editXycanvas');
canvas.width = width;
canvas.height = height;
if(!canvas.getContext) return;
let ctx = canvas.getContext("2d");
coordinates.forEach(item => {
this.dealCoordinates(item, ctx, width, height)
})
}
},
dealCoordinates(item, ctx, width, height) {
let editZoneVal = []
const coor = JSON.parse(item.coordinates)
coor.forEach(item => {
editZoneVal.push([
(item[0] / this.normalWidth * width).toFixed(2),
(item[1] / this.normalWidth * height).toFixed(2)
])
})
ctx.moveTo(editZoneVal[0][0], editZoneVal[0][1])
for (let i = 1; i < editZoneVal.length; i++) {
ctx.lineTo(editZoneVal[i][0], editZoneVal[i][1])
}
ctx.closePath();
ctx.lineWidth = '2'
ctx.strokeStyle = 'blue'
ctx.stroke()
ctx.fillStyle = 'rgba(0, 0, 0, 0)'
ctx.fill()
},
getAccountList() {
this.accountId = this.$cookie.get("accountId");
this.getMallData();
},
// 查询门店列表
getMallData() {
this.tableData = [];
let tabelParams = {
accountId: this.accountId,
status: 1
};
this.$api.base.mall(tabelParams, null, true)
.then(data => {
this.malls = data.data.data;
this.mallId = data.data.data[0].id
this.floorFetch()
})
.catch(error => {});
},
// 获取楼层列表
floorFetch() {
this.floors = [];
this.floorValue = "";
this.$api.base.floor({
mallId: this.mallId,
status: 1
}).then(data => {
this.floors = data.data.data;
this.floorId = data.data.data[0].id;
this.floorImage = this.floorPlanUrl + data.data.data[0].floorPlan
this.zoneFetch()
}).catch(error => {})
},
// 获取区域列表
zoneFetch() {
const tabelParams = {
accountId: this.accountId,
mallId: this.mallId,
floorId: this.floorId,
status: 1,
type: 2
};
this.$api.base.zone(tabelParams, null, true)
.then(data => {
let result = data.data.data;
let zones = [];
if (result && result.length > 0) {
result.forEach(item => {
if (item.coordinates && item.coordinates !== '') {
zones.push(item)
}
})
}
this.zones = zones
this.init()
})
.catch(error => {});
}
}
}
</script>
<style scoped>
.canvas-image {
width: 100%;
height: 100%;
position: relative;
text-align: center;
position: relative;
overflow-x: hidden;
overflow-y: auto;
}
.xycanvas {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 0 auto;
}
</style>