Ver código fonte

拖动后与滑动卡片没有关联上。

zhupeng 3 anos atrás
pai
commit
1249816826
2 arquivos alterados com 97 adições e 22 exclusões
  1. 56 13
      components/Chargermap.vue
  2. 41 9
      pages/searchPile/searchPile.vue

+ 56 - 13
components/Chargermap.vue

@@ -10,25 +10,27 @@
 <script>
 		import MapLoader from '@/utils/AMap'
 	let _self;
+	 
 	function mapMovestart(e) {
 		console.log('movestart')
 	}
 	function mapMove(e){
-		//console.log('mapMove')
+//		console.log('mapMove')
 	}
 	function mapMoveend(e){
 		//let _self = e;
 		let pos = _self.logMapInfo();
 		 
 		_self.$emit('onMoveEnd',pos);
-	//						console.log('mapMoveend')
-	}	
+		console.log('mapMoveend')
+	}	 
 		
 	export default {
 		name:"Chargermap",
 		
 		data() {
 			return {
+				enabledMove:true,
 				myStyle:"width: 100%; height: 1200rpx;",
 				chargerIcon:'',
 				chargerSelectedIcon:'',
@@ -254,7 +256,8 @@
 				}) */
 			},
 			updateCharger(pos){ 
-//				console.log('更新充电桩1'+JSON.stringify(pos) ) 
+				
+				console.log('更新充电桩1'+JSON.stringify(pos) ) 
 //				let index = this.chargerList.findIndex(item => item.info.latitude === pos.latitude && item.info.longitude === pos.longitude);
 				//let index = this.chargerList.findIndex(item => (Math.abs(item.info.longitude-pos.longitude)<0.000001 && Math.abs(item.info.longitude - pos.latitude)<0.000001));
 				let index = this.chargerList.findIndex(item => item.info.id === pos.id);
@@ -420,26 +423,47 @@
 			},
 			myEmit(type,ob1,obj){
 				var _this=this;
+				
 				AMap.event.addListener(ob1, 'click', function(e) {
+					
 					_this.$emit('clickMap',{
 						type:type,
 						obj:obj
-					})						
+					})			
 				})
 				
 			},
 			setMyStyle(s){
 				this.myStyle=s;
 			},			 
+			checkCenter(item){
+				let pos =  this.mapcharger.getCenter();
+				if(pos.lng == item.longitude && pos.lat == item.latitude){
+					console.log('setCenter pos '+JSON.stringify(pos))
+					console.log('setCenter item '+JSON.stringify(item))
+					this.listenMove();
+				}else{
+					console.log('setCenter pos1 '+JSON.stringify(pos))
+					console.log('setCenter item1 '+JSON.stringify(item))
+					setTimeout(() => {
+						this.checkCenter(item);
+					}, 1000)
+				}
+			},
 			setCenter(item){ 
+//				this.enableMove(false);
 				this.removeMove();
 //				console.log('setCenter'+JSON.stringify(item))
 				if(this.mapcharger){
 					this.mapcharger.setCenter([item.longitude,item.latitude]);
-					this.listenMove();
+					this.checkCenter(item);
+//					this.listenMove();
+ 
+//					this.enableMove(true);
 					return true
 				}else{
-					this.listenMove();
+//					this.listenMove();
+//					this.enableMove(true);
 					return false
 				}
 			},		
@@ -592,23 +616,42 @@
 					//_this.mui.toast('地图加载失败');
 					console.log('地图加载失败', e)
 				})
