jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
var deptMap;
var deptList;
var deptParent;
var deptParentId;
var map = new BMapGL.Map("container");
var timer;
var layer;
var showDeptFlag = true;
$(function () {
    layui.use(['layer', 'laydate', 'form'], function () {
        layer = layui.layer;
        //旋转动画
       // rotate();
    });
});
 
 
//页面初始化后,查看是否有初始化仓库编码
window.onload = function () {
    //初次定位到库区位置
    if (dept) {
        deptParent = dept;
        //setTimeout('firstSetCenter()', 5000);
        firstSetCenter();
    }
};
 
 
//定位库区位置
function firstSetCenter() {
    map.enableScrollWheelZoom(true);
    //适应地图大小,设置地图中心点坐标及地图级别
    map.centerAndZoom(new BMapGL.Point(dept.lon, dept.lat), 10);
    
    setTimeout(function () {
        map.setMapType(BMAP_NORMAL_MAP);
        map.setMapStyleV2({
           styleId: '2d7e9be25edbcb299c48ff8d14119eef'
        });
        $("#topdiv").css("display", "block");
        currentSetCenter();
        if (dept.type == "10") {
            deptParentId = dept.id;
            showChildDept();
            getDeptChild()
        }
    }, 1000);
}
 
/**
 * 将当前部门设为中心
 */
function currentSetCenter() {
    map.centerAndZoom(new BMapGL.Point(deptParent.lon, deptParent.lat), 15);
}
 
/**
 * 显示部门列表
 */
function showChildDept() {
    if (showDeptFlag) {
        $("#rightdiv").addClass("show");
        showDeptFlag = false;
    } else {
        $("#rightdiv").removeClass("show");
        showDeptFlag = true;
    }
}
 
 
/**
 * 渲染列表
 * @param data
 */
function renderDept() {
    //先清除之前的标记点
    map.clearOverlays();
    deptList = deptParent.children;
    // console.log(deptList);
    if (deptList) {
        deptMap = {};
        //右侧列表html
        var html = "";
        var myIcon;
        var pt;
        var pts = [];
        var marker;
        //把自己加进去一块标记出来
        for(var i = 0; i < deptList.length; i ++){
            !function(i){
                var data1 = deptList[i];
                if (data1.type == "10" || data1.type == "20") {
                    html += " <li onclick=\"setCenter(\'" + data1.id + "\');\">\n";
                    if (data1.type == "10") {
                        html += " <img src=\"../../static/images/gongsi.png\" >\n";
                    } else {
                        html += " <img src=\"../../static/images/cangku.png\" >\n";
                    }
                    html += " <div>\n" +
                        "             <h4>" + (data1.name ? data1.name : "") + "</h4>\n" + (data1.address ? data1.address : "") + "</div>\n";
                    html += "     </li>";
                }
            }(i);
        }
 
        //创建标记点
        deptList.push(deptParent);
        for(var i = 0; i < deptList.length; i ++){
            !function(i){
                var data2 = deptList[i];
                if (data2.type == "10" || data2.type == "20") {
                    deptMap[data2.id] = data2;
                    if (data2.type == "10") {
                        myIcon = new BMapGL.Icon("../../static/images/zuobiao_blue.png", new BMapGL.Size(70, 70));
                    } else {
                        myIcon = new BMapGL.Icon("../../static/images/zuobiao_yellow.png", new BMapGL.Size(70, 70));
                    }
                    // 创建Marker标注,
                    pt = new BMapGL.Point(data2.lon, data2.lat);
                    pts.push(pt);
                    marker = new BMapGL.Marker(pt, {
                        icon: myIcon
                    });
                    // 将标注添加到地图
                    map.addOverlay(marker);
                    marker.addEventListener('click', function () {
                        openInfo(this, data2.id);
                    });
                }
            }(i);
        }
 
        $("#deptUl").html(html);
        //将所有的点显示出来
        var view = map.getViewport(eval(pts));
        var mapZoom = view.zoom;
        var centerPoint = view.center;
        map.centerAndZoom(centerPoint, mapZoom);
    } else {
        layer.msg("没有下属部门信息!");
    }
}
 
//点位点击事件
function openInfo(marker, deptId) {
    var d = deptMap[deptId];
    if (d) {
        var sContent = "";
        sContent += "<div style=\"margin:0;line-height:20px;padding:2px;\">联系人:" + (d.contact ? d.contact : "") + "<br/>联系电话:" + (d.phone ? d.phone : "") + "<br/>";
        // sContent += "详细地址:" + (d.address?d.address:"") ;
        // sContent +="<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>" ;
        // sContent += d.desc ? d.desc:"";
        // sContent += "</p>" ;
        if (d.type == "20") {
            sContent += "<button class=\"layui-btn layui-btn-primary layui-border-black\" onclick=\"openHome(\'" + d.id + "\');\">打开首页</button>"
        }
 
        sContent += "</div>";
 
        var infoWindow = new BMapGL.InfoWindow(sContent, {
            title: d.name,      //标题
            width: 200,             //宽度
            height: 120             //高度
 
        });
        marker.openInfoWindow(infoWindow);
    } else {
        console.log("没有从map中获取到部门")
    }
 
}
 
