Commit 48fc6a15 by zhangxw

找车页面修改

1 parent 648a9ae2
...@@ -74,42 +74,46 @@ Page({ ...@@ -74,42 +74,46 @@ Page({
getData() { getData() {
this.getVehicleData() this.getVehicleData()
}, },
getVehicleData(){ async getVehicleData(){
if(this.data.sns){ if(this.data.sns){
this.setData({ this.setData({
isLoading: true isLoading: true
}) })
WXRequest.get('trialdrive/api/vehicle/location', { let res = await WXRequest.get('trialdrive/api/vehicle/location', {sns: decodeURIComponent(this.data.sns)}, true)
sns: decodeURIComponent(this.data.sns) if (res) this.setData({isLoading: false})
}, true).then(res => {
this.setData({
isLoading: false
})
if (res.code == 200) { if (res.code == 200) {
let [markers, includePoints] = [[], []] let [markers, includePoints] = [[], []]
if (res.data.length > 0) { if (res.data.length > 0 ) {
res.data.forEach(item => { for (var i = 0; i < res.data.length; i++) {
markers.push({ markers.push({
id: Number(item.sn), // 设备号唯一 可作为markerid id: Number(res.data[i].sn), // 设备号唯一 可作为markerid
width: 28, width: 28,
height: 36, height: 36,
latitude: Number(item['gpsLocation'].elat), // 默认显示GPS定位位置 latitude: Number(res.data[i]['gpsLocation'].elat), // 默认显示GPS定位位置
longitude: Number(item['gpsLocation'].elng), longitude: Number(res.data[i]['gpsLocation'].elng),
iconPath: item.source === 1 ? '../../images/oncar.png' : '../../images/offcar.png' iconPath: res.data[i].source === 1 ? '../../images/oncar.png' : '../../images/offcar.png'
}) })
includePoints.push({ includePoints.push({
latitude: item['gpsLocation'].elat, latitude: res.data[i]['gpsLocation'].elat,
longitude: item['gpsLocation'].elng, longitude: res.data[i]['gpsLocation'].elng,
padding: [80, 80, 80, 80] padding: [80, 80, 80, 80]
}) })
item.type = 'gpsLocation' // 默认显示GPS的定位类型 res.data[i].type = 'gpsLocation' // 默认显示GPS的定位类型
}) let typeArr = ['gpsLocation', 'bsLocation']
this.myMap.setData({ // 防止页面跳转回退页面未保留用户的操作 用mapContext 会有问题 for (var j = 0; j < typeArr.length; j++) {
inPoints: includePoints await this.getTransferAddress(res.data[i], typeArr[j])
}
}
this.setData({
carInfoArr: res.data,
includePoints: includePoints,
markers: markers
}) })
wx.getSystemInfo({ wx.getSystemInfo({
success: (res) => { success: (res) => {
console.log(res)
if (res.platform == 'devtools') { // 开发工具上include-points 失效 if (res.platform == 'devtools') { // 开发工具上include-points 失效
console.log('123')
this.myMap.getMapCtx().includePoints({ this.myMap.getMapCtx().includePoints({
points: includePoints, points: includePoints,
padding: [80, 80, 80, 80] padding: [80, 80, 80, 80]
...@@ -121,11 +125,6 @@ Page({ ...@@ -121,11 +125,6 @@ Page({
} }
} }
}) })
this.setData({
carInfoArr: res.data,
includePoints: includePoints,
markers: markers
})
} else { } else {
wx.showModal({ wx.showModal({
content: '暂无数据', content: '暂无数据',
...@@ -133,34 +132,17 @@ Page({ ...@@ -133,34 +132,17 @@ Page({
}) })
} }
} }
})
} }
}, },
// 显示对应marker详情 // 显示对应marker详情
getCarInfoWindowObj(e) { getCarInfoWindowObj(e) {
let data = this.data.carInfoArr.find(item => Number(item.sn) === e.detail.markerId) let data = this.data.carInfoArr.find(item => Number(item.sn) === e.detail.markerId)
// 根据坐标返回详细地址
let _this = this let _this = this
_this.moveToLocation(Number(data[data['type']].elat), Number(data[data['type']].elng)) _this.moveToLocation(Number(data[data['type']].elat), Number(data[data['type']].elng))
if (data[data['type']].transferAddress) {
_this.setData({ _this.setData({
isShowCarInfoWindow: true, isShowCarInfoWindow: true,
carInfoWindowObj: data, carInfoWindowObj: data,
}) })
return
}
wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ data[data['type']].elat + ',' + data[data['type']].elng,
success: res => {
if (res.statusCode === 200) {
data[data['type']].transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough)
_this.setData({
carInfoWindowObj: data,
isShowCarInfoWindow: true
})
}
}
})
}, },
findCarClick() { findCarClick() {
wx.navigateBack({ wx.navigateBack({
...@@ -242,28 +224,21 @@ Page({ ...@@ -242,28 +224,21 @@ Page({
markers: markers markers: markers
}) })
this.moveToLocation(Number(this.data.carInfoWindowObj['bsLocation'].elat), Number(this.data.carInfoWindowObj['bsLocation'].elng)) this.moveToLocation(Number(this.data.carInfoWindowObj['bsLocation'].elat), Number(this.data.carInfoWindowObj['bsLocation'].elng))
if (this.data.carInfoWindowObj['bsLocation'].transferAddress) return break
}
},
async getTransferAddress(data, typeItem) {
new Promise(async reslove => {
wx.request({ wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ this.data.carInfoWindowObj['bsLocation'].elat + ',' + this.data.carInfoWindowObj['bsLocation'].elng, url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ data[typeItem].elat + ',' + data[typeItem].elng,
success: res => { success: res => {
if (res.statusCode === 200) { if (res.statusCode === 200) {
let transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) data[typeItem].transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough)
data['bsLocation'].transferAddress = transferAddress reslove()
carInfoArr.forEach(val => {
if (val.sn === this.data.carInfoWindowObj.sn) {
val.type = 'bsLocation'
val['bsLocation'].transferAddress = transferAddress
}
})
this.setData({
carInfoWindowObj: data,
carInfoArr: carInfoArr
})
} }
} }
}) })
break })
}
}, },
moveToLocation: function (latitude, longitude ) { moveToLocation: function (latitude, longitude ) {
this.myMap.getMapCtx().moveToLocation({ this.myMap.getMapCtx().moveToLocation({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!