index.vue 7.9 KB

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