-			},						
+			},	
+			 
 			removeMove(){
 				var _this = this;
-				
+				//this.enabledMove = false;
 				_this.mapcharger.off('movestart', mapMovestart);
 				_this.mapcharger.off('mapmove', mapMove);
 				_this.mapcharger.off('moveend', mapMoveend); 
 				 
 								
+			}, 
+			enableMove(enable){
+				this.enabledMove = enable;
 			},
 			listenMove(){
 				var _this = this;
-				
+				/*var mapMovestart = function(){
+					if(!_this.enabledMove)
+						return;
+					console.log('movestart')
+				}
+				var mapMove = function(){
+					if(!_this.enabledMove)
+						return;
+					//console.log('mapMove')
+				}
+				var mapMoveend = function(){
+					let pos = _this.logMapInfo();
+					if(!_this.enabledMove)
+						return;
+					_this.$emit('onMoveEnd',pos); 
+				}*/
 //				console.log('listenMove')
-				_this.mapcharger.on('movestart', mapMovestart,_this);
-				_this.mapcharger.on('mapmove', mapMove,_this);
-				_this.mapcharger.on('moveend',mapMoveend,_this); 
+				_this.mapcharger.on('movestart', mapMovestart);
+				_this.mapcharger.on('mapmove', mapMove);
+				_this.mapcharger.on('moveend',mapMoveend); 
 				 
 			},
 			navigate(startLngLat,endLngLat){

+ 41 - 9
pages/searchPile/searchPile.vue

@@ -183,7 +183,7 @@
 					 
 				</view>
 				<view v-if="stationsmap.length>0" class="chargerCard" style="border-radius: 20rpx;"> 
-					<swiper :current="currentIndex" @change="swiperChange" @transition="swiperTransition" style="height: 100%;">
+					<swiper :current="currentIndex" @change="swiperChange" slide-change-transition-end='swiperTransitionEnd' @transition="swiperTransition" style="height: 100%;">
 					 	<swiper-item v-for="(item,index) in stationsmap" :key="item.id" style="height: 100%;">							 
 							
 							<view class="swiper-item" style="height: 100%; background-color: #ffffff;" @click="stationDetail(item)">
@@ -377,7 +377,7 @@ export default {
 		
 	},
 	onReady() {
-		console.log('长者模式'+JSON.stringify(this.carhelp.get("getElderModeClass")));
+//		console.log('长者模式'+JSON.stringify(this.carhelp.get("getElderModeClass")));
 		this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
 		
 		//this.elderMode = true;
@@ -774,6 +774,13 @@ export default {
 				data1.findType = pos.findType;
 			else
 				data1.findType = "0";
+				
+			if(data1.findType == "0")
+			{					
+			//					console.log('getChargingStationData res1'+JSON.stringify(res));
+				_self.currentIndex = -1;
+				_self.stationsmap = []; 
+			}
 			/*
 			if(this.preference.obc_power.minValue!=null)
 				data1.powerStart = this.preference.obc_power.minValue.toString();
@@ -795,7 +802,9 @@ export default {
 				if(data1.findType == "0")
 				{					
 //					console.log('getChargingStationData res1'+JSON.stringify(res));
-					_self.stationsmap = [];
+//					_self.currentIndex = -1;
+//					_self.stationsmap = []; 
+					//let stations  = [];
 					for(let i = 0;i<items.length;i++)
 					{
 						let obj = {
@@ -856,12 +865,23 @@ export default {
 									latitude: items[i].latitude
 									};*/
 						_self.stationsmap.push(obj);						
+						//stations.push(obj);
 					}
 					_self.$refs.amap.calcDistances([_self.longitude, _self.latitude],_self.stationsmap)
- 					_self.$refs.amap.setChargerList(_self.stationsmap);
+ 					_self.$refs.amap.setChargerList(_self.stationsmap); 
+					_self.currentIndex = 0; 
+					//if(_self.stationsmap.length>0)
+					/*_self.$refs.amap.calcDistances([_self.longitude, _self.latitude],stations)
+					_self.stationsmap = stations;	
+ 					_self.$refs.amap.setChargerList(stations);*/
 					if(_self.stationsmap.length>0)
 					{
+						console.log('刷新Map'+JSON.stringify(_self.stationsmap));
 						_self.$refs.amap.updateCharger(_self.stationsmap[0]); 
+						//let index = _self.stationsmap.findIndex(item => item.id == _self.stationsmap[0].id);						
+						
+						
+						console.log('刷新Map Index'+ _self.currentIndex)
 					}
 				}else if(data1.findType == "1")
 				{
@@ -949,6 +969,7 @@ export default {
 			
 		},	*/	
 		moveEnd(e){ 
+			console.log('moveEnd')
 			this.close_all();
 			let posCenter = this.$refs.amap.logMapInfo();
 			//console.log('posCenter'+JSON.stringify(posCenter))			
@@ -959,11 +980,12 @@ export default {
 			this.close_all();
 		},
 		clickTabItem (index) {
-			
+			console.log('clickTabaItem'+JSON.stringify(index));
 			this.currentIndex = index
 		},
 		swiperChange (e) {
-//			console.log('swiperChange'+JSON.stringify(e))
+			console.log('swiperChange currentIndex'+JSON.stringify(this.currentIndex))
+			console.log('swiperChange'+JSON.stringify(e))
 			this.currentIndex = e.detail.current
 			let station = this.stationsmap[this.currentIndex];
 			
@@ -984,8 +1006,11 @@ export default {
 			this.$refs.amap.setCenter(posCenter);
 			  
 		},
+		swiperTransitionEnd(e){
+			console.log('swiperTransitionEnd'+JSON.stringify(e))
+		},
 		swiperTransition (e) {
-			// console.log(e)
+			// console.log('swiperTransition'+JSON.stringify(e))
 		},
 		listMode() {
 			this.close_all();
@@ -1075,7 +1100,14 @@ export default {
 //			console.log('latitude1  ' + _self.latitude);
 			if (obj == null || obj.type == null) return;
 			if (obj.type == 'charger') {
-				api.getChargerInfoById(obj).then(
+				if (obj.obj != null) {
+					
+					//_self.$refs.amap.updateCharger(obj.obj);
+					let index = _self.stationsmap.findIndex(item => item.id == obj.obj.id);
+					_self.currentIndex = index;
+					console.log('find Index'+index);
+				}
+				/*api.getChargerInfoById(obj).then(
 					function(data) {
 						if (obj.obj != null) {
 							//obj.obj.price = 2.25;
@@ -1090,7 +1122,7 @@ export default {
 					function(err) {
 						console.log('点击2' + JSON.stringify(obj));
 					}
-				);
+				);*/
 			}
 		},
 		mapdown() {