<div>       
    <div class='bdmapscript'></div>
    <div id='bdmap-bugsell' style='height:650px;width:100%;'></div>
</div>

 

<script type='text/javascript'>
        
		function Sms(record_id,t){
            var data={
                    record_id:record_id,                    
                    ancestor_id:'{{request.user.company.ancestor_id}}'                    
            };
            if (t == 1){
                $.ajax({
                url:"/sales/bugsell/sms/sms/",
                dataType:"json",
                data:data,
                success:function(data){
                    if(data['e']==''){
                        if(data['users'].length==0){
                            toastr.error("授权的稽察人员帐号没有录入电话号码",  "操作失败：",
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );
                        }else{
                            var a=[];
                            for(i in data['users']){
                                a.push(data['users'][i]);
                            };
                            var s=a.join(',');
                            toastr.success('已发送 '+s+".", '消息已发送成功：',
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );
                        }
                    }else{
                        toastr.error(data['e'],  "操作失败：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    };

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                }
            });
            }else{
                 $.ajax({
                url:"/sales/bugsell/sms/wx/",
                dataType:"json",
                data:data,
                success:function(data){
                    if(data['e']==''){
                        toastr.success(  '微信推送已发送成功',
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );
                    }else{
                        toastr.error(data['e'],  "操作失败：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    };

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                }
            });
            }

        };	
    $(document).ready(function(){                
        
        

        var lbl_style={
　　        //color : "white", //字体颜色
　　        fontSize : "15px",//字体大小 　
　　        backgroundColor :"0.5", //文本标注背景颜色
　　        border :"1", 　
　　        fontWeight :"bold" //字体加粗
        };

        !function(mapInit) {
            var script = document.createElement("script");
            script.type = "text/javascript";
            script.src = "https://api.map.baidu.com/api?v=3.0&ak=GSZdhR3cy3egvUIm7njXTT5NIUqMszWo&callback=mapinit";
            window['mapinit'] = function() {
                mapInit();
            };            
            $('#bg-modal .bdmapscript').html(script);
        }(function() {     
            map = new BMap.Map('bdmap-bugsell');         

            {% for d in data %}                    
                var p1 = new BMap.Point({{d.lng}}, {{d.lat}});
                var marker = new BMap.Marker(p1);  // 创建标注
                map.addOverlay(marker);  
                marker.setAnimation(BMAP_ANIMATION_BOUNCE); 
                marker.addEventListener('click', function(){
                    var me=this;
                    var infoWin=new BMap.InfoWindow(
                        '<div>标签号码：{{d.label_code}}</div>'+
                        '<div>标签类别：{{d.package}}</div>'+ 
                        '<div>产品名称：{{d.product}}</div>'+  
                        '<div>扫码地点：{{d.address}}</div>'+
                        '<div>扫码时间：{{d.time}}</div>'+
                        '<div>超出范围：{{d.distance}}公里</div>'+
                        '<div><button class="btn btn-primary btn-xs" onclick="Sms({{d.id}},1)">发送短消息通知市场稽察人员</a></div>'  +
                        '<div><button class="btn btn-primary btn-xs" onclick="Sms({{d.id}})",0>发送微信推送通知市场稽察人员</a></div>'                        

                    );
                    me.openInfoWindow(infoWin);
                    me.setAnimation(null);
                    infoWin.addEventListener("close", function () {
                        me.setAnimation(BMAP_ANIMATION_BOUNCE);
                    });    
                });   
            {% endfor %}

            map.centerAndZoom(new BMap.Point(72.541653,53.82061), 5);
            map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
            map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用   

        });
        
    });

</script>


