index.vue 8.2 KB

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