pyt
2025-02-26 403da33c30fc628c1608b96d95efdc12e70c3b06
H5/pages/location/location.vue
@@ -1,10 +1,8 @@
<template>
   <view class="content">
      <u-navbar title="选择地点" bgColor="transparent" titleStyle="font-size: 35rpx;font-weight:bold;" placeholder>
         <view slot="left" @click="back">
            <image src="/static/location/back.png" class="w-19 h-35" mode=""></image>
         </view>
      </u-navbar>
      <view slot="left" @click="back">
         <image src="/static/location/back.png" class="w-19 h-35" mode=""></image>
      </view>
      <view class="" id="container">
      </view>
@@ -24,8 +22,9 @@
         </view>
         <view class="card" @click="changeAdr(item.id,item)" :class="item.id ==uid ?'activecard':''"
            v-for="item in locationList" :key="item.id">
            <text>{{item.address}}</text>
            <text class="font-w500 fs-23 mt-25" style="color: rgba(0, 0, 0, 0.6);">{{item.address}}</text>
            <text>{{item.title || item.name}}</text>
            <text class="font-w500 fs-23 mt-25"
               style="color: rgba(0, 0, 0, 0.6);">{{item.address || item.name}}</text>
         </view>
      </view>
@@ -34,6 +33,9 @@
</template>
<script>
   import {
      searchLocation
   } from './service'
   export default {
      data() {
         return {
@@ -44,29 +46,35 @@
            keyword: '',
            locationList: [],
            city: '攀枝花市',
            markers:[],
            markers: [],
         };
      },
      methods: {
 clearMarkers() {
            // 清除所有标点
            this.markers.forEach((marker) => {
                this.map.removeOverlay(marker);
            });
            this.markers = []; // 清空存储标点的数组
        },
         clearMarkers() {
            // 清除所有标点
            this.markers.forEach((marker) => {
               this.map.removeOverlay(marker);
            });
            this.markers = []; // 清空存储标点的数组
         },
         back() {
            uni.navigateBack()
         },
         changeAdr(value, addr) {
            console.log(value, addr, 'asdasdada');
            this.uid = value
            const pages = getCurrentPages()
            let prevPage = pages[pages.length - 2];
            prevPage.location = addr.address
            prevPage.latitude = addr.point.lat
            prevPage.longitude = addr.point.lng
            if (addr.point) {
               prevPage.latitude = addr.point.lat
               prevPage.longitude = addr.point.lng
            }
            if (addr.location) {
               prevPage.latitude = addr.location.lat
               prevPage.longitude = addr.location.lng
            }
            prevPage.location = addr.address || addr.name
            setTimeout(() => {
               uni.navigateBack()
            }, 200)
@@ -74,6 +82,24 @@
         // 搜索地点
         searchLocation() {
            if (!this.keyword) return;
            searchLocation({
               query: this.keyword,
               location: `${this.latitude},${this.longitude }`,
            }).then(res => {
               if (res.code == 200) {
                  this.searchResults = res.data;
                  if (res.data.length > 0) {
                     this.latitude = res.data[0].location.lat
                     this.longitude = res.data[0].location.lng
                  }
                  this.locationList = res.data.map((result, index) => {
                     result.id = index + 1
                     return result
                  });
                  console.log(this.locationList);
               }
            })
            return
            uni.request({
               url: `https://api.map.baidu.com/place/v2/search`,
               method: 'GET',
@@ -165,7 +191,7 @@
               item.id = index + 1
               return item
            })
            console.log(this.locationList);
         })
         this.map.addEventListener('click', (e) => {
            this.clearMarkers()