Commit 4e9e706e by 前端

Merge branch 'change-map' into 'master'

上线合并

See merge request !2
2 parents 5848fd4c 90922fef
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-11-25 20:11:22
* @LastEditors: limin
* @LastEditTime: 2020-11-25 20:29:36
*/
export default function loadMap ({key='qRLkZJN32WsQe2LMSTjduuTs2TObie3x', v = '3.0'}={}) {
return new Promise(function (resolve, reject) {
if (typeof BMap !== 'undefined') {
resolve(BMap)
return true
}
window.onCallback = function () {
resolve(BMap)
}
let script = document.createElement('script')
script.type = 'text/javascript'
script.src = `//api.map.baidu.com/api?v=${v}&ak=${key}&callback=onCallback`
script.onerror = reject
document.head.appendChild(script)
})
}
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
> >
<span :class="[hasLocation ? 'error map-txt' : 'error', isEdit ? 'mapTips-edit': 'mapTips']">{{i.value}}</span> <span :class="[hasLocation ? 'error map-txt' : 'error', isEdit ? 'mapTips-edit': 'mapTips']">{{i.value}}</span>
<gl-button v-if="isEdit && i.label == 'POI位置点'" class="mapTips-button" @click="markAddr(isMarkAddr = true)">标记位置点</gl-button> <gl-button v-if="isEdit && i.label == 'POI位置点'" class="mapTips-button" @click="markAddr(isMarkAddr = true)">标记位置点</gl-button>
<el-amap <!-- <el-amap
vid='amapDemo' vid='amapDemo'
:center='center' :center='center'
:amap-manager='amapManager' :amap-manager='amapManager'
...@@ -50,7 +50,9 @@ ...@@ -50,7 +50,9 @@
:events='events' :events='events'
class='amap-demo' class='amap-demo'
> >
</el-amap> </el-amap> -->
<div id="container"
class='amap-demo'></div>
</div> </div>
<span v-else-if="i.isImg"> <span v-else-if="i.isImg">
<img <img
...@@ -155,20 +157,21 @@ ...@@ -155,20 +157,21 @@
</template> </template>
<script> <script>
import VueAMap from 'vue-amap' // import VueAMap from 'vue-amap'
import Vue from 'vue' import Vue from 'vue'
import axios from 'axios' import axios from 'axios'
import qs from 'qs' import qs from 'qs'
import { businessManagenMethods, bizMethods, request } from '@/api' import { businessManagenMethods, bizMethods, request } from '@/api'
import loadBMap from '@/common/loadBmap'
import notice from '@/common/notice' import notice from '@/common/notice'
var marker = [] var marker = []
const amapManager = new VueAMap.AMapManager() // const amapManager = new VueAMap.AMapManager()
VueAMap.initAMapApiLoader({ // VueAMap.initAMapApiLoader({
key: '44cc16e43ad7ed3358df507bd0618181', // key: '44cc16e43ad7ed3358df507bd0618181',
plugin: ['AMap.Geocoder'], // plugin: ['AMap.Geocoder'],
uiVersion: '1.0' // uiVersion: '1.0'
}) // })
Vue.use(VueAMap) // Vue.use(VueAMap)
export default { export default {
name: 'BusinessDetails', name: 'BusinessDetails',
data() { data() {
...@@ -244,8 +247,9 @@ export default { ...@@ -244,8 +247,9 @@ export default {
isMap: true isMap: true
} }
], ],
amapManager, // amapManager,
zoom: 12, zoom: 12,
map: null,
// 地图中心点(初始化得有值);也是标记点 // 地图中心点(初始化得有值);也是标记点
center: [113.939723, 22.525351], center: [113.939723, 22.525351],
events: { events: {
...@@ -401,6 +405,28 @@ export default { ...@@ -401,6 +405,28 @@ export default {
}) })
}, },
methods: { methods: {
intiBMap(lng = 103.048078, lat = 36.383814) {
var that = this
loadBMap().then(BMap => {
that.map = new BMap.Map('container')
that.map.clearOverlays()
var point = new BMap.Point(Number(lng), Number(lat))
that.map.centerAndZoom(point, this.zoom)
that.map.addEventListener("tilesloaded", function() {
that.assignBasicInfo()
that.map.panTo(point)
});
that.map.addEventListener('click', function(e) {
if (that.isMarkAddr) {
console.log(e)
that.map.clearOverlays()
that.merchantInfo.lng = e.point.lng
that.merchantInfo.lat = e.point.lat
that.getAddress(e.point.lng, e.point.lat)
}
})
})
},
back() { back() {
this.$parent.to(['商户数据平台', '商户数据管理', '商户数据', '商户列表管理', '商户数据列表']) this.$parent.to(['商户数据平台', '商户数据管理', '商户数据', '商户列表管理', '商户数据列表'])
}, },
...@@ -426,6 +452,13 @@ export default { ...@@ -426,6 +452,13 @@ export default {
this.merchantInfo.merchantPortrait = this.List[9].value this.merchantInfo.merchantPortrait = this.List[9].value
const params = this.$deep_clone(this.merchantInfo) const params = this.$deep_clone(this.merchantInfo)
delete params.merchantChannelName delete params.merchantChannelName
params.lat = params.lat.toFixed(6)
params.lng = params.lng.toFixed(6)
let attrList = Object.keys(params)
attrList.forEach(item => {
params[item] = params[item] || ''
})
console.log(params, 'params--')
params.method = bizMethods.MerchantModify params.method = bizMethods.MerchantModify
// console.log(params) // console.log(params)
request.req(params).then(res => { request.req(params).then(res => {
...@@ -440,10 +473,16 @@ export default { ...@@ -440,10 +473,16 @@ export default {
this.merchantInfo = JSON.parse(JSON.stringify(this.tempMerchantInfo)) this.merchantInfo = JSON.parse(JSON.stringify(this.tempMerchantInfo))
this.List[9].value = this.merchantInfo.merchantPortrait this.List[9].value = this.merchantInfo.merchantPortrait
if (!this.merchantInfo.lng && !this.merchantInfo.lat) { if (!this.merchantInfo.lng && !this.merchantInfo.lat) {
marker && amapManager._map.remove(marker) // marker && amapManager._map.remove(marker)
this.map.clearOverlays()
this.hasLocation = false this.hasLocation = false
this.List[10].value = '无位置信息' this.List[10].value = '无位置信息'
} else { } else {
this.List[10].value = this.merchantInfo.address
this.map.clearOverlays()
var point = new BMap.Point(this.merchantInfo.lng, this.merchantInfo.lat)
this.map.centerAndZoom(point, this.zoom)
this.map.panTo(point)
// this.getAddress(this.merchantInfo.lng, this.merchantInfo.lat) // this.getAddress(this.merchantInfo.lng, this.merchantInfo.lat)
} }
} }
...@@ -486,10 +525,9 @@ export default { ...@@ -486,10 +525,9 @@ export default {
params.method = bizMethods.Detail params.method = bizMethods.Detail
request.req(params).then(res => { request.req(params).then(res => {
this.merchantInfo = res this.merchantInfo = res
console.log(this.merchantInfo)
// this.merchantInfo.lng = '' // this.merchantInfo.lng = ''
// this.merchantInfo.lat = '' // this.merchantInfo.lat = ''
this.assignBasicInfo() this.intiBMap(this.merchantInfo.lng, this.merchantInfo.lat, true)
this.IdChange[0] = 0 this.IdChange[0] = 0
this.basicLoading = false this.basicLoading = false
}).catch(err => { }).catch(err => {
...@@ -515,27 +553,50 @@ export default { ...@@ -515,27 +553,50 @@ export default {
}, },
// 根据经纬度获取地址名 // 根据经纬度获取地址名
getAddress(lng, lat) { getAddress(lng, lat) {
amapManager._map.remove(marker) var that = this
marker = [] var myGeo = new BMap.Geocoder();
if (lng && lat) this.center = [+lng, +lat] // 根据坐标得到地址描述
var geocoder = new AMap.Geocoder({ // eslint-disable-line myGeo.getLocation(new BMap.Point(lng, lat), function(result){
radius: 1000, if (result){
extensions: 'all' console.log(result);
}) var point = new BMap.Point(lng, lat)
geocoder.getAddress(this.center, (status, result) => { var marker = new BMap.Marker(point)
if (status === 'complete' && result.info === 'OK') { that.map.addOverlay(marker)
const mar = new AMap.Marker({ // eslint-disable-line that.merchantInfo.address = result.address
position: this.center, let code = result.content.address_detail.adcode + ''
title: result.regeocode.formattedAddress let name = result.addressComponents
}) that.merchantInfo.provinceId = code.slice(0,2) + '0000'
marker.push(mar) that.merchantInfo.provinceName = name.province
amapManager._map.add(marker) that.merchantInfo.cityId = code.slice(0,4) + '00'
this.hasLocation = true that.merchantInfo.cityName = name.city
this.merchantInfo.lng = this.center[0] that.merchantInfo.areaId = code
this.merchantInfo.lat = this.center[1] that.merchantInfo.areaName = name.district
this.List[10].value = result.regeocode.formattedAddress that.List[10].value = result.address
} that.hasLocation = true
}) that.map.panTo(point)
}
});
// amapManager._map.remove(marker)
// marker = []
// if (lng && lat) this.center = [+lng, +lat]
// var geocoder = new AMap.Geocoder({ // eslint-disable-line
// radius: 1000,
// extensions: 'all'
// })
// geocoder.getAddress(this.center, (status, result) => {
// if (status === 'complete' && result.info === 'OK') {
// const mar = new AMap.Marker({ // eslint-disable-line
// position: this.center,
// title: result.regeocode.formattedAddress
// })
// marker.push(mar)
// amapManager._map.add(marker)
// this.hasLocation = true
// this.merchantInfo.lng = this.center[0]
// this.merchantInfo.lat = this.center[1]
// this.List[10].value = result.regeocode.formattedAddress
// }
// })
}, },
markAddr() { markAddr() {
this.hasLocation = true this.hasLocation = true
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!