From 51366c1fac89a3102cdc94c9b1668e32a9658ef8 Mon Sep 17 00:00:00 2001 From: XiaoXinPro 14 IAH5R <568170040@qq.com> Date: Fri, 17 Feb 2023 18:15:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index/index.js | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/index/index.js b/index/index.js index 76236f2..3b4274b 100644 --- a/index/index.js +++ b/index/index.js @@ -626,7 +626,30 @@ Page({ console.log(error); }, complete: finish => { + const latitudeNow = that.data.locateData.latitude + const longitudeNow = that.data.locateData.longitude + const mallLocationArr = [] + let index = 0 + that.data.shopList.forEach(item => { + const obj = { + latitude: item.latitude, + longitude: item.longitude, + mallTenantId: item.tenantId, + 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_str) + }) + console.log(isBest, 'isBest'); + const winer = isBest.bubbleSort() + console.log(winer, 'winer'); } }) @@ -667,8 +690,6 @@ Page({ return objData }, - - onShow: function () { this.mallSync() console.log(app.globalData.mouldType, "mouldType") @@ -1442,4 +1463,16 @@ Page({ } }; } -}); \ No newline at end of file +}); + +Array.prototype.bubbleSort = function () { + for (let i = 0; i < this.length - 1; i += 1) { + for (let j = 0; j < this.length - 1 - i; j += 1) { + if (this[j] > this[j + 1]) { + const temp = this[j]; + this[j] = this[j + 1]; + this[j + 1] = temp; + } + } + } +} \ No newline at end of file