耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
8.1 KiB

  1. <template>
  2. <view class="receiving-map position-relative flex-1">
  3. <!-- 地图 -->
  4. <view class="map">
  5. <map id="myMap" style="width: 100%; height: 44vh" :subkey="mapKey"
  6. :latitude="latitude" :longitude="longitude" :markers="markers" :layer-style="1"
  7. @regionchange="onMapDrag" show-location>
  8. <!-- :polyline="polyline" 线-->
  9. <cover-image class="locate-img" src="https://cheum.oss-cn-beijing.aliyuncs.com/chemuXcx-img/newimg/locate2.png"></cover-image>
  10. <cover-view class="location-img-box" @click="test">
  11. <cover-image class="location-img" :src="IMG_URL + 'location.png'"></cover-image>
  12. </cover-view>
  13. </map>
  14. <view class="receiving-map-container position-absolute zIndex-1">
  15. <view class="flex align-center justify-between p-l-20 p-r-20">
  16. <view class="flex align-center receiving-map-container-title u-line-1">
  17. <u-icon name="map" color="##707070" size="40" />
  18. <text class="text-grey font-26 m-l-10 u-line-1">{{ locale }}</text>
  19. </view>
  20. <text class="text-grey font-26 m-l-10">(当前定位)</text>
  21. </view>
  22. <!-- <scroll-view scroll-y class="receiving-map-container-scroll" >
  23. <view class="m-l-20 m-r-20">
  24. <receiving-item v-for="item in 10" :key="item" />
  25. </view>
  26. </scroll-view> -->
  27. <view class="receiving-map-container-scroll">
  28. <view class="font-28 font-weight-bold text-black flex flex-wrap align-center justify-center receiving-map-container-tips">
  29. <text class="m-b-16">您附近1.5KM内没有取货点</text>
  30. <text class="m-b-16">可以添加收货地址让快递小哥送货哟</text>
  31. <text class="m-b-16 text-grey">*(运费自理满100包邮</text>
  32. </view>
  33. <view class="receiving-map-container-btn">
  34. <u-button type="primary" @click="toAdd">去添加收货地址</u-button>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. /**
  43. * map 用到的属性
  44. * @param width map宽度
  45. * @param height map高度
  46. * @param latitude 中心纬度getLocation
  47. * @param longitude 中心经度
  48. * @param scale 缩放级别取值范围为5-18
  49. * @param markers 标记点
  50. * @param show-location 显示带有方向的当前定位点
  51. * @param @markertap 点击标记点时触发
  52. * @param @labeltap 点击label时触发e.detail = {markerId} 微信小程序2.9.0
  53. * @param @callouttap 点击标记点对应的气泡时触发e.detail = {markerId}
  54. * @param @controltap 点击控件时触发e.detail = {controlId}
  55. * */
  56. import QQMapWX from '@/plugin/map/qqmap-wx-jssdk.min.js'
  57. import { IMG_URL } from '@/env.js'
  58. import { MAP_KEY } from '@/config/settings.js'
  59. export default {
  60. data() {
  61. return {
  62. mapKey: MAP_KEY,
  63. IMG_URL,
  64. xuanran:true,//是否渲染地图
  65. showLocate:true,//展示地图上的标记点
  66. markers: [], // 标记点列表
  67. latitude: 0, // 当前位置经纬度
  68. longitude: 0, // 当前位置经纬度
  69. center : ['', ''],
  70. show: false, // 众筹店铺详细信息显示隐藏
  71. qqmapsdk: '',
  72. locale: ''
  73. }
  74. },
  75. onLoad() {
  76. this.qqmapsdk = new QQMapWX({
  77. key: this.mapKey // 必填
  78. })
  79. this.handleAuthorize()
  80. },
  81. onShow() {
  82. //调用地图信息
  83. },
  84. onHide() {
  85. },
  86. methods: {
  87. toAdd () {
  88. this.$tools.navigateTo({
  89. url: '/pages/my/address/address?type=set_location'
  90. })
  91. },
  92. test () {
  93. this.handleAuthorize()
  94. },
  95. // 距离换算
  96. getDistance(val){
  97. return ((val/1000)*1).toFixed(2) + 'km'
  98. },
  99. // 授权定位
  100. handleAuthorize() {
  101. uni.authorize({
  102. scope: 'scope.userLocation', // 获取地理信息必填的参数,其它参数见文档
  103. success: res => {
  104. this.getLocationFn()
  105. },
  106. // 授权失败
  107. fail(err) {
  108. err = err['errMsg']
  109. uni.showModal({
  110. title: '温馨提示',
  111. content: '为了您的体验,请授权定位服务。',
  112. showCancel: false,
  113. confirmText: '确认授权',
  114. }).then(res => {
  115. // 这里只设置了确认按钮,没有取消按钮
  116. //res : [null, {cancel: false, confirm: true, errMsg: 'showModal: ok'}]
  117. if (res[1]['confirm']) {
  118. // 点击了确认按钮时
  119. // 调用下边方法时,会弹出 【使用我的地理位置】界面, 未设置直接返回,还是会走fail授权失败的函数,
  120. // 还是会弹出上边的温馨提示!!!
  121. // 如果设置, scope.userLocation: true
  122. uni.openSetting({
  123. success(res) {
  124. // 如果不设置,res结果:
  125. // {errMsg: "openSetting:ok", authSetting: {scope.userLocation: false}}
  126. // 如果设置, res结果:
  127. // {errMsg: "openSetting:ok", authSetting: {scope.userLocation: true}}
  128. // console.log('小程序设置界面:', res)
  129. },
  130. })
  131. }
  132. })
  133. },
  134. })
  135. },
  136. getLocationFn() {
  137. uni.getLocation({
  138. type: 'gcj02', // <map> 组件默认为国测局坐标gcj02
  139. altitude: true,
  140. success: res => {
  141. console.log(res);
  142. this.latitude = res.latitude
  143. this.longitude = res.longitude
  144. this.getMarkeres(this.latitude,this.longitude);
  145. },
  146. fail: error =>{
  147. console.log('error-------',error)
  148. this.latitude = ''
  149. this.longitude = ''
  150. this.getMarkeres('','')
  151. }
  152. })
  153. },
  154. onMapDrag(e){
  155. var map = uni.createMapContext('myMap', this);
  156. map.getCenterLocation({
  157. success:(res)=>{
  158. console.log(res)
  159. this.qqmapsdk.reverseGeocoder({
  160. location: {
  161. latitude: res.latitude,
  162. longitude: res.longitude
  163. },
  164. success: (location) => {
  165. let {result} = location
  166. console.log('location=======>',result,result.formatted_addresses.recommend)
  167. this.locale = result.formatted_addresses.recommend
  168. },
  169. })
  170. setTimeout(()=>{
  171. this.getMarkeres(res.latitude, res.longitude)
  172. },1000)
  173. }
  174. })
  175. },
  176. // 获取取货列表
  177. getMarkeres (longitude, latitude) {
  178. // let arr = [longitude, latitude]
  179. // arr = arr.join()
  180. let imgUrl = 'https://cheum.oss-cn-beijing.aliyuncs.com/chemuXcx-img/index/'
  181. // this.queryMerchantInfo({
  182. // lon: latitude,
  183. // lat: longitude
  184. // }).then(res => {
  185. // this.nearlyList = res.result.slice(0, 3)
  186. // // 添加气泡
  187. // let num = 0
  188. // res.result.forEach((item, i) => {
  189. // num++
  190. // item.longitLat = item.longitLat.split(',')
  191. // item.business = item.business.split("、")
  192. let mk = {
  193. id: 1, //marker 序号
  194. width: '53rpx', //marker 宽度
  195. height: '60rpx', //marker 高度
  196. iconPath: imgUrl + 'markersImg-2.png', //marker 图标路径
  197. // iconPath: item.type == 2 ? imgUrl + 'markersImg-1.png' : imgUrl + 'markersImg-2.png', //marker 图标路径
  198. longitude, //marker 经度
  199. latitude: 90, //marker 纬度
  200. name: 'Cheum车姆',
  201. callout: {
  202. borderRadius: 10,
  203. padding: 10,
  204. color: '#333333',
  205. fontSize: 10,
  206. content: 'Cheum车姆',
  207. display:'ALWAYS'
  208. }
  209. }
  210. // if(this.xuanran){
  211. this.markers.push(mk)
  212. // console.log(this.markers)
  213. // // this.xuanran = false
  214. // }
  215. // if(num === res.result.length){
  216. // this.xuanran = false
  217. // }
  218. // })
  219. // // 初始化onMapDragNum
  220. // this.onMapDragNum = 0
  221. // })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .locate-img {
  228. width: 50rpx;
  229. height: 82rpx;
  230. position: fixed;
  231. top: 22vh;
  232. left: 50%;
  233. transform: translate(-50%, -100%);
  234. }
  235. .location-img-box {
  236. position: fixed;
  237. top: 40vh;
  238. right: 0;
  239. transform: translate(-20%, -110%);
  240. }
  241. .location-img {
  242. width: 120rpx;
  243. height: 120rpx;
  244. }
  245. .receiving-map {
  246. &-container {
  247. width: 100vw;
  248. left: 0;
  249. bottom: 0;
  250. height: 60vh;
  251. background: #fff;
  252. border-radius: 47rpx 47rpx 0px 0px;
  253. &-title {
  254. width: 78%;
  255. height: 80rpx;
  256. box-sizing: border-box;
  257. }
  258. &-scroll {
  259. height: calc(60vh - 80rpx);
  260. }
  261. &-tips {
  262. padding-top: 80rpx;
  263. margin-bottom: 200rpx;
  264. }
  265. &-btn {
  266. padding: 0 150rpx;
  267. }
  268. }
  269. }
  270. </style>