index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="content">
  3. <!-- 顶部导航 -->
  4. <uni-nav-bar :border="false" @click-left="toUserCenter" leftIcon="person-filled" leftText=" " :shadow="false"
  5. background-color="#fff" :status-bar="true" :fixed="true" color="rgb(255,0,0)" title=" ">
  6. </uni-nav-bar>
  7. <!-- 页面主体 -->
  8. <view class="pageContent">
  9. <map id="map" :latitude="centerY" :longitude="centerX" scale="14" :markers="markers" bindmarkertap="markertap"
  10. show-location style="width: 100%; height:100%;">
  11. <view class="cover-view">
  12. <view class="flex-wrp">
  13. <cover-view @click="intoList" class="flex-item">
  14. <cover-image class="img" src="/static/img/index-list.png"></cover-image>
  15. <cover-view>网点列表</cover-view>
  16. </cover-view>
  17. <cover-view @click="openPop" class="flex-item">
  18. <cover-image class="img" src="/static/img/index-call.png"></cover-image>
  19. <cover-view>联系客服</cover-view>
  20. </cover-view>
  21. <cover-view class="flex-item">
  22. <cover-image class="img" src="/static/img/index-discount.png"></cover-image>
  23. <cover-view>优惠活动</cover-view>
  24. </cover-view>
  25. </view>
  26. </view>
  27. <view class="cover-bottom">
  28. <button @click="scanCode" type="warn">扫码洗车</button>
  29. </view>
  30. </map>
  31. </view>
  32. <!-- 客服弹窗 -->
  33. <uni-popup ref="popup" type="bottom">
  34. <view class="popup-box">
  35. <view class="pop-top">
  36. <view class="top-first pop-item">
  37. 在线客服
  38. </view>
  39. <view @click="callPhone" class="pop-item">
  40. 电话客服
  41. </view>
  42. </view>
  43. <view @click="closePop" class="pop-cancle">
  44. 取消
  45. </view>
  46. </view>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
  52. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  53. export default {
  54. components: {
  55. uniNavBar, uniPopup
  56. },
  57. data() {
  58. return {
  59. markers: [], // 标注点
  60. centerX: '',
  61. centerY: '',
  62. showPop: false, // 是否显示客服弹框
  63. markData: [{
  64. id: '1',
  65. name: '洗车机',
  66. latitude: '34.29318',
  67. longitude: '108.94712',
  68. },
  69. {
  70. id: '2',
  71. name: '洗车机',
  72. latitude: '34.29318',
  73. longitude: '118.94712',
  74. },
  75. {
  76. id: '11',
  77. name: '洗车机',
  78. latitude: '34.29318',
  79. longitude: '128.94712',
  80. },
  81. {
  82. id: '12',
  83. name: '洗车机',
  84. latitude: '38.29318',
  85. longitude: '108.94712',
  86. },
  87. {
  88. id: '13',
  89. name: '洗车机',
  90. latitude: '44.29318',
  91. longitude: '108.94712',
  92. }
  93. ]
  94. }
  95. },
  96. onReady() {
  97. this.mapCtx = wx.createMapContext('map')
  98. },
  99. onLoad() {
  100. this.getUserLocation()
  101. // H5及APP平台适配代码
  102. // #ifdef H5 || APP-PLUS
  103. this.getLocation()
  104. // #endif
  105. },
  106. methods: {
  107. // 用户位置信息授权
  108. getUserLocation() {
  109. let _this = this
  110. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope H5及APP平台不适用
  111. uni.getSetting({
  112. success(res) {
  113. if (!res.authSetting['scope.userLocation']) {
  114. uni.authorize({
  115. scope: 'scope.userLocation',
  116. success() {
  117. // 用户已经同意小程序使用位置信息,后续调用 wx.getLocation 接口不会弹窗询问
  118. _this.getLocation()
  119. }
  120. })
  121. } else {
  122. _this.getLocation()
  123. }
  124. }
  125. })
  126. },
  127. // 获取用户位置
  128. getLocation () {
  129. wx.getLocation({
  130. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  131. success: (res) => {
  132. console.log(res)
  133. console.log(11111111111)
  134. let latitude = res.latitude;
  135. let longitude = res.longitude;
  136. this.centerX = longitude
  137. this.centerY = latitude
  138. this.markers = this.getMarkersData()
  139. }
  140. });
  141. },
  142. // 点击标点获取数据
  143. markertap(e) {
  144. var id = e.markerId
  145. var name = this.data.markers[id - 1].name
  146. console.log(name)
  147. this.setData({
  148. lingyuanName: name,
  149. showDialog: true,
  150. })
  151. },
  152. // 获取标记点数据
  153. getMarkersData() {
  154. let markers = [];
  155. for (let item of this.markData) {
  156. let marker = this.createMarker(item);
  157. markers.push(marker)
  158. }
  159. return markers;
  160. },
  161. // 进入个人中心
  162. toUserCenter () {
  163. uni.navigateTo({
  164. url: '/pages/userCenter/index'
  165. })
  166. },
  167. // 打开网点列表
  168. intoList() {
  169. uni.navigateTo({
  170. url: '/pages/store/storeList'
  171. })
  172. },
  173. // 联系客服
  174. openPop() {
  175. this.$refs.popup.open()
  176. this.showPop = true
  177. },
  178. // 关闭客服弹窗
  179. closePop() {
  180. this.$refs.popup.close()
  181. this.showPop = false
  182. },
  183. // 电话客服
  184. callPhone () {
  185. uni.makePhoneCall({
  186. phoneNumber: '114'
  187. })
  188. },
  189. // 扫码洗车
  190. scanCode () {
  191. uni.scanCode({
  192. success: function (res) {
  193. console.log('条码类型:' + res.scanType);
  194. console.log('条码内容:' + res.result);
  195. }
  196. });
  197. },
  198. // 创建标记点
  199. createMarker(point) {
  200. let latitude = point.latitude;
  201. let longitude = point.longitude;
  202. let marker = {
  203. iconPath: "/image/location.png",
  204. id: point.id || 0,
  205. name: point.name || '',
  206. latitude: latitude,
  207. longitude: longitude,
  208. width: 30,
  209. height: 30,
  210. label: {
  211. content: point.name,
  212. color: '#22ac38',
  213. fontSize: 14,
  214. bgColor: 'transparent',
  215. borderRadius: 30,
  216. borderColor: "#22ac38",
  217. // borderWidth: 1,
  218. padding: 3
  219. },
  220. callout: {
  221. content: point.name,
  222. fontSize: 0,
  223. }
  224. };
  225. return marker;
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. .content {
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. justify-content: center;
  236. padding: 0;
  237. .pageContent {
  238. width: 100%;
  239. flex: 1;
  240. .cover-view {
  241. position: absolute;
  242. top: calc(60% - 120rpx);
  243. left: calc(50% - 360rpx);
  244. background: rgba(255, 0, 0, 0.6);
  245. border-radius: 20rpx;
  246. .flex-wrp {
  247. display: flex;
  248. flex-direction: column;
  249. }
  250. .flex-item {
  251. width: 120rpx;
  252. height: 120rpx;
  253. font-size: 24rpx;
  254. color: #F8F8F8;
  255. display: flex;
  256. flex-direction: column;
  257. justify-content: center;
  258. align-items: center;
  259. .img {
  260. width: 50rpx;
  261. height: 50rpx;
  262. margin-bottom: 10rpx;
  263. }
  264. }
  265. }
  266. .cover-bottom {
  267. position: absolute;
  268. bottom: calc(60rpx);
  269. width: 80%;
  270. left: calc(9%);
  271. }
  272. }
  273. .popup-box{
  274. width: 100%;
  275. height: 320rpx;
  276. background-color: #F8F8F8;
  277. display: flex;
  278. flex-direction: column;
  279. .pop-top{
  280. width: 100%;
  281. font-size: 32rpx;
  282. display: flex;
  283. flex-direction: column;
  284. align-items: center;
  285. justify-content: center;
  286. background-color: #fff;
  287. .pop-item{
  288. width: 80%;
  289. text-align: center;
  290. line-height: 100rpx;
  291. }
  292. .top-first{
  293. border-bottom: 1px solid #F8F8F8;
  294. }
  295. }
  296. .pop-cancle{
  297. width: 100%;
  298. flex: 1;
  299. margin-top: 20rpx;
  300. background-color: #fff;
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. font-size: 30rpx;
  305. color: #333;
  306. }
  307. }
  308. }
  309. </style>