index.vue 6.9 KB

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