index.vue 8.1 KB

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