Commit 48fc6a15 by zhangxw

找车页面修改

1 parent 648a9ae2
......@@ -74,42 +74,46 @@ Page({
getData() {
this.getVehicleData()
},
getVehicleData(){
async getVehicleData(){
if(this.data.sns){
this.setData({
isLoading: true
})
WXRequest.get('trialdrive/api/vehicle/location', {
sns: decodeURIComponent(this.data.sns)
}, true).then(res => {
this.setData({
isLoading: false
})
let res = await WXRequest.get('trialdrive/api/vehicle/location', {sns: decodeURIComponent(this.data.sns)}, true)
if (res) this.setData({isLoading: false})
if (res.code == 200) {
let [markers, includePoints] = [[], []]
if (res.data.length > 0) {
res.data.forEach(item => {
if (res.data.length > 0 ) {
for (var i = 0; i < res.data.length; i++) {
markers.push({
id: Number(item.sn), // 设备号唯一 可作为markerid
id: Number(res.data[i].sn), // 设备号唯一 可作为markerid
width: 28,
height: 36,
latitude: Number(item['gpsLocation'].elat), // 默认显示GPS定位位置
longitude: Number(item['gpsLocation'].elng),
iconPath: item.source === 1 ? '../../images/oncar.png' : '../../images/offcar.png'
latitude: Number(res.data[i]['gpsLocation'].elat), // 默认显示GPS定位位置
longitude: Number(res.data[i]['gpsLocation'].elng),
iconPath: res.data[i].source === 1 ? '../../images/oncar.png' : '../../images/offcar.png'
})
includePoints.push({
latitude: item['gpsLocation'].elat,
longitude: item['gpsLocation'].elng,
latitude: res.data[i]['gpsLocation'].elat,
longitude: res.data[i]['gpsLocation'].elng,
padding: [80, 80, 80, 80]
})
item.type = 'gpsLocation' // 默认显示GPS的定位类型
})
this.myMap.setData({ // 防止页面跳转回退页面未保留用户的操作 用mapContext 会有问题
inPoints: includePoints
res.data[i].type = 'gpsLocation' // 默认显示GPS的定位类型
let typeArr = ['gpsLocation', 'bsLocation']
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({
points: includePoints,
padding: [80, 80, 80, 80]
......@@ -121,11 +125,6 @@ Page({
}
}
})
this.setData({
carInfoArr: res.data,
includePoints: includePoints,
markers: markers
})
} else {
wx.showModal({
content: '暂无数据',
......@@ -133,34 +132,17 @@ Page({
})
}
}
})
}
},
// 显示对应marker详情
getCarInfoWindowObj(e) {
let data = this.data.carInfoArr.find(item => Number(item.sn) === e.detail.markerId)
// 根据坐标返回详细地址
let _this = this
_this.moveToLocation(Number(data[data['type']].elat), Number(data[data['type']].elng))
if (data[data['type']].transferAddress) {
_this.setData({
isShowCarInfoWindow: true,
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() {
wx.navigateBack({
......@@ -242,28 +224,21 @@ Page({
markers: markers
})
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({
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 => {
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
})
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()
}
}
})
break
}
})
},
moveToLocation: function (latitude, longitude ) {
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!