You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
import {
|
|
axios
|
|
} from './libs'
|
|
let cities = []
|
|
const init = async () => {
|
|
const db = wx.cloud.database()
|
|
const [{
|
|
data: {
|
|
value: cityIndexMap
|
|
}
|
|
}, malls] = await Promise.all([db.collection('config').doc('cityIndexMap').get(), axios.get('/Api/Coupon/MallList')])
|
|
cities = Object.values(malls.reduce((acc, nxt) => {
|
|
const mall = {
|
|
name: nxt.name,
|
|
code: nxt.mallCode
|
|
}
|
|
if (acc[nxt.areaName]) {
|
|
acc[nxt.areaName].malls.push(mall)
|
|
} else acc[nxt.areaName] = {
|
|
name: nxt.areaName,
|
|
malls: [mall],
|
|
index: cityIndexMap[nxt.areaName]
|
|
}
|
|
return acc
|
|
}, {}))
|
|
cities.sort((a, b) => a.index.charCodeAt(0) - b.index.charCodeAt(0))
|
|
|
|
}
|
|
export const getCities = async () => {
|
|
if (!cities.length) {
|
|
await init()
|
|
return cities
|
|
} else return cities
|
|
}
|
|
|
|
|
|
const toRadians = lonlat => lonlat / 180 * Math.PI;
|
|
const ToDigits = radian => radian / Math.PI * 180;
|
|
const R = 6371
|
|
const r = 50
|
|
const offset = Math.asin(r / 2 / R) * 2
|
|
const getRestrict = (lon, lat) => {
|
|
const lonR = toRadians(lon)
|
|
const latR = toRadians(lat)
|
|
return [lonR - offset, lonR + offset, latR - offset, latR + offset].map(ToDigits)
|
|
}
|
|
const getMall = ([minLon, maxLon, minLat, maxLat]) =>
|
|
new Promise(resolve => {
|
|
|
|
})
|
|
|
|
export const getNearMall = async ({
|
|
longitude,
|
|
latitude
|
|
}) => {
|
|
const restrict = getRestrict(longitude, latitude)
|
|
return (await getCities())[0]
|
|
}
|