<{import file="header.html" title="门店位置"}>
<style type="text/css">
.lbox{ padding-bottom:100px; float:left;}
.map{ width:910px; height:500px; float:left;}

.map .name{ width:928px; background:#f8f8f8; border:1px solid #efefef; margin:0 0 10px 0; height:36px; padding:6px 0 0 0; float:left;}
.map .name span{padding:0 10px 0 10px; }
.cname{ float:left; }
.cname .nm{ padding:7px 10px 10px 10px; float:left; }
.cname .area_box{ padding:3px 0 10px 0; float:left;  }
.cname .area_box span{ padding:3px 5px 2px; background:#fff; float:left; }
.cname input{ padding:5px 5px 4px 5px; margin:3px 0 0 10px; float:left; }

.map .name .aname{ padding:0 10px 0 10px; float:left;}
.map .name .aname span{ padding:7px 10px 0 10px; float:left; }
.map .name .aname input.btn{ padding:5px; margin:3px 0 0 0; } 
.map .name input#save_location{ background:#0188E0; border:none; color:#fff; padding:7px 10px 6px; margin-left:10px; }

.map #allmap {width: 100% ;height: 100%; overflow: hidden; margin:0; } 
#l-map{height:500px; width:100%;}
#r-result{width:100%;}
</style> 
<{include file="shop/tab.html"}> 
<{uqcms m="shop" v="row" c="get_one:id=auto"}>
<div class="lbox"> 
	<div class="map">
		<form action="#" method="post"> 
			<div class="name">  
				<div class="cname">
					<div class="nm">详细地址：</div>
					<div class="area_box"></div>
					<input type="text" name="address" size="30" id="address" value="<{$row.address}>"/> 
				</div>
				<{if $row.lng == ''&& $row.lat== ''}><span>当前定位：<span></span> </span><{/if}> 
				<div class="aname"><span>经度：</span> <input type="text" size="10" value="<{$row.lng}>" name="lng" class="btn"/></div>
				<div class="aname"><span>纬度：</span><input type="text" size="10" value="<{$row.lat}>" name="lat" class="btn"/></div>
				<input type="button" name="save_pst" id="save_location" value="保存定位"/> 
			</div>
		</form> 
		<div id="allmap"></div>  
		<div id="r-result"></div>
	</div>  
</div>
<{import file="footer.html"}> 
<script type="text/javascript" src="<{$__PUBLIC__}>js/area.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=<{$UQCMS.map_baidu_key}>"></script> 
<script type="text/javascript">
$(function(){
	<{if $row.prov == '' && $row.city == '' && $row.dist == ''}>
		$(".area_box").area();
	<{else}>	
		$(".area_box").area({'prov':'<{$row.prov}>', 'city':'<{$row.city}>', 'dist':'<{$row.dist}>'});	
	<{/if}> 
	
	$("#save_location").click(function(){
		var lng = $(".map .name input[name=lng]").val();
		var lat = $(".map .name input[name=lat]").val(); 
		var prov = $("#prov").val();
		var city = $("#city").val();
		var dist = $("#dist").val();
		var address = $("#address").val();
		$.post(SELLER+'shop/map_save', {prov:prov, city:city, dist:dist, address:address, lng:lng, lat:lat}, function(result){ 
			data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				$.alert('保存成功');
			}else{ 
				$.alert(data.msg);
			}
		}); 	
	});
});
// 百度地图API功能
var map = new BMap.Map("allmap");  
<{if ($row.lng == '') && ($row.lat== '')}>
	var point = new BMap.Point(116.331398, 39.897445);
	map.centerAndZoom(point, 12); 
	var myCity = new BMap.LocalCity();
	myCity.get(function(){
		var cityName = result.name; 
		map.setCenter(cityName); 
		var myCity = new BMap.LocalCity(); 
		$('.map .name span').html(cityName); 
	}); 
<{else}>  
	var point = new BMap.Point(<{$row.lng}>, <{$row.lat}>);
	map.centerAndZoom(point, 18); 
	var marker = new BMap.Marker(point);// 创建标注
	map.addOverlay(marker);             // 将标注添加到地图中 
<{/if}> 
map.enableScrollWheelZoom();  			//启用滚轮放大缩小，默认禁用
map.enableContinuousZoom();    			//启用地图惯性拖拽，默认禁用 
map.addEventListener("click",function(e){ 
	$(".map .name input[name=lng]").val(e.point.lng);
	$(".map .name input[name=lat]").val(e.point.lat); 
	// 提示窗 
	map.clearOverlays();        		 // 移除覆盖物
	var point = new BMap.Point(e.point.lng, e.point.lat); 
	var marker = new BMap.Marker(point);// 创建标注
	map.addOverlay(marker);             // 将标注添加到地图中
});

</script>
