zhupeng 3 years ago
parent
commit
176df6c820
3 changed files with 231 additions and 29 deletions
  1. 45 16
      components/Chargermap.vue
  2. 163 3
      pages/search/search.vue
  3. 23 10
      pages/searchPile/searchPile.vue

+ 45 - 16
components/Chargermap.vue

@@ -72,6 +72,7 @@
 			};
 		},
 		methods:{
+			/*
 			getLocation1() {
 //			  console.log('getLocation');
 			  const self = this;
@@ -132,7 +133,31 @@
 				  }
 				});
 			  });
-			}, 
+			}, */
+			getPositionByLonLats(pos) {
+				var _this = this;
+				MapLoader().then(AMap => {
+					var lnglatXY =//[_this.longitude, _this.latitude]
+					 [pos.longitude, pos.latitude];
+					AMap.service('AMap.Geocoder', function() {
+						let geocoder = new AMap.Geocoder({});
+						geocoder.getAddress(lnglatXY, function(status, result) {
+							console.log(lnglatXY);
+							console.log(status, result);
+							if (status === 'complete' && result.info === 'OK') {
+								var address = result.regeocode.formattedAddress;
+								console.log('当前位置'+JSON.stringify(lnglatXY)+address);
+								//_this.message= address;
+							
+							} else {
+								//_this.message= '无法获取定位';
+							}
+						});
+					});
+				}).catch(error => {
+					console.log(error)
+				})
+			},
 			searchBtn(startLngLat,endLst){
 				var _this = this;
 				
@@ -377,31 +402,35 @@
 						center: [this.longitude, this.latitude],
 						zoom: 14
 					});
-					 
 					//var clickHandler = function(e) {
 					//	console.log('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!');
 					//};
 					//_this.mapcharger.on('click', clickHandler); 
 					_this.$emit('onload')
-					var mapMovestart = function(){
-						console.log('movestart')
-					}
-					var mapMove = function(){
-						//console.log('mapMove')
-					}
-					var mapMoveend = function(){
-						let pos = _this.logMapInfo();
-						_this.$emit('onMoveEnd',pos);
-//						console.log('mapMoveend')
-					}
-					_this.mapcharger.on('movestart', mapMovestart);
-					_this.mapcharger.on('mapmove', mapMove);
-					_this.mapcharger.on('moveend', mapMoveend); 
+					_this.listenMove();
+					
 				}, e => {
 					//_this.mui.toast('地图加载失败');
 					console.log('地图加载失败', e)
 				})
 			},
