Storemap.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 common-no-more" v-if="store && !(store.store_latitude && store.store_longitude)">
  13. 店铺未设置地址
  14. </view>
  15. <iframe class="map-content" v-if="getUrl || iframeUrl" :src="iframeUrl"></iframe>
  16. </view></home-base>
  17. </template>
  18. <script>
  19. import {getFontSize} from '@/util/common'
  20. import TitleHeader from '../../TitleHeader'
  21. import HomeBase from '../HomeBase'
  22. import { mapState, mapActions } from 'vuex'
  23. import { getPosition,convertPoint } from '../../../util/bmap'
  24. import { getStoreInfo,getStoreMap } from '../../../api/homestoredetail'
  25. export default {
  26. mounted(){
  27. // #ifdef MP-WEIXIN
  28. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  29. // #endif
  30. },
  31. data(){
  32. return {
  33. navHeight: 0,
  34. iframeUrl:'',
  35. store: false,
  36. store_id: '',
  37. o_lat: false,
  38. o_lng: false,
  39. d_lat: false,
  40. d_lng: false,
  41. }
  42. },
  43. components:{
  44. TitleHeader,
  45. HomeBase,
  46. },
  47. onLoad: function (option) {
  48. this.store_id=option.id ? option.id : ''
  49. getStoreInfo(
  50. this.store_id
  51. ).then((res) => {
  52. this.store = res.result.store_info
  53. if(this.store.store_longitude && this.store.store_latitude){
  54. convertPoint(this.store.store_longitude,this.store.store_latitude).then(result=>{
  55. if(result.status==0){
  56. this.d_lat = result.result[0].y
  57. this.d_lng = result.result[0].x
  58. }else{
  59. uni.showToast({icon:'none',title: '坐标转换失败'})
  60. }
  61. }).catch(error => {
  62. console.log(error)
  63. uni.showToast({icon:'none',title: '调用坐标转换接口失败'})
  64. })
  65. }
  66. }).catch(error => {
  67. uni.showToast({icon:'none',title: error.message})
  68. })
  69. var _this = this
  70. getPosition(function (res) {
  71. if (res.code === 10000) {
  72. _this.o_lat = res.result.lat
  73. _this.o_lng = res.result.lng
  74. } else {
  75. uni.showToast({icon:'none',title: res.message})
  76. }
  77. }, true)
  78. },
  79. computed:{
  80. fontSize(){
  81. return getFontSize()
  82. },
  83. getUrl: function () {
  84. if (this.d_lat && this.d_lng && this.o_lat && this.o_lng) {
  85. getStoreMap({region:this.store.area_info,o_lng:this.o_lng,o_lat:this.o_lat,o_name:'我',d_lng:this.d_lng,d_lat:this.d_lat,d_name:this.store.store_name}).then(res=>{
  86. this.iframeUrl = res.result.url
  87. console.log(this.iframeUrl)
  88. }).catch(error=>{
  89. uni.showToast({icon:'none',title: error.message})
  90. })
  91. }
  92. }
  93. },
  94. methods:{
  95. goBack(){uni.navigateBack({delta:1})},
  96. }
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .map-content{position: absolute;padding-top:2rem;width:100%;height:100%;top:0;box-sizing: border-box;border: 0}
  101. </style>