Browse Source

地图 居中,时刻表

zhengkaixin 4 năm trước cách đây
mục cha
commit
2be64b3c2b
2 tập tin đã thay đổi với 61 bổ sung19 xóa
  1. 7 2
      components/Carmap.vue
  2. 54 17
      pages/route/index.js

+ 7 - 2
components/Carmap.vue

@@ -107,6 +107,9 @@
 			setCenter(item){
 				if(this.mapbus){
 					this.mapbus.setCenter([item.longitude,item.latitude]);
+					return true
+				}else{
+					return false
 				}
 			},
 			setSite(ob){
@@ -210,7 +213,7 @@
 			 
 				
 			},
-			setPerson(ob){
+			setPerson(ob,bl){
 				if(this.AMap==null){
 					return
 				}
@@ -233,7 +236,9 @@
 							autoRotation: true,
 						});
 						//this.mapbus.setCenter([this.info.longitude,this.info.latitude]); //设置地图中心点
-						this.mapbus.setCenter([ this.info.longitude,this.info.latitude]); //设置地图中心点
+						if(!bl){
+							this.mapbus.setCenter([ this.info.longitude,this.info.latitude]); //设置地图中心点
+						}
 
 					}else{
 						this.info.ob.setPosition( [this.info.longitude,this.info.latitude]);

+ 54 - 17
pages/route/index.js

@@ -20,7 +20,8 @@ export default {
 			longitude: 112.276527,
 			latitude: 30.306427,
 			show1: false,
-			show2: false,
+			show2: false,
+			centerBl:false,
 			shiftInfo: {
 
 			},
@@ -31,7 +32,8 @@ export default {
 				driverInfo:{}
 			},
 			caritemBl:false,
-			stationList: [],
+			stationList: [],
+			routeTimeTableList:[],
 			dis:'',
 			//个人
 			info: {
@@ -81,26 +83,43 @@ export default {
 			console.log(e)
 		},
 		vehicleStationDis(){
-			var obj={
-				startStationId:this.stationList[0].id,
-				currentStationId :this.downItem.id,
-				routeId:this.routeInfo.id,
-			}
-			if(this.stationList[0].id==this.downItem.id&&this.routeInfo.interval){
+			
+			if(this.stationList[0].id==this.downItem.id&&this.routeTimeTableList&&this.routeTimeTableList.length){
 				
 				
 				var nowDate =new Date();
 				var curDay=nowDate.getFullYear()+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();
-				var startDate =new Date(curDay+" "+this.routeInfo.startTime+":00");
-				var endDate =new Date(curDay+" "+this.routeInfo.endTime+":00");
-				if(nowDate.getTime()>endDate.getTime()){
+				var startDate =null;
+				
+				for(var i in this.routeTimeTableList){
+					var obj=this.routeTimeTableList[i]
+					var objDate =new Date(curDay+" "+obj.startTime+":00");
+					
+					if(nowDate.getTime()<objDate.getTime()){
+						if(startDate==null){
+							startDate=objDate;
+						}
+						if(objDate<startDate){
+							startDate=objDate;
+						}
+					}
+				}
+				
+				if(startDate==null){
 					this.dis="今日发车已经结束,明日发车时间"+this.routeInfo.startTime
 				}else{
-					var d=this.routeInfo.interval - parseInt((nowDate.getTime()-startDate.getTime())/1000/60)%this.routeInfo.interval
+					console.log(startDate)
+						console.log(nowDate)
+					var d=  parseInt((startDate.getTime()-nowDate.getTime())/1000/60)
 					this.dis="等待发车... 大约"+d+"分钟发车"
 				}
 				
 			}else{
+				var obj={
+					startStationId:this.stationList[0].id,
+					currentStationId :this.downItem.id,
+					routeId:this.routeInfo.id,
+				}
 				//this.$refs.common.showLoading();
 				API.vehicleStationDis(obj).then((res) => {
 					this.dis=res.data;
@@ -176,6 +195,24 @@ export default {
 			}
 			API.routeShiftList(obj).then((response) => {
 				this.carList=response.data;
+				if(!this.centerBl&&this.carList.length){
+					this.centerBl=this.$refs.amap.setCenter(this.carList[0]);
+					//this.centerBl=true;
+					if(this.centerBl){
+						document.getElementById('map-route-main').scrollLeft = 0
+						this.$nextTick(function() {
+							const query = uni.createSelectorQuery().in(this);
+							query.select('.map-route-car').boundingClientRect(data => {
+								if(data){
+									document.getElementById('map-route-main').scrollLeft = data.left-20;
+								}
+								
+								//this.downBtn()
+							}).exec();
+						});
+					}
+				}
+				
 				this.$refs.amap.setCarList(response.data);
 				this.vehicleStationDis();
 			}).catch(error => {
@@ -318,6 +355,7 @@ export default {
 				
 				var point = [];
 				this.routeInfo=response.data.routeInfo;
+				this.routeTimeTableList=response.data.routeTimeTableList;
 				this.title=this.routeInfo.name;
 				if(!response.data.routeInfo.mapPath){
 					this.$refs.common.showLoading(false,"路线加载失败!")
@@ -365,6 +403,8 @@ export default {
 		
 				if(this.downid=="null"){
 					this.downid="";
+				}else{
+					this.centerBl=true;
 				}
 			if(this.downid){
 				this.downBtn(this.downItem)
@@ -372,10 +412,7 @@ export default {
 			
 		},
 		getPoint() {
-
-
-			
-		
+
 			if (!this.info.init) {
 				WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
 					// this.$refs.common.showLoading(false)
@@ -405,7 +442,7 @@ export default {
 				this.info.latitude = latitude;
 				this.info.longitude = longitude;
 			
-				this.$refs.amap.setPerson(this.info);
+				this.$refs.amap.setPerson(this.info,true);
 			
 			}).catch(error => {
 				console.log(error)