+			listenMove(){
+				var _this = this;
+				var mapMovestart = function(){
+					console.log('movestart')
+				}
+				var mapMove = function(){
+					//console.log('mapMove')
+				}
+				var mapMoveend = function(){
+					let pos = _this.logMapInfo();
+					_this.$emit('onMoveEnd',pos);
+//						console.log('mapMoveend')
+				}
+				_this.mapcharger.on('movestart', mapMovestart);
+				_this.mapcharger.on('mapmove', mapMove);
+				_this.mapcharger.on('moveend', mapMoveend); 
+			},
 			navigate(){
 				AMap.plugin('AMap.Driving', function() {
 				  var driving = new AMap.Driving({

+ 163 - 3
pages/search/search.vue

@@ -2,7 +2,7 @@
 <template>
 	<view>
 		<u-navbar title="">
-			<u-search class="search" placeholder="搜索站点名称" @change="search" v-model="keyword" color="#c8c8c8" @search="search" @click="search" @clickicon='back' @custom='search'></u-search>
+			<u-search class="search" placeholder="搜索站点名称" @change="keyword.length>0?search():''" v-model="keyword" color="#c8c8c8" @search="search" @click="search" @clickicon='back' @custom='search'></u-search>
 		</u-navbar>
 		<view class="recommend">推荐充电站</view>
 		<view class="charing-slow" v-for="(item,index) in stations_filter" :key="item.id">
@@ -32,7 +32,10 @@
 </template>
 
 <script>
-	
+	let _self;
+	import * as api from '@/apis/site.js';
+	import * as WxJsApi from '@/utils/wxJsApi.js'
+	import MapLoader from '@/utils/AMap'
 	export default {
 		
 		data() {
@@ -50,14 +53,170 @@
 			}
 		},
 		onLoad(op){
+			_self = this;
+			/*
 			if(op!= null && op.stationlist != null){
 				this.stations = decodeURIComponent(op.stationlist)
 				console.log('stations'+JSON.stringify(this.stations))
 			}
-			console.log('op'+JSON.stringify(op))
+			console.log('op'+JSON.stringify(op))*/
+		},
+		onReady() {
+			 
+			 WxJsApi.getWxConfig(['getLocation','addEventListener']).then((res)=>{
+			 
+				// this.message=JSON.stringify(res)
+				// uni.showToast({
+				// 	title:JSON.stringify(res)
+				// })
+				console.log(res)
+			  
+			 }).catch(error => {
+					console.log(res)
+			 })
+			this.getPoint();
 		},
 		 // conponents:{charingSlows},
 		methods: { 
+			getPoint() {
+				var _this = this;
+				console.log('getPoint')
+				WxJsApi.getLocation().then((res) => {
+					
+					var latitude = parseFloat(res.latitude);
+					var longitude = parseFloat(res.longitude);
+					_this.latitude = latitude;
+					_this.longitude = longitude;
+					
+ 			 
+					let data = {latitude:_this.latitude,longtitude:_this.longitude};
+					this.getChargingStationData(data);
+					
+					console.log('当前位置' +JSON.stringify(data))
+					
+					//this.latitude2 = latitude;
+					//this.longitude2 = longitude;
+					/*uni.showToast({
+						title:JSON.stringify(res)
+					})*/
+					//this.message=JSON.stringify(res)
+				}).catch(error => {
+					uni.showToast({
+						title:JSON.stringify(error)
+					})					
+				})
+			},
+			getChargingStationData(pos){
+						//return;
+				if(pos == null)
+					return ;		 
+				let data1 = { pageIndex:0,pageSize:20};
+				if(pos.longtitude != null)
+					data1.longitude = pos.longtitude.toString();
+				if(pos.latitude != null)
+					data1.latitude = pos.latitude.toString(); 
+				//data1.findType = "0";
+				//data1.type = "1";
+				data1.online = "0";
+/*				if(this.info.obc_type[this.preference.obc_type_index].text.indexOf('直流快充')>=0)
+					data1.type = "1";
+				else if(this.info.obc_type[this.preference.obc_type_index].text.indexOf('交流慢充')>=0)
+					data1.type = "2";
+				
+				if(this.info.miles_type[this.preference.miles_index].distance!=null)
+					data1.radius = this.info.miles_type[this.preference.miles_index].distance.toString();
+				data1.online = "0";//在线	
+				if(pos.findType != null)
+					data1.findType = pos.findType;
+				else
+					data1.findType = "0";
+				
+				if(this.preference.obc_power.minValue!=null)
+					data1.powerStart = this.preference.obc_power.minValue.toString();
+				if(this.preference.obc_power.maxValue!=null)
+					data1.powerEnd = this.preference.obc_power.maxValue.toString();
+				*/
+				console.log('data1'+JSON.stringify(data1))
+				api.getChargingStationData(data1).then(function(res){
+					
+					console.log('getChargingStationData'+JSON.stringify(res))
+					if(!res.result || !res.data || !res.data.data)
+					{
+						console.log('getChargingStationData res nulll')
+						return;					
+					}
+					let items = res.data.data;
+					 
+					_self.stations_filter = [];
+					for(let i = 0;i<items.length;i++)
+					{
+						let obj = {
+									name:'',
+									position:'',
+									price:1.2,
+									idleNum:10,
+									total:10,									
+									type: data1.type == "2" ? '慢充':'快充',
+									id: i,									
+									distance:0.9,
+									time:9,
+									park: '以实际费用为准',
+//									longitude: 112.28541 + i * 0.001,
+//									latitude: 30.308354 + i * 0.01
+									};
+						if(items[i].id != null)
+							obj.id = items[i].id;
+						else
+							continue;
+						if(items[i].name!=null)
+							obj.name = items[i].name;
+						if(items[i].address!=null)
+							obj.position = items[i].address;
+						if(items[i].coostPrice!=null)
+							obj.price = items[i].coostPrice;
+						if(items[i].availableNum!=null)
+							obj.idleNum = items[i].availableNum;
+						if(items[i].totalNum!=null)
+							obj.total = items[i].totalNum;
+						if(items[i].longitude!=null)
+							obj.longitude = items[i].longitude;
+						if(items[i].latitude!=null)
+							obj.latitude = items[i].latitude;
+						if(items[i].distance!=null)
+							obj.distance = items[i].distance;
+						if(items[i].time != null){
+							obj.time = items[i].time;
+						}
+						if(items[i].park != null)
+							obj.park = items[i].park;
+						/*
+						let obj = {name:items[i].name,
+									position:items[i].address,
+									price:items[i].coostPrice,									
+									idleNum:items[i].availableNum,
+									total:items[i].totalNum,
+									distance:0.1,
+									time:1,
+									type:'慢充',
+									id: items[i].id,
+									park: i%2 == 0? '以实际费用为准':'2小时免费停车',
+									longitude: items[i].longitude,
+									latitude: items[i].latitude
+									};*/
+						_self.stations.push(obj);						
+					}
+					_self.stations_filter = _self.stations;
+					//_self.$refs.amap.searchBtn([_self.longitude, _self.latitude],_self.stationsmap)
+					//_self.$refs.amap.setChargerList(_self.stationsmap);
+					//if(_self.stationsmap.length>0)
+					//	_self.$refs.amap.updateCharger(_self.stationsmap[0]);
+					 
+				},function(err){
+					console.log('getChargingStationData err'+JSON.stringify(err))
+				}
+				)
+				console.log('getChargingStationData end')
+			},	
 			back(){
 				console.log('back');
 				uni.navigateBack({
@@ -77,6 +236,7 @@
 				}
 				
 				console.log('search ' + this.keyword);
+				
 			}
 		}
 	}

+ 23 - 10
pages/searchPile/searchPile.vue

@@ -164,7 +164,8 @@
 			</view>
 			<view v-show="viewMode" >					
 				<view>
-					<Chargermap @location="location"  @onMoveEnd="moveEnd" ref="amap" @onload="mapdown" @clickMap="clickMap"></Chargermap>
+					<Chargermap   @onMoveEnd="moveEnd" ref="amap" @onload="mapdown" @clickMap="clickMap"></Chargermap>
+					<!--@location="location"-->
 				</view>
 				 
 				<view v-if="stationsmap.length>0" class="chargerCard" style="border-radius: 20rpx;" > 
@@ -233,7 +234,7 @@
 
 			</view>
 		</view>
-		<Tabbar :current="1"></Tabbar>
+		<Tabbar :current="1"></Tabbar> 
 	</view>
 </template>
 
@@ -246,13 +247,13 @@ import DoubleSlider from '@/components/double-slider/DoubleSlider.vue';
 import Tabbar from '@/components/Tabbar.vue';
 import * as WxJsApi from '@/utils/wxJsApi.js'
 import MapLoader from '@/utils/AMap'
-//import * as navigation from '@/pages/navigation/index.vue'
+ 
 let _self;
 export default {
 	components: {
 		Chargermap,
 		DoubleSlider,
-		Tabbar	
+		Tabbar, 
 	},
 	data() {
 		return {
@@ -318,6 +319,8 @@ export default {
 			if (op.latitude != null) this.latitude = op.latitude;
 			if (op.id != null) this.id = op.id;
 		}
+		 
+		//navigation.getPoint();
 		
 	},
 	onReady() {
@@ -337,7 +340,7 @@ export default {
 		//		console.log('longitude2  '+this.longitude)
 		//		console.log('latitude2  '+this.latitude)
 		this.$refs.amap.init();
-		
+		//this.getPositionByLonLats();
 //		this.$refs.amap.setMyStyle("height:1500rpx;width:100%;");
 //	this.$refs.amap.setMyStyle("height:calc(100%-176rpx);width:100%;");
 				
@@ -355,6 +358,7 @@ export default {
 		this.end();
 	},
 	methods: {
+		
 		navigateTo(){
 			console.log('导航')
 			this.$refs.amap.navigate();
@@ -365,15 +369,17 @@ export default {
 				url:'/pages/search/search?stationlist='+encodeURIComponent(JSON.stringify(_self.stationsmap))
 					 
 			})
-		},
+		},		
 		getPoint() {
-		
+			 
 			console.log('getPoint')
 			WxJsApi.getLocation().then((res) => {
 				
 				var latitude = parseFloat(res.latitude);
 				var longitude = parseFloat(res.longitude);
 				let data = {position:{latitude:latitude,longitude:longitude}};
+
+				_self.location(data);
 				
 				if(_self.first)
 				{
@@ -382,10 +388,14 @@ export default {
 									latitude: latitude
 								};
 					this.$refs.amap.setPerson(obj);	
+					//let data = {latitude:latitude,longtitude:longitude};
+					//this.getChargingStationData(data);
+					this.getNearbyStationInfo();
 					_self.first = false;
+					//this.$refs.amap.listenMove();
 				}
-			
-				this.location(data);
+				
+				
 				console.log('当前位置' +JSON.stringify(data))
 				
 				//this.latitude2 = latitude;
@@ -424,6 +434,7 @@ export default {
 		},
 		location(e){
 			if(e.position){
+				this.$refs.amap.getPositionByLonLats(e.position);
 				if(e.position.latitude && e.position.longitude)
 				if(this.latitude != e.position.latitude || 
 					this.longitude != e.position.longitude)
@@ -539,6 +550,8 @@ export default {
 					}
 					_self.$refs.amap.searchBtn([_self.longitude, _self.latitude],_self.stationsmap)
  					_self.$refs.amap.setChargerList(_self.stationsmap);
+					if(_self.stationsmap.length>0)
+						_self.$refs.amap.updateCharger(_self.stationsmap[0]);
 				}else if(data1.findType == "1")
 				{
 					_self.stationslist = [];
@@ -741,7 +754,7 @@ export default {
 //			console.log('latitude1  ' + this.latitude);
 			//this.start();
 			//this.$refs.amap.getLocation1();
-//			this.getNearbyStationInfo();
+			this.getNearbyStationInfo();
 			this.isReady = true;
 			//this.$refs.amap.getLocation ();
 			//let state = {};