|
|
@@ -118,7 +118,7 @@ Page({ |
|
|
|
shopList: [], |
|
|
|
mallTenantId: tt.getStorageSync('mallTenantId') || '', |
|
|
|
index: tt.getStorageSync('mallIndex') || 0, |
|
|
|
locateData: {} |
|
|
|
locateData: {}, |
|
|
|
}, |
|
|
|
|
|
|
|
getCongig() { //获取小程序是否开通授权手机号 |
|
|
@@ -143,7 +143,7 @@ Page({ |
|
|
|
|
|
|
|
getsubMallList() { |
|
|
|
Http.get({ |
|
|
|
url: '/mall/subMall?isAll=1', |
|
|
|
url: '/mall/subMall?isAll=0', |
|
|
|
}).then(res => { |
|
|
|
tt.setStorageSync('shopList', JSON.stringify(res.data)); |
|
|
|
this.setData({ |
|
|
@@ -161,7 +161,8 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
bindPickerChange(e, indexIn, id) { |
|
|
|
const index = indexIn || e.detail.value |
|
|
|
const index = e ? e.detail.value : indexIn |
|
|
|
|
|
|
|
const mallTenantId = id || this.data.shopList[index].tenantId |
|
|
|
tt.setStorageSync('mallTenantId', mallTenantId) |
|
|
|
tt.setStorageSync('mallIndex', index) |
|
|
@@ -571,7 +572,6 @@ Page({ |
|
|
|
* 生命周期函数--监听页面初次渲染完成 |
|
|
|
*/ |
|
|
|
onLoad: function (options) { |
|
|
|
|
|
|
|
let that = this; |
|
|
|
let optionss; |
|
|
|
|
|
|
@@ -607,6 +607,7 @@ Page({ |
|
|
|
// isHighAccuracy: true, |
|
|
|
success: function (res) { |
|
|
|
console.log(res, 'getLocation') |
|
|
|
|
|
|
|
const locateData = { |
|
|
|
latitude: res.latitude, |
|
|
|
longitude: res.longitude, |
|
|
@@ -623,57 +624,78 @@ Page({ |
|
|
|
city: res.city |
|
|
|
} |
|
|
|
}).then(res => { |
|
|
|
this.getsubMallList() |
|
|
|
console.log(res, 9999) |
|
|
|
// 获取到的用户的坐标 |
|
|
|
const latitudeNow = that.data.locateData.latitude |
|
|
|
const longitudeNow = that.data.locateData.longitude |
|
|
|
|
|
|
|
const mallLocationArr = [] |
|
|
|
|
|
|
|
const shopList = JSON.parse(tt.getStorageSync('shopList')); |
|
|
|
|
|
|
|
shopList.forEach((item, index) => { |
|
|
|
const obj = { |
|
|
|
latitude: item.latitude, |
|
|
|
longitude: item.longitude, |
|
|
|
mallTenantId: item.tenantId, |
|
|
|
index: index |
|
|
|
} |
|
|
|
mallLocationArr.push(obj) |
|
|
|
}) |
|
|
|
|
|
|
|
console.log(mallLocationArr, 'mallLocationArr'); |
|
|
|
|
|
|
|
const tempArr = shopList |
|
|
|
const bloobArr = [] |
|
|
|
|
|
|
|
// 调整广场列表数据 |
|
|
|
mallLocationArr.forEach((item, index) => { |
|
|
|
const distanceData = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude) |
|
|
|
tempArr[index].distance_str = distanceData.distance_str |
|
|
|
tempArr[index].distanceName = tempArr[index].name + ' ' + distanceData.distance_str |
|
|
|
tempArr[index].distance = distanceData.distance |
|
|
|
bloobArr.push(distanceData.distance) |
|
|
|
}) |
|
|
|
that.setData({ |
|
|
|
shopList: tempArr |
|
|
|
}) |
|
|
|
|
|
|
|
// 通过排序获取最近广场 |
|
|
|
const nearestDistance = that.bloob(bloobArr)[0] |
|
|
|
const nearestArr = that.data.shopList.filter((item, index) => { |
|
|
|
// 切换至最近的广场 |
|
|
|
const locationFlag = tt.getStorageSync('locationFlag'); |
|
|
|
if ((item.distance == nearestDistance)) { |
|
|
|
that.bindPickerChange('', index, item.tenantId) |
|
|
|
tt.setStorageSync('locationFlag', false); |
|
|
|
return true |
|
|
|
} else { |
|
|
|
return false |
|
|
|
} |
|
|
|
}) |
|
|
|
console.log(nearestArr[0], 'nearestArr'); |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: error => { |
|
|
|
console.log(error); |
|
|
|
}, |
|
|
|
complete: finish => { |
|
|
|
// 获取到的用户的坐标 |
|
|
|
const latitudeNow = that.data.locateData.latitude |
|
|
|
const longitudeNow = that.data.locateData.longitude |
|
|
|
|
|
|
|
const mallLocationArr = [] |
|
|
|
|
|
|
|
const shopList = JSON.parse(tt.getStorageSync('shopList')); |
|
|
|
|
|
|
|
let obj = {} |
|
|
|
shopList.forEach((item, index) => { |
|
|
|
const obj = { |
|
|
|
latitude: item.latitude, |
|
|
|
longitude: item.longitude, |
|
|
|
mallTenantId: item.tenantId, |
|
|
|
index: index |
|
|
|
if (item.defaultSign == 1) { |
|
|
|
const tempObj = { |
|
|
|
index: index, |
|
|
|
tenantId: item.tenantId |
|
|
|
} |
|
|
|
obj = tempObj |
|
|
|
return |
|
|
|
} |
|
|
|
mallLocationArr.push(obj) |
|
|
|
}) |
|
|
|
console.log(obj, 'obj'); |
|
|
|
that.bindPickerChange('', obj.index, obj.tenantId) |
|
|
|
}, |
|
|
|
complete: finish => { |
|
|
|
|
|
|
|
console.log(mallLocationArr, 'mallLocationArr'); |
|
|
|
|
|
|
|
const tempArr = shopList |
|
|
|
const bloobArr = [] |
|
|
|
mallLocationArr.forEach((item, index) => { |
|
|
|
const distanceData = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude) |
|
|
|
tempArr[index].distance_str = distanceData.distance_str |
|
|
|
|
|
|
|
tempArr[index].distance = distanceData.distance |
|
|
|
bloobArr.push(distanceData.distance) |
|
|
|
}) |
|
|
|
that.setData({ |
|
|
|
shopList: tempArr |
|
|
|
}) |
|
|
|
const nearestDistance = that.bloob(bloobArr)[0] |
|
|
|
const nearestArr = that.data.shopList.filter((item, index) => { |
|
|
|
if (item.distance == nearestDistance) { |
|
|
|
that.bindPickerChange('', index, item.tenantId) |
|
|
|
return true |
|
|
|
} else { |
|
|
|
return false |
|
|
|
} |
|
|
|
}) |
|
|
|
console.log(nearestArr[0], 'nearestArr'); |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
@@ -702,6 +724,8 @@ Page({ |
|
|
|
|
|
|
|
if (parseInt(distance) >= 1) { |
|
|
|
distance_str = distance.toFixed(2) + "km"; |
|
|
|
} else if (!arseInt(distance)) { |
|
|
|
return false |
|
|
|
} else { |
|
|
|
distance_str = (distance * 1000).toFixed(2) + "m"; |
|
|
|
} |
|
|
|