diff --git a/app.js b/app.js index 0eea595..a56173b 100644 --- a/app.js +++ b/app.js @@ -24,7 +24,7 @@ App({ }, onLaunch: function () { let that = this - + tt.setStorageSync('locationFlag', true); try { var res = tt.getSystemInfoSync(); that.statusBarHeight = res.statusBarHeight diff --git a/index/index.js b/index/index.js index 009465a..801be3e 100644 --- a/index/index.js +++ b/index/index.js @@ -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"; } diff --git a/index/index.ttml b/index/index.ttml index 3b84a9d..7c0c1d6 100644 --- a/index/index.ttml +++ b/index/index.ttml @@ -17,14 +17,31 @@ --> - + + + + + + + {{ shopList[index].name }} + 距您{{ + shopList[index].distance_str}} + + + + + + + + {{ shopList[index].name }} - 距您{{ + 距您{{ shopList[index].distance_str}} diff --git a/pages/couponorder/detail/index.ttml b/pages/couponorder/detail/index.ttml index 039b2d6..dc665b5 100644 --- a/pages/couponorder/detail/index.ttml +++ b/pages/couponorder/detail/index.ttml @@ -65,9 +65,9 @@ 购买须知 - {{data.remark}} + {{data.remark}} - + diff --git a/pages/couponorder/index/index.js b/pages/couponorder/index/index.js index 746dca0..42b2e59 100644 --- a/pages/couponorder/index/index.js +++ b/pages/couponorder/index/index.js @@ -141,7 +141,7 @@ Page({ onLoad: function (options) { this.mallSync() Http.get({ - url: '/mall/subMall?isAll=1', + url: '/mall/subMall?isAll=0', }).then(res => { this.setData({ shopList: res.data, diff --git a/pages/order/index/index.js b/pages/order/index/index.js index 9d56643..3868374 100644 --- a/pages/order/index/index.js +++ b/pages/order/index/index.js @@ -106,7 +106,7 @@ Page({ onLoad(e) { Http.get({ - url: '/mall/subMall?isAll=1', + url: '/mall/subMall?isAll=0', }).then(res => { this.setData({ shopList: res.data,