From d9a214ff263c1bea8bfd62fa61b3df128c3e1637 Mon Sep 17 00:00:00 2001 From: XiaoXinPro 14 IAH5R <568170040@qq.com> Date: Mon, 20 Feb 2023 10:42:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E5=88=B0=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E7=9A=84=E5=B9=BF=E5=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index/index.js | 39 ++++++++++++++++++++++++--------------- index/index.ttss | 3 +++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/index/index.js b/index/index.js index 6741b45..49b4b34 100644 --- a/index/index.js +++ b/index/index.js @@ -158,9 +158,9 @@ Page({ }) }, - bindPickerChange(e) { - const index = e.detail.value - const mallTenantId = this.data.shopList[index].tenantId + bindPickerChange(e, indexIn, id) { + const index = indexIn || e.detail.value + const mallTenantId = id || this.data.shopList[index].tenantId tt.setStorageSync('mallTenantId', mallTenantId) tt.setStorageSync('mallIndex', index) this.setData({ @@ -630,8 +630,8 @@ Page({ const longitudeNow = that.data.locateData.longitude const mallLocationArr = [] - let index = 0 - that.data.shopList.forEach(item => { + + that.data.shopList.forEach((item, index) => { const obj = { latitude: item.latitude, longitude: item.longitude, @@ -639,17 +639,28 @@ Page({ index: index } mallLocationArr.push(obj) - index++ }) - const isBest = [] - mallLocationArr.forEach(item => { - const num = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude) - isBest.push(num.distance) + const tempArr = that.data.shopList + const bloobArr = [] + mallLocationArr.forEach((item, index) => { + const distanceData = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude) + 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(isBest, 'isBest'); - const winer = this.bloob(isBest) - console.log(winer, 'winer'); + console.log(nearestArr[0], 'nearestArr'); } }) @@ -697,9 +708,7 @@ Page({ let temp = tempArr[j]; tempArr[j] = tempArr[j + 1]; tempArr[j + 1] = temp; - } - } } return tempArr diff --git a/index/index.ttss b/index/index.ttss index e896974..e4d1e18 100644 --- a/index/index.ttss +++ b/index/index.ttss @@ -130,6 +130,9 @@ page { margin-right: 10rpx; } +.distance_str { + margin-left: 10rpx; +} .right { position: relative;