shinnosuke
2026-08-24 43e3f1fd39512310c0c097781e8a0f739cd115e5
fix: sync merchant addresses with map locations
1个文件已修改
40 ■■■■■ 已修改文件
talent-card-admin/src/views/MerchantCreateView.vue 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
talent-card-admin/src/views/MerchantCreateView.vue
@@ -1001,7 +1001,7 @@
  amapApi = await loadAMapApi({
    key,
    version: '2.0',
    plugins: ['AMap.PlaceSearch', 'AMap.Scale', 'AMap.ToolBar'],
    plugins: ['AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.Scale', 'AMap.ToolBar'],
  })
  return amapApi
}
@@ -1231,7 +1231,12 @@
    })
    locationMap.addControl(new AMap.Scale())
    locationMap.addControl(new AMap.ToolBar({ position: { right: '10px', top: '10px' } }))
    locationMap.on('click', (event: any) => setMapMarker(event.lnglat.getLat(), event.lnglat.getLng(), false))
    locationMap.on('click', (event: any) => {
      const latitude = event.lnglat.getLat()
      const longitude = event.lnglat.getLng()
      setMapMarker(latitude, longitude, false)
      reverseGeocodeLocation(latitude, longitude)
    })
    if (selected) setMapMarker(initial.latitude, initial.longitude, false)
    window.setTimeout(() => locationMap?.resize(), 120)
  } catch (error) {
@@ -1269,10 +1274,39 @@
function selectSearchLocation(item: { name: string; longitude: number; latitude: number }) {
  setMapMarker(item.latitude, item.longitude)
  if (!form.address?.trim()) form.address = item.name
  setLocationAddress(item.name)
  locationSearchResults.value = []
}
function setLocationAddress(address: string) {
  const normalizedAddress = address.trim()
  if (!normalizedAddress) return
  if (activeParkingAddress.value) {
    activeParkingAddress.value.address = normalizedAddress
  } else if (activeSchoolAddress.value) {
    activeSchoolAddress.value.address = normalizedAddress
  } else if (activeFuelStore.value) {
    activeFuelStore.value.address = normalizedAddress
  } else {
    form.address = normalizedAddress
  }
  locationSearch.value = normalizedAddress
}
async function reverseGeocodeLocation(latitude: number, longitude: number) {
  try {
    const AMap = await loadAMap()
    const geocoder = new AMap.Geocoder({ radius: 1000, extensions: 'all' })
    geocoder.getAddress([longitude, latitude], (status: string, result: any) => {
      if (status === 'complete' && result?.regeocode?.formattedAddress) {
        setLocationAddress(result.regeocode.formattedAddress)
      }
    })
  } catch (error) {
    console.warn('Failed to reverse geocode AMap location', error)
  }
}
function closeLocationMap() {
  locationMap?.destroy()
  locationMap = undefined