index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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="$refs.popup.open()" 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="$refs.popup.close()" 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. markData: [{
  63. id: '1',
  64. name: '洗车机',
  65. latitude: '34.29318',
  66. longitude: '108.94712',
  67. },
  68. {
  69. id: '2',
  70. name: '洗车机',
  71. latitude: '34.29318',
  72. longitude: '118.94712',
  73. },
  74. {
  75. id: '11',
  76. name: '洗车机',
  77. latitude: '34.29318',
  78. longitude: '128.94712',
  79. },
  80. {
  81. id: '12',
  82. name: '洗车机',
  83. latitude: '38.29318',
  84. longitude: '108.94712',
  85. },
  86. {
  87. id: '13',
  88. name: '洗车机',
  89. latitude: '44.29318',
  90. longitude: '108.94712',
  91. }
  92. ]
  93. }
  94. },
  95. onReady() {
  96. this.mapCtx = wx.createMapContext('map')
  97. },
  98. onLoad() {
  99. this.getUserLocation()
  100. },
  101. methods: {
  102. // 用户位置信息授权
  103. getUserLocation() {
  104. let _this = this
  105. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope
  106. wx.getSetting({
  107. success(res) {
  108. if (!res.authSetting['scope.userLocation']) {
  109. wx.authorize({
  110. scope: 'scope.userLocation',
  111. success() {
  112. // 用户已经同意小程序使用位置信息,后续调用 wx.getLocation 接口不会弹窗询问
  113. _this.getLocation()
  114. }
  115. })
  116. } else {
  117. _this.getLocation()
  118. }
  119. }
  120. })
  121. },
  122. // 获取用户位置
  123. getLocation () {
  124. wx.getLocation({
  125. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  126. success: (res) => {
  127. console.log(res)
  128. console.log(11111111111)
  129. let latitude = res.latitude;
  130. let longitude = res.longitude;
  131. this.centerX = longitude
  132. this.centerY = latitude
  133. this.markers = this.getMarkersData()
  134. }
  135. });
  136. },
  137. // 点击标点获取数据
  138. markertap(e) {
  139. var id = e.markerId
  140. var name = this.data.markers[id - 1].name
  141. console.log(name)
  142. this.setData({
  143. lingyuanName: name,
  144. showDialog: true,
  145. })
  146. },
  147. // 获取标记点数据
  148. getMarkersData() {
  149. let markers = [];
  150. for (let item of this.markData) {
  151. let marker = this.createMarker(item);
  152. markers.push(marker)
  153. }
  154. return markers;
  155. },
  156. // 进入个人中心
  157. toUserCenter () {
  158. uni.navigateTo({
  159. url: '/pages/userCenter/index'
  160. })
  161. },
  162. // 打开网点列表
  163. intoList() {
  164. uni.navigateTo({
  165. url: '/pages/store/storeList'
  166. })
  167. },
  168. // 联系客服
  169. concatServicer() {
  170. this.$refs.popup.open()
  171. },
  172. // 电话客服
  173. callPhone () {
  174. uni.makePhoneCall({
  175. phoneNumber: '114'
  176. })
  177. },
  178. // 扫码洗车
  179. scanCode () {
  180. uni.scanCode({
  181. success: function (res) {
  182. console.log('条码类型:' + res.scanType);
  183. console.log('条码内容:' + res.result);
  184. }
  185. });
  186. },
  187. // 创建标记点
  188. createMarker(point) {
  189. let latitude = point.latitude;
  190. let longitude = point.longitude;
  191. let marker = {
  192. iconPath: "/image/location.png",
  193. id: point.id || 0,
  194. name: point.name || '',
  195. latitude: latitude,
  196. longitude: longitude,
  197. width: 30,
  198. height: 30,
  199. label: {
  200. content: point.name,
  201. color: '#22ac38',
  202. fontSize: 14,
  203. bgColor: 'transparent',
  204. borderRadius: 30,
  205. borderColor: "#22ac38",
  206. // borderWidth: 1,
  207. padding: 3
  208. },
  209. callout: {
  210. content: point.name,
  211. fontSize: 0,
  212. }
  213. };
  214. return marker;
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .content {
  221. display: flex;
  222. flex-direction: column;
  223. align-items: center;
  224. justify-content: center;
  225. padding: 0;
  226. .pageContent {
  227. width: 100%;
  228. flex: 1;
  229. .cover-view {
  230. z-index: 9;
  231. position: absolute;
  232. top: calc(60% - 120rpx);
  233. left: calc(50% - 360rpx);
  234. background: rgba(255, 0, 0, 0.6);
  235. border-radius: 20rpx;
  236. .flex-wrp {
  237. display: flex;
  238. flex-direction: column;
  239. }
  240. .flex-item {
  241. width: 120rpx;
  242. height: 120rpx;
  243. font-size: 24rpx;
  244. color: #fff;
  245. display: flex;
  246. flex-direction: column;
  247. justify-content: center;
  248. align-items: center;
  249. .img {
  250. width: 50rpx;
  251. height: 50rpx;
  252. margin-bottom: 10rpx;
  253. }
  254. }
  255. }
  256. .cover-bottom {
  257. z-index: 9;
  258. position: absolute;
  259. bottom: calc(60rpx);
  260. width: 80%;
  261. left: calc(9%);
  262. }
  263. }
  264. uni-popup{
  265. z-index: 999;
  266. }
  267. .popup-box{
  268. width: 100%;
  269. height: 320rpx;
  270. background-color: #F8F8F8;
  271. display: flex;
  272. flex-direction: column;
  273. .pop-top{
  274. width: 100%;
  275. font-size: 32rpx;
  276. display: flex;
  277. flex-direction: column;
  278. align-items: center;
  279. justify-content: center;
  280. background-color: #fff;
  281. .pop-item{
  282. width: 80%;
  283. text-align: center;
  284. line-height: 100rpx;
  285. }
  286. .top-first{
  287. border-bottom: 1px solid #F8F8F8;
  288. }
  289. }
  290. .pop-cancle{
  291. width: 100%;
  292. flex: 1;
  293. margin-top: 20rpx;
  294. background-color: #fff;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. font-size: 30rpx;
  299. color: #333;
  300. }
  301. }
  302. }
  303. </style>