/**
 * 打开首页事件
 */
function openHome(deptId) {
    //首先主动更换当前人临时部门
    layer.msg("开始验证部门……");
 
    $.ajax({
        type: "GET",
        cache: false,
        url: "../../basic/common/change-deptId?deptId=" + deptId + "&userId=" + userId,
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            if(model == "all"){
                window.open("../../index?g=1", "_parent");
            }else {
                window.open("../../home?t=" + model + "&g=1", "_parent");
            }
        },
        error: function (result) {
            if("SUCCESS" == result.responseText){
                if(model == "all"){
                    window.open("../../index?g=1", "_parent");
                }else {
                    window.open("../../home?t=" + model + "&g=1", "_parent");
                }
            }else{
                layer.alert("系统验证当前用户所在部门异常,请联系管理员!");
            }
        }
    });
}
 
/**
 * 渲染按钮
 * @param data
 */
function renderBtnBack() {
    //console.log(deptParent);
    var html = "";
    if (deptParent.id == dept.id) {
        html += "  <img src=\"../../static/images/fanhui.png\" style=\"width: 24px !important;padding-top: 10px !important;transform: rotateY(180deg)\">\n" +
            "<div> <h4 onclick='currentSetCenter();'>当前下属分支</h4> </div>\n";
    } else {
        html += " <img src=\"../../static/images/fanhui.png\" style=\"width: 24px !important;padding-top: 10px !important;\">\n" +
            " <div> <h4 onclick='backParent();'>返回上级</h4> </div>";
    }
    $("#btBack").html(html)
}
 
/**
 * 返回上层
 */
function backParent() {
    var nowTime = new Date().getTime();
    var clickTime = $(this).attr("ctime");
    if (clickTime != 'undefined' && (nowTime - clickTime < 3000)) {
        alert('操作过于频繁,稍后再试');
        return false;
    } else {
        $(this).attr("ctime", nowTime);
        getDeptparent();
    }
}
 
/**
 * 仓库点击事件
 * @param deptId
 */
function setCenter(deptId) {
   // console.log(deptId);
 
   // console.log(deptMap);
 
    var d = deptMap[deptId];
    console.log(d);
    if (d) {
        if (d.type == 10) {
            //是公司还需要加载子部门数据并且渲染
            deptParentId = d.id;
            getDeptChild();
        } else {
            map.centerAndZoom(new BMapGL.Point(d.lon, d.lat), 15);
        }
    } else {
        console.log("没有从map中获取到部门")
    }
}
 
/**
 * 获取数据
 */
function getDeptChild() {
    $.ajax({
        type: "POST",
        url: "../../basic/gis/dept-child",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({
            "deptId": deptParentId
        }),
        success: function (result) {
            console.log(result);
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                deptParent = result.data;
                deptParentId = result.data.id;
                renderBtnBack();
                renderDept();
                //currentSetCenter();
            }
        },
        error: function () {
            layer.msg("获取信息失败!");
        }
    });
}
 
/**
 * 获取数据
 */
function getDeptparent() {
 
    $.ajax({
        type: "POST",
        url: "../../basic/gis/back-parent",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({
            "deptId": deptParentId
        }),
        success: function (result) {
            console.log(result);
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                deptParent = result.data;
                deptParentId = result.data.id;
                renderBtnBack();
                renderDept();
                //currentSetCenter();
            }
        },
        error: function () {
            layer.msg("获取信息失败!");
        }
    });
}
 
 
/**
 * 初始动画
 */
function rotate() {
    //开启鼠标滚轮缩放
    map.enableScrollWheelZoom(true);
 
    //开启地球模式
    map.setMapType(BMAP_EARTH_MAP);
 
    // 初始化地图,设置动画起始点坐标和地图级别
    map.centerAndZoom(new BMapGL.Point(214.406, 40.000), 5);
 
    //旋转动画开始
    setTimeout(function () {
        map.panTo(new BMapGL.Point(204.406, 40.000));
    }, 2000);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(194.406, 40.000)); //旋转动画
    }, 2250);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(184.406, 40.000)); //旋转动画
    }, 2500);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(174.406, 40.000)); //旋转动画
    }, 2775);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(164.406, 40.000)); //旋转动画
    }, 3000);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(154.406, 40.000)); //旋转动画
    }, 3250);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(144.406, 40.000)); //旋转动画
    }, 3500);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(134.406, 40.000)); //旋转动画
    }, 3750);
    setTimeout(function () {
        map.panTo(new BMapGL.Point(124.406, 40.000)); //旋转动画
    }, 4000);
    //旋转动画结束
    setTimeout(function () {
        map.panTo(new BMapGL.Point(114.403, 40.000));
    }, 4250);
}
 
//格式化时间
function dateFormatStr(time) {
    if (time) {
        var d = new Date(time);
        return dateFtt("yyyy-MM-dd hh:mm:ss", d);
    }
    return "";
}