{"ast":null,"code":"import { searchFun } from '@/utils/map';\nimport { leftCopy } from '@/utils/common';\nexport default {\n name: \"addressMap\",\n data() {\n return {\n map: '',\n mapPosition: 60,\n source: '',\n keyword: '',\n addressList: [],\n activeIndex: null,\n marker: null\n };\n },\n watch: {\n keyword() {\n this.searchHandler();\n }\n },\n created() {\n this.source = this.$route.query.source || '';\n },\n async mounted() {\n await this.initMap();\n },\n methods: {\n chooseHandler(item, index) {\n this.activeIndex = index;\n this.addMarker();\n },\n addMarker() {\n if (this.marker) {\n this.map.remove(this.marker);\n }\n let content = '
';\n let activeObj = this.addressList[this.activeIndex];\n this.marker = new AMap.Marker({\n position: new AMap.LngLat(activeObj.location.lng, activeObj.location.lat),\n content: content,\n offset: new AMap.Pixel(-13, -30)\n });\n this.map.add(this.marker);\n },\n // 取消 返回上一页\n cancelHandler() {\n this.$router.go(-1);\n },\n // 完成 选择了事发地或者目的地\n async successHandler() {\n if (this.activeIndex == null) {\n this.$toast('请选择具体地址');\n return;\n }\n let activeObj = this.addressList[this.activeIndex];\n if (this.source == 'address') {\n // 事发地地址\n await this.$store.dispatch('order/setServerCity', activeObj.district);\n await this.$store.dispatch('order/setAddress', {\n startPoiAddress: activeObj.district + activeObj.address + activeObj.name,\n startLat: activeObj.location.lat,\n startLng: activeObj.location.lng\n });\n } else if (this.source == 'dest') {\n // 目的地地址\n await this.$store.dispatch('order/setDestAddress', {\n endLat: activeObj.location.lat,\n endLng: activeObj.location.lng,\n endPoiAddress: activeObj.district + activeObj.address + activeObj.name\n });\n }\n this.$router.go(-1);\n },\n initMap() {\n // 初始化地图\n let orderInfo = this.$store.getters.order.localAddress;\n this.map = new AMap.Map('mapId', {\n viewMode: '2D',\n // 默认使用 2D 模式\n zoom: 11,\n //初始化地图层级\n center: [orderInfo.lng, orderInfo.lat] //初始化地图中心点\n });\n },\n\n async searchHandler() {\n // 根据当前定位城市搜索,将选中的地址清空\n let localCityCode = this.$store.getters.order.localAddress.localCityCode;\n this.activeIndex = null;\n if (this.keyword) {\n this.addressList = await searchFun(this.map, localCityCode, this.keyword);\n } else {\n this.addressList = [];\n }\n }\n }\n};","map":{"version":3,"names":["searchFun","leftCopy","name","data","map","mapPosition","source","keyword","addressList","activeIndex","marker","watch","searchHandler","created","$route","query","mounted","initMap","methods","chooseHandler","item","index","addMarker","remove","content","activeObj","AMap","Marker","position","LngLat","location","lng","lat","offset","Pixel","add","cancelHandler","$router","go","successHandler","$toast","$store","dispatch","district","startPoiAddress","address","startLat","startLng","endLat","endLng","endPoiAddress","orderInfo","getters","order","localAddress","Map","viewMode","zoom","center","localCityCode"],"sources":["src/views/index/addressMap.vue"],"sourcesContent":["\r\n