|
|
@@ -9,61 +9,23 @@ definePage({
|
|
|
navigationBarTitleText: '选择收获地址',
|
|
|
},
|
|
|
})
|
|
|
-const { SelectShopInfo } = storeToRefs(useSysXsbStore())
|
|
|
-const { name, Location } = storeToRefs(useAddressStore())
|
|
|
-const nearbyAddress = ref<Api.xsbShopList>()
|
|
|
+const { SelectShopInfo, xsbShopList: shopList } = storeToRefs(useSysXsbStore())
|
|
|
+const { name } = storeToRefs(useAddressStore())
|
|
|
|
|
|
-const { data: shopList } = useRequest(() => Apis.xsb.shopList({})).onSuccess(() => {
|
|
|
- if (!Location.value.longitude || !Location.value.latitude || !shopList.value) {
|
|
|
- return null
|
|
|
- }
|
|
|
-
|
|
|
- const getDistance = (lat1: number, lng1: number, lat2: number, lng2: number): number => {
|
|
|
- const R = 6371 // 地球半径(公里)
|
|
|
- const dLat = (lat2 - lat1) * Math.PI / 180
|
|
|
- const dLng = (lng2 - lng1) * Math.PI / 180
|
|
|
- const a
|
|
|
- = Math.sin(dLat / 2) * Math.sin(dLat / 2)
|
|
|
- + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180)
|
|
|
- * Math.sin(dLng / 2) * Math.sin(dLng / 2)
|
|
|
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
|
- return R * c // 距离(公里)
|
|
|
- }
|
|
|
-
|
|
|
- let minDistance = Infinity
|
|
|
-
|
|
|
- for (const shop of shopList.value) {
|
|
|
- if (shop.shopLat && shop.shopLng) {
|
|
|
- const distance = getDistance(
|
|
|
- Location.value.latitude,
|
|
|
- Location.value.longitude,
|
|
|
- Number(shop.shopLat),
|
|
|
- Number(shop.shopLng),
|
|
|
- )
|
|
|
-
|
|
|
- if (distance < minDistance) {
|
|
|
- minDistance = distance
|
|
|
- nearbyAddress.value = { ...shop, distance: Number(distance.toFixed(2)) }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-})
|
|
|
const selectAddressId = ref()
|
|
|
|
|
|
const allShopList = computed(() => {
|
|
|
- return shopList.value?.filter(it => it.shopId !== nearbyAddress.value?.shopId)
|
|
|
+ return shopList.value?.filter(it => it.shopId !== SelectShopInfo.value?.shopId)
|
|
|
+})
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ useSysXsbStore().getAllShopList()
|
|
|
})
|
|
|
|
|
|
function handleClick(item: Api.xsbShopList) {
|
|
|
SelectShopInfo.value = item
|
|
|
router.back()
|
|
|
}
|
|
|
-
|
|
|
-onUnload(() => {
|
|
|
- if (!SelectShopInfo.value?.shopId) {
|
|
|
- SelectShopInfo.value = nearbyAddress.value
|
|
|
- }
|
|
|
-})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -76,7 +38,7 @@ onUnload(() => {
|
|
|
<view class="flex items-center">
|
|
|
<image :src="`${StaticUrl}/location-black.png`" class="h33.8rpx min-w28.97rpx w28.97rpx" />
|
|
|
<view class="ml18rpx max-w-380rpx truncate text-32rpx">
|
|
|
- {{ name }}
|
|
|
+ {{ name == '请选择位置' ? SelectShopInfo.shopName : name }}
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="flex items-center text-24rpx text-#1A8DFF" @click="useAddressStore().getMapAddress">
|
|
|
@@ -111,12 +73,12 @@ onUnload(() => {
|
|
|
</wd-radio-group>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view v-if="nearbyAddress" class="mt20rpx rounded-16rpx bg-white px24rpx py28rpx" @click="handleClick(nearbyAddress)">
|
|
|
+ <view v-if="SelectShopInfo" class="mt20rpx rounded-16rpx bg-white px24rpx py28rpx" @click="handleClick(SelectShopInfo)">
|
|
|
<view class="text-24rpx text-#AAAAAA">
|
|
|
附近的门店
|
|
|
</view>
|
|
|
<view class="mt24rpx text-28rpx font-semibold">
|
|
|
- {{ nearbyAddress?.shopName }}
|
|
|
+ {{ SelectShopInfo?.shopName }}
|
|
|
</view>
|
|
|
<view class="mt16rpx text-24rpx text-#AAAAAA">
|
|
|
以为您选择距离最近的可配送店
|