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

 

<script type='text/javascript'>
        function Sms(record_id,method){                    
            //var data={
            //        record_id:record_id,                    
            //        ancestor_id:'{{request.user.company.ancestor_id}}'                    
            //};     
            $.ajax({                
                url:"/sales/sms/fakelabel/{{request.user.company.ancestor_id}}/"+record_id+"/?method="+method,
                //url:"/sales/fakelabel/sms/",
                //url(r'^sales/sms/(?P<what>\w+)/(?P<ancestor_id>\d+)/(?P<record_id>\d+)/$', sal_views.sms_ancestor),
                dataType:"json",
                //data:data,     
                success:function(data){
                    if(data['e']==''){
                        if(method=='sms'){
                            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;
                }
            });            
        };

    $(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>'+
                            '<button class="btn btn-primary btn-xs"  onclick="Sms({{d.id}},\'sms\')">短信通知市场稽察人员</button>'+
                            '<button class="btn btn-primary btn-xs"  onclick="Sms({{d.id}},\'wx\')">微信通知市场稽察人员</button>'+
                        '</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>


