index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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="lat" :longitude="lng" scale="14" show-compass :markers="markers" @markertap="markertap"
  17. show-location style="width: 100%; height:100%;">
  18. <!-- 信息提示 -->
  19. <cover-view class="work-message" @click="toWork" v-if="workStatus!='stop'">
  20. <cover-view class="work-message-in">
  21. <cover-view class="view">洗车机正在工作中...</cover-view>
  22. <cover-view class="view">点击进入</cover-view>
  23. </cover-view>
  24. </cover-view>
  25. <!-- 左边控件 -->
  26. <view class="cover-view">
  27. <view class="flex-wrp">
  28. <cover-view @click="intoList" class="flex-item">
  29. <cover-image class="img" src="/static/img/index-list.png"></cover-image>
  30. <cover-view>网点列表</cover-view>
  31. </cover-view>
  32. <cover-view @click="openPop" class="flex-item">
  33. <cover-image class="img" src="/static/img/index-call.png"></cover-image>
  34. <cover-view>联系客服</cover-view>
  35. </cover-view>
  36. <!-- <cover-view class="flex-item">
  37. <cover-image class="img" src="/static/img/index-discount.png"></cover-image>
  38. <cover-view>优惠活动</cover-view>
  39. </cover-view> -->
  40. </view>
  41. </view>
  42. <!-- 地图移动后返回原位置控件 -->
  43. <view class="cover-location">
  44. <cover-image class="img" @click="moveToLocation" src="/static/img/location.png"></cover-image>
  45. </view>
  46. <view class="cover-bottom">
  47. <button @click="scanCode" type="warn">
  48. <u-icon name="scan" color="#fff" size="38"></u-icon>
  49. 扫码洗车
  50. </button>
  51. </view>
  52. </map>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
  58. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  59. import {checkLogin} from '@/api/login.js'
  60. import {getMapStoreList} from '@/api/store.js'
  61. import {getLookUpDatas} from '@/api/data.js'
  62. export default {
  63. components: {
  64. uniNavBar, uniPopup
  65. },
  66. data() {
  67. return {
  68. workStatus:'',
  69. mapCtx: null, // 地图对象
  70. markers: [], // 标注点
  71. lng: '',
  72. lat: '',
  73. }
  74. },
  75. onReady() {
  76. this.mapCtx = uni.createMapContext('map')
  77. },
  78. onShow() {
  79. console.log(this.$store.state.vuex_orderInfo,'vuex_orderInfo')
  80. console.log(this.$store.state.vuex_workStatus,'vuex_workStatus')
  81. this.workStatus = this.$store.state.vuex_workStatus
  82. },
  83. onLoad() {
  84. this.getUserLocation()
  85. // 获取订单状态数据字典
  86. this.getCodeList('ORDER_STATUS')
  87. // 获取支付方式数据字典
  88. this.getCodeList('PAY_TYPE')
  89. // 获取网点标签数据字典
  90. this.getCodeList('STORE_LABEL')
  91. },
  92. methods: {
  93. // 获取数据字典
  94. getCodeList (code) {
  95. getLookUpDatas({type:code}).then(res =>{
  96. if (res.status == 200) {
  97. console.log(res.data,'res.data')
  98. switch (code){
  99. case 'ORDER_STATUS':
  100. this.$u.vuex('vuex_payStatus', res.data)
  101. break;
  102. case 'PAY_TYPE':
  103. this.$u.vuex('vuex_payType', res.data)
  104. break;
  105. case 'STORE_LABEL':
  106. this.$u.vuex('vuex_storeLabel', res.data)
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. })
  113. },
  114. // 如果机器正在运行,提示并点击跳转的运行界面
  115. toWork(){
  116. uni.navigateTo({
  117. url: "/pages/work/index/index"
  118. })
  119. },
  120. // 用户位置信息授权
  121. getUserLocation() {
  122. let _this = this
  123. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope H5及APP平台不适用
  124. // H5及APP平台适配代码
  125. // #ifndef H5 || APP-PLUS
  126. uni.getSetting({
  127. success(res) {
  128. if (!res.authSetting['scope.userLocation']) {
  129. uni.authorize({
  130. scope: 'scope.userLocation',
  131. success() {
  132. // 用户已经同意小程序使用位置信息,后续调用 uni.getLocation 接口不会弹窗询问
  133. _this.getLocation()
  134. },
  135. // 用户拒绝授权位置信息时默认展示青海西宁位置地图
  136. fail: (err) => {
  137. _this.lng = '101.760521'
  138. _this.lat = '36.636193'
  139. _this.markers = _this.getMarkersData()
  140. }
  141. })
  142. } else {
  143. _this.getLocation()
  144. }
  145. }
  146. })
  147. // #endif
  148. },
  149. // 获取用户位置
  150. getLocation () {
  151. uni.getLocation({
  152. type: 'gcj02',
  153. success: (res) => {
  154. console.log(res,'rrrr')
  155. let latitude = res.latitude;
  156. let longitude = res.longitude;
  157. this.lng = longitude
  158. this.lat = latitude
  159. this.markers = this.getMarkersData()
  160. },
  161. // 定位失败默认展示青海西宁位置地图
  162. fail: (err) => {
  163. this.lng = '101.760521'
  164. this.lat = '36.636193'
  165. this.markers = this.getMarkersData()
  166. }
  167. });
  168. },
  169. // 点击标点进入网点详情
  170. markertap(e) {
  171. console.log(e)
  172. uni.navigateTo({
  173. url: `/pages/store/storeDetail?id=${e.markerId}`
  174. })
  175. },
  176. // 获取所有标记点数据
  177. getMarkersData() {
  178. uni.showLoading({
  179. title: '加载中...'
  180. })
  181. let params = {
  182. lat: this.lat,
  183. lng: this.lng
  184. }
  185. getMapStoreList(params).then(res=>{
  186. uni.hideLoading()
  187. if (res.status == 200) {
  188. this.markData = res.data
  189. let markers = [];
  190. for (let item of this.markData) {
  191. let marker = this.createMarker(item);
  192. markers.push(marker)
  193. }
  194. this.markers = markers
  195. console.log(this.markers,'111111')
  196. } else {
  197. this.toashMsg(res.message)
  198. }
  199. })
  200. },
  201. // 点击回到定位坐标点
  202. moveToLocation () {
  203. this.mapCtx.moveToLocation()
  204. },
  205. // 进入个人中心
  206. toUserCenter () {
  207. // 检验是否登录或登录是否过期
  208. checkLogin().then(res =>{
  209. if (res.status == '200'){
  210. uni.navigateTo({
  211. url: '/pages/userCenter/index'
  212. })
  213. } else {
  214. uni.navigateTo({
  215. url: `/pages/login/login?lanuch=false&path=` + encodeURIComponent(`/pages/userCenter/index`)
  216. });
  217. }
  218. })
  219. },
  220. // 打开网点列表
  221. intoList() {
  222. uni.navigateTo({
  223. url: '/pages/store/storeList'
  224. })
  225. },
  226. // 联系客服
  227. openPop() {
  228. let _this = this
  229. uni.showActionSheet({
  230. itemList: ['在线客服', '电话客服'],
  231. success: function (res) {
  232. //在线客服
  233. if(res.tapIndex == 1){
  234. _this.callPhone()
  235. }
  236. //电话客服
  237. if(res.tapIndex == 1){
  238. _this.callPhone()
  239. }
  240. },
  241. fail: function (res) {
  242. console.log(res.errMsg);
  243. }
  244. });
  245. },
  246. // 电话客服
  247. callPhone () {
  248. uni.makePhoneCall({
  249. phoneNumber: '114'
  250. })
  251. },
  252. // 扫码洗车
  253. scanCode () {
  254. uni.navigateTo({
  255. url: `/pages/getOrder/getOrder?scene=100033,9695`
  256. })
  257. // uni.scanCode({
  258. // success: function (res) {
  259. // console.log('条码类型:' + res.scanType);
  260. // console.log('条码内容:' + res.result);
  261. // }
  262. // });
  263. },
  264. // 创建标记点 OPEN :正常营业 CLOSED:暂停营业 TO_BE_OPENED:待开业
  265. createMarker(point) {
  266. let latitude = point.lat;
  267. let longitude = point.lng;
  268. let iconPath = ''
  269. if (point.businessStatus==='CLOSED') {
  270. iconPath = '/static/img/store-dky.png'
  271. } else if (point.businessStatus==='OPEN') {
  272. iconPath = '/static/img/store.png'
  273. } else {
  274. iconPath = '/static/img/store-zt.png'
  275. }
  276. let marker = {
  277. iconPath: iconPath,
  278. id: point.id || 0,
  279. name: point.name || '',
  280. latitude: latitude,
  281. longitude: longitude,
  282. width: 30,
  283. height: 49,
  284. callout: {
  285. content: point.name,
  286. fontSize: 14,
  287. }
  288. };
  289. return marker;
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. .content {
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. justify-content: center;
  300. padding: 0;
  301. .pageContent {
  302. width: 100%;
  303. flex: 1;
  304. .work-message{
  305. position: absolute;
  306. top: 6%;
  307. width: 80%;
  308. left: 50%;
  309. margin-left: -40%;
  310. background: rgba(0,0,0,0.6);
  311. border-radius: 100rpx;
  312. color: #eee;
  313. .work-message-in{
  314. display: flex;
  315. align-items: center;
  316. padding: 26rpx;
  317. .view{
  318. &:first-child{
  319. flex-grow: 1;
  320. text-align: center;
  321. }
  322. &:last-child{
  323. font-size: 24rpx;
  324. color: #fff;
  325. display: flex;
  326. align-items: center;
  327. }
  328. }
  329. }
  330. }
  331. .cover-view {
  332. position: absolute;
  333. top: calc(60% - 150rpx);
  334. left: calc(50% - 360rpx);
  335. .flex-wrp {
  336. display: flex;
  337. flex-direction: column;
  338. background: rgba(0, 0, 0, 0.3);
  339. border-radius: 10rpx;
  340. padding: 10rpx 0;
  341. }
  342. .flex-item {
  343. width: 110rpx;
  344. height: 110rpx;
  345. font-size: 24rpx;
  346. color: #F8F8F8;
  347. display: flex;
  348. flex-direction: column;
  349. justify-content: center;
  350. align-items: center;
  351. .img {
  352. width: 50rpx;
  353. height: 50rpx;
  354. margin-bottom: 10rpx;
  355. }
  356. }
  357. }
  358. .cover-location{
  359. position: absolute;
  360. top: calc(75%);
  361. left: calc(85%);
  362. .img{
  363. width: 80rpx;
  364. height: 80rpx;
  365. }
  366. }
  367. .cover-bottom {
  368. position: absolute;
  369. bottom: calc(60rpx);
  370. width: 80%;
  371. left: calc(9%);
  372. uni-button[type=warn]{
  373. background: red;
  374. u-icon{
  375. margin-right: 15rpx;
  376. }
  377. }
  378. }
  379. }
  380. }
  381. </style>