Commit 48fc6a15 by zhangxw

找车页面修改

1 parent 648a9ae2
...@@ -74,92 +74,74 @@ Page({ ...@@ -74,92 +74,74 @@ 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 => { if (res.code == 200) {
this.setData({ let [markers, includePoints] = [[], []]
isLoading: false if (res.data.length > 0 ) {
}) for (var i = 0; i < res.data.length; i++) {
if (res.code == 200) { markers.push({
let [markers, includePoints] = [[], []] id: Number(res.data[i].sn), // 设备号唯一 可作为markerid
if (res.data.length > 0) { width: 28,
res.data.forEach(item => { height: 36,
markers.push({ latitude: Number(res.data[i]['gpsLocation'].elat), // 默认显示GPS定位位置
id: Number(item.sn), // 设备号唯一 可作为markerid longitude: Number(res.data[i]['gpsLocation'].elng),
width: 28, iconPath: res.data[i].source === 1 ? '../../images/oncar.png' : '../../images/offcar.png'
height: 36,
latitude: Number(item['gpsLocation'].elat), // 默认显示GPS定位位置
longitude: Number(item['gpsLocation'].elng),
iconPath: item.source === 1 ? '../../images/oncar.png' : '../../images/offcar.png'
})
includePoints.push({
latitude: item['gpsLocation'].elat,
longitude: item['gpsLocation'].elng,
padding: [80, 80, 80, 80]
})
item.type = 'gpsLocation' // 默认显示GPS的定位类型
}) })
this.myMap.setData({ // 防止页面跳转回退页面未保留用户的操作 用mapContext 会有问题 includePoints.push({
inPoints: includePoints latitude: res.data[i]['gpsLocation'].elat,
longitude: res.data[i]['gpsLocation'].elng,
padding: [80, 80, 80, 80]
}) })
wx.getSystemInfo({ res.data[i].type = 'gpsLocation' // 默认显示GPS的定位类型
success: (res) => { let typeArr = ['gpsLocation', 'bsLocation']
if (res.platform == 'devtools') { // 开发工具上include-points 失效 for (var j = 0; j < typeArr.length; j++) {
await this.getTransferAddress(res.data[i], typeArr[j])
}
}
this.setData({
carInfoArr: res.data,
includePoints: includePoints,
markers: markers
})
wx.getSystemInfo({
success: (res) => {
console.log(res)
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]
}) })
} else { } else {
this.myMap.setData({ // 防止页面跳转回退页面未保留用户的操作 用mapContext 会有问题 this.myMap.setData({ // 防止页面跳转回退页面未保留用户的操作 用mapContext 会有问题
inPoints: includePoints inPoints: includePoints
}) })
}
} }
}) }
this.setData({ })
carInfoArr: res.data, } else {
includePoints: includePoints, wx.showModal({
markers: markers content: '暂无数据',
}) showCancel: false
} else { })
wx.showModal({
content: '暂无数据',
showCancel: false
})
}
} }
}) }
} }
}, },
// 显示对应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() {
...@@ -242,29 +224,22 @@ Page({ ...@@ -242,29 +224,22 @@ 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
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,
success: res => {
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['bsLocation'].transferAddress = transferAddress
carInfoArr.forEach(val => {
if (val.sn === this.data.carInfoWindowObj.sn) {
val.type = 'bsLocation'
val['bsLocation'].transferAddress = transferAddress
}
})
this.setData({
carInfoWindowObj: data,
carInfoArr: carInfoArr
})
}
}
})
break break
} }
}, },
async getTransferAddress(data, typeItem) {
new Promise(async reslove => {
wx.request({
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 => {
if (res.statusCode === 200) {
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)
reslove()
}
}
})
})
},
moveToLocation: function (latitude, longitude ) { moveToLocation: function (latitude, longitude ) {
this.myMap.getMapCtx().moveToLocation({ this.myMap.getMapCtx().moveToLocation({
longitude: Number(longitude), longitude: Number(longitude),
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!