drawFloor.vue
4.93 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
<template>
<el-dialog
title="绘制楼层店铺"
width="80%"
class="manage-dialog draw-dialog"
:visible.sync="drawDialogVisible"
:close-on-click-modal="false"
@close="drawDialogClose">
<div class="dheader">
<div class="action">
<el-upload class="upload"
action=""
:show-file-list="false"
:auto-upload="false"
:on-change="handlePreview"
>
<el-button size="mini">点击上传</el-button>
</el-upload>
<el-button size="mini" type="danger" @click="clearPainter">清空画布</el-button>
<!-- <input @change="imgChoose" class="none" type="file" accept="image/*"> -->
</div>
<div class="btns">
<el-button size="mini" type="primary" @click="saveData">保存楼层图</el-button>
</div>
</div>
<div class="dView">
<div class="dWrap" ref="dWrap">
<img :src="uploadImgUrl" class="fimg" @load="resizePainter">
<!-- 绘制区域 S -->
<Painter ref="painter" @zoneClick="zoneClick" @zoneRight="zoneRight" @zoneMove="zoneMove" :isEdit="true"></Painter>
<!-- 绘制区域 E -->
</div>
</div>
<!-- <div slot="footer" class="dialog-footer">
<el-button @click="drawDialogVisible = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
<el-button type="primary" @click="drawSubmit" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
</div> -->
</el-dialog>
</template>
<script>
import Painter from '@/components/Floormap/index';
export default {
components:{
Painter
},
data() {
return {
drawDialogVisible: false,
uploadImgUrl:'',
mallList: [],
isIe: null,
floorId:'',
}
},
mounted() {
this.$nextTick(()=>{
// this.dialogInit();
})
},
methods: {
zoneClick(data){
console.info('zoneClick',data)
},
zoneRight(data){
console.info('zoneRight',data)
},
zoneMove(data){
console.info('zoneMove',data)
},
handlePreview(file){
this.uploadImgUrl = URL.createObjectURL(file.raw);
},
resizePainter(){
let client = this.$refs.dWrap.getBoundingClientRect();
this.$refs.painter.resizePainter(client);
},
dialogInit(data) {
/*******************************************************/
this.floorId = data.id;
this.drawDialogVisible = true;
this.$api.management.getFloorCanvas(this.floorId).then(res=>{
//this.$nextTick(()=>{
let floorData = {};
if(res.data&&res.data.data&&res.data.data.svg){
let fdata = JSON.parse(res.data.data.svg);
if(fdata&&fdata.list&&fdata.list.length){
floorData = fdata;
}
}
floorData.floorId = this.floorId;
this.$refs.painter.setPainter(floorData);
this.uploadImgUrl = data.floorPlan?window._vionConfig.picUrl+data.floorPlan:'';
this.timer = setInterval(()=>{
if(this.$refs.painter){
this.$refs.painter.saveLocal();
}else{
clearInterval(this.timer);
}
},3000);
//})
})
},
clearPainter(){
this.$refs.painter.clearPainter();
},
saveData() {
let that = this,floorData = this.$refs.painter.getPainterData();
if(!floorData.list||floorData.list.length==0){
// return that.$message({
// showClose: true,
// type: "error",
// message: '请绘制店铺图再保存'
// });
}
this.$api.management.saveFloorCanvas({
floorId:floorData.floorId,
svg:JSON.stringify(floorData)
}).then(res=>{
that.$message({
showClose: true,
type: "success",
message: res.data.msg,
onClose(){
that.drawDialogVisible = false;
}
});
})
},
drawDialogClose() {
clearInterval(this.timer);
localStorage.removeItem('floorcanvas'+this.floorId);
}
}
}
</script>
<style scoped>
.header{
background: #000;
}
</style>