<!DOCTYPE html>
<html>
	<?php echo $this->fetch('head.html'); ?>
	<link href="<?php echo $this->_var['skins']; ?>sites/index.css" rel="stylesheet" />
	<body>
		<div class="header">
			<div class="header-back"></div>
			<div class="header-title">校园选择</div>
		</div>
		<div class="header-row"></div>
		<div class="g-search-box">
			<input type="search" id="keyword" placeholder="请输入学校名称" class="g-search-input" />
			<div id="search-btn" class="g-search-btn icon-search"></div>
		</div>
	
	<div class="modal-group" id="searchBox">
		<div class="modal-mask"></div>
		<div class="modal">
			<div class="modal-body pdt-10" id="search-result">
				<div class="search-result-item"></div>
			</div>
		</div>
	</div>

		<div class="flex flex-al-center bg-fff pd-10 mgb-10">
			<div class="iconfont icon-location_light cl-success"></div>
			<div>离你最近的学校：</div>
			<div id="nearSite" class="cl-primary"></div>
		</div>
		<div id="app" style="display:none;" :style="'display:block'">	
			<div class="site-list bg-white">
				 
				<div  v-for="(s,sindex) in pageData.siteList" :key="sindex" class="site-list-item" @click="setSites(s.siteid)">
					{{s.sitename}}
				</div>
							
			</div>
		</div>
		<?php echo $this->fetch('footer.html'); ?>
		 <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=F73283d678ec76619500152b1a0835c0"></script> 
		
				<script src="/plugin/vue/vue.min.js"></script>
				<script src="<?php echo $this->_var['skins']; ?>sites/index.js?<?php echo time(); ?>"></script>
				<script>
					var word="";
					 $("#search-btn").on("click",function(){
  
							 $.get("/index.php?m=sites&a=search&ajax=1",{keyword:$("#keyword").val()},function(data){
								 if(data.error){
									 skyToast(data.message);
									 $("#search-result").html("");
								 }else{
									 var html="";
									 for(var i=0;i<data.data.length;i++){
										html=html+'<div class="search-result-item js-setSites" siteid="'+data.data[i].siteid+'">'+data.data[i].sitename+'</div>'; 
									 }
									 $("#search-result").html(html)
									 $("#searchBox").show();
								 }
							 },"json");
						  
					 });
					 $(document).on("click",".js-setSites",function(data){
						 $.ajax({
						 	url:"/index.php?m=sites&a=setsite&ajax=1&siteid="+$(this).attr("siteid"),
						 	success:function(){
						 		history.back();
						 	}
						 })
						 
					 })

					var lat,lng;
					var geolocation = new BMap.Geolocation();
					 
						geolocation.getCurrentPosition(function(r){
						if(this.getStatus() == BMAP_STATUS_SUCCESS){
							lat=r.point.lat;
							lng=r.point.lng;
							$.get("/index.php?m=sites&a=near&ajax=1",{lat:lat,lng:lng},function(data){
								if(data.error==0){
									$("#nearSite").html('<a class="cl2 pointer js-setSites" siteid="'+data.data.siteid+'">'+data.data.sitename+'</a>');
								}
							},"json")
						}
						else {
							skyToast('获取位置失败'+this.getStatus());
						}        
					},{enableHighAccuracy: true})
		
				</script>
	</body>
</html>
