warehouseReceiptMap.vue 5.7 KB

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