index.vue 8.5 KB

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