Map.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <home-base :show="false"><view class="div">
  3. <view class="div common-header-wrap">
  4. <view :style="'height:'+navHeight+'px'"></view>
  5. <view class="common-header-holder"></view>
  6. <view class="common-header-fixed">
  7. <title-header />
  8. <uni-nav-bar title="定位" class="common-header" left-icon="back" @clickLeft="goBack()">
  9. </uni-nav-bar>
  10. </view>
  11. </view>
  12. <view class="div map-wrapper">
  13. <map-select ref="map_select" :longitude="lng" :latitude="lat" :ifShowCurrent="true" @setPosition="setPosition"></map-select>
  14. </view>
  15. </view>
  16. </home-base>
  17. </template>
  18. <script>
  19. import {getFontSize} from '@/util/common'
  20. import TitleHeader from '../../TitleHeader'
  21. import HomeBase from '../HomeBase'
  22. import MapSelect from '../../MapSelect'
  23. import { mapState, mapMutations } from 'vuex'
  24. import { getAddressByPoint, getPosition, getPointByIp } from '../../../util/bmap'
  25. export default {
  26. name:'HomeMap',
  27. data(){
  28. return {
  29. navHeight: 0,
  30. lng: 0,
  31. lat: 0
  32. }
  33. },
  34. components:{
  35. TitleHeader,
  36. HomeBase,
  37. MapSelect
  38. },
  39. mounted(){
  40. // #ifdef MP-WEIXIN
  41. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  42. // #endif
  43. },
  44. created: function () {
  45. let _this = this
  46. getPosition(function (res) {
  47. if (res.code === 10000) {
  48. _this.lat = res.result.lat
  49. _this.lng = res.result.lng
  50. _this.getAddressByPoint()
  51. } else {
  52. // uni.showToast({icon:'none',title: res.message})
  53. // 使用ip定位
  54. getPointByIp().then(res => {
  55. if (res.status == 0) {
  56. _this.lat = res.content.point.y
  57. _this.lng = res.content.point.x
  58. _this.getAddressByPoint()
  59. } else {
  60. uni.showToast({icon:'none',title: res.message})
  61. }
  62. }).catch(function (error) {
  63. uni.showToast({icon:'none',title: error.message})
  64. })
  65. }
  66. }, true)
  67. },
  68. computed:{
  69. fontSize(){
  70. return getFontSize()
  71. },
  72. ...mapState({
  73. member_point: state => state.member.point
  74. })
  75. },
  76. methods:{
  77. goBack(){uni.navigateBack({delta:1})},
  78. ...mapMutations({
  79. memberPoint: 'memberPoint'
  80. }),
  81. getAddressByPoint () {
  82. getAddressByPoint(this.lat + ',' + this.lng).then(res => {
  83. if (res.status == 0) {
  84. this.memberPoint({ point: { lng: this.lng, lat: this.lat, address: res.result.sematic_description, cityCode: res.result.cityCode } })
  85. } else {
  86. uni.showToast({icon:'none',title: res.message})
  87. }
  88. }).catch(function (error) {
  89. uni.showToast({icon:'none',title: error.message})
  90. })
  91. },
  92. setPosition (lat, lng, name, cityCode) {
  93. this.memberPoint({ point: { lng: lng, lat: lat, address: name, cityCode: cityCode } })
  94. uni.navigateBack({delta:1})
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .map-wrapper{position:absolute;top:$headerHeight;bottom:0;width:100%}
  101. </style>