warehouseReceiptMap.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <style lang='scss' scoped>
  2. .mapContent {
  3. position: relative;
  4. height: 95%;
  5. transition: 0.5s;
  6. .center-add {
  7. position: absolute;
  8. top: 0;
  9. bottom: 0;
  10. left: 0;
  11. right: 0;
  12. margin: auto;
  13. z-index: 999;
  14. width: 30px;
  15. height: 30px;
  16. }
  17. }
  18. #mapContainer {
  19. width: 100%;
  20. height: 100%;
  21. }
  22. .amap-info-close {
  23. display: none !important;
  24. }
  25. </style>
  26. <template>
  27. <div class="mapContent">
  28. <div id="mapContainer"></div>
  29. </div>
  30. </template>
  31. <script>
  32. import {
  33. regionData,
  34. CodeToText,
  35. TextToCode
  36. } from 'element-china-area-data'
  37. import image from '../../../public/img/ic_locationmarker.jpg'
  38. import AMapLoader from '@amap/amap-jsapi-loader';
  39. export default {
  40. data() {
  41. return {
  42. map: null,
  43. marker: null,
  44. markers: [],
  45. zoomEnable: true,
  46. dragEnable: true,
  47. status: true,
  48. }
  49. },
  50. props: [
  51. 'listData'
  52. ],
  53. computed: {},
  54. watch: {
  55. listData: function(val1, val2) {
  56. this.listData = val1
  57. var that = this
  58. this.map = new AMap.Map('mapContainer', {
  59. resizeEnable: true,
  60. zoom: 5,
  61. center: [103.809074, 36.051121],
  62. zoomEnable: this.zoomEnable,
  63. dragEnable: this.dragEnable
  64. })
  65. this.loadmap()
  66. }
  67. },
  68. async created() {
  69. // AMapLoader.reset();
  70. // 已载入高德地图API,则直接初始化地图
  71. if (window.AMap && window.AMapUI) {
  72. this.initMap()
  73. // 未载入高德地图API,则先载入API再初始化
  74. } else {
  75. await remoteLoad(`http://webapi.amap.com/maps?v=1.3&key=${MapKey}&plugin=AMap.AutoComplete`)
  76. await remoteLoad('http://webapi.amap.com/ui/1.0/main.js')
  77. this.initMap()
  78. }
  79. },
  80. mounted() {},
  81. methods: {
  82. makeMarkersList() {
  83. let _list = this.listData
  84. for (let i = 0; i < _list.length; i++) {
  85. _list[i].marker = []
  86. _list[i].marker.push(_list[i].warehousePositioning.split(',')[1])
  87. _list[i].marker.push(_list[i].warehousePositioning.split(',')[0])
  88. }
  89. },
  90. loadmap(val) {
  91. let that = this
  92. //构造markersList
  93. this.makeMarkersList()
  94. AMap.plugin(['AMap.DistrictSearch', 'AMap.Polygon'], function() {
  95. var geolocation = new AMap.Geolocation({
  96. // 是否使用高精度定位,默认:true
  97. enableHighAccuracy: true, // 设置定位超时时间,默认:无穷大
  98. timeout: 10000, // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
  99. buttonOffset: new AMap.Pixel(10, 20), // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
  100. zoomToAccuracy: true, // 定位按钮的排放位置, RB表示右下
  101. buttonPosition: 'RB'
  102. })
  103. geolocation.getCurrentPosition()
  104. AMap.event.addListener(geolocation, 'complete', e => {
  105. console.log(e) // 定位成功之后做的事 // 定位成功之后再定位处添加一个marker
  106. var infoWindow = new AMap.InfoWindow({
  107. offset: new AMap.Pixel(0, -30)
  108. })
  109. function infoOpen(e) {
  110. infoWindow.setContent(e.target.content)
  111. infoWindow.open(that.map, e.target.getPosition())
  112. }
  113. function infoClose(e) {
  114. infoWindow.close(that.map, e.target.getPosition())
  115. }
  116. function toGetList(e) {
  117. // console.log(e.target.getExtData())
  118. that.$parent.getList(e.target.getExtData().id, 1)
  119. }
  120. for (let i = 0; i < that.listData.length; i++) {
  121. var marker = new AMap.Marker({
  122. map: that.map,
  123. position: that.listData[i]
  124. .marker, // marker最终显示在那个点上,
  125. icon: new AMap.Icon({
  126. image: "https://taohaoliang.oss-cn-beijing.aliyuncs.com/pcfiles/home_pic.png",
  127. size: new AMap.Size(20, 20), //图标大小
  128. imageSize: new AMap.Size(20, 20),
  129. }),
  130. })
  131. marker.setExtData({
  132. 'id': that.listData[i].warehouseName
  133. })
  134. let _cwList = '<div class="cw-wrap">'
  135. for (let k = 0; k < that.listData[i].tradeWarehouseReceiptAppls.length; k++) {
  136. let _k = that.listData[i].tradeWarehouseReceiptAppls[k]
  137. _cwList += '<div style="display:flex">' +
  138. '<div style="margin:10px 20px">' + _k.warehouseNo + '仓位</div>' +
  139. '<div style="margin:10px 20px">' + _k.goodsName + '</div>' +
  140. '<div style="margin:10px 20px">' + _k.weight + '</div>' +
  141. '</div>'
  142. }
  143. _cwList = _cwList + '</div>'
  144. console.log('地图仓位数据', _cwList)
  145. marker.content = '<div style="display:flex;justify-content: center">' + that.listData[i]
  146. .warehouseName + '</div>' + _cwList + '</div>'
  147. marker.on('mouseover', infoOpen)
  148. marker.on('mouseout', infoClose)
  149. marker.on('click', toGetList)
  150. // 设置label标签
  151. // label默认蓝框白底左上角显示,样式className为:amap-marker-label
  152. // marker.setLabel({
  153. // offset: new AMap.Pixel(20, 20), //设置文本标注偏移量
  154. // content: "<div class='info'>我是 marker 的 label 标签</div>", //设置文本标注内容
  155. // direction: 'right' //设置文本标注方位
  156. // });
  157. }
  158. })
  159. AMap.event.addListener(geolocation, 'error', e => {
  160. console.log(e) // 定位失败
  161. })
  162. })
  163. }
  164. }
  165. }
  166. </script>