index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <view class="content">
  3. <!-- 顶部导航 -->
  4. <uni-nav-bar :border="false" @clickLeft="toUserCenter" background-color="#fff" title="智能快洗" :status-bar="true" :fixed="true"
  5. color="rgb(255,0,0)">
  6. <view style="padding-left: 20rpx;" slot="left">
  7. <u-image width="40rpx" height="60rpx" mode="aspectFit" src="/static/img/person.png"></u-image>
  8. </view>
  9. </uni-nav-bar>
  10. <!-- 页面主体 -->
  11. <view class="pageContent">
  12. <map id="map" :latitude="lat" :longitude="lng" scale="10" show-compass :markers="markers" @markertap="markertap"
  13. show-location style="width: 100%; height:100%;">
  14. <!-- 信息提示 -->
  15. <cover-view class="work-message" v-if="workStatus=='show'" @click="toWork">
  16. <cover-view class="work-message-in">
  17. <cover-view class="view">洗车机正在工作中...</cover-view>
  18. <cover-view class="view">点击进入</cover-view>
  19. </cover-view>
  20. </cover-view>
  21. <!-- 左边控件 -->
  22. <view class="cover-view">
  23. <view class="flex-wrp">
  24. <cover-view @click="intoList" class="flex-item">
  25. <cover-image class="img" src="/static/img/index-list.png"></cover-image>
  26. <cover-view>网点列表</cover-view>
  27. </cover-view>
  28. <cover-view @click="openPop" class="flex-item">
  29. <cover-image class="img" src="/static/img/index-call.png"></cover-image>
  30. <cover-view>联系客服</cover-view>
  31. </cover-view>
  32. <cover-view @click="scanCoupon" class="flex-item">
  33. <cover-image class="img" src="/static/img/index-discount.png"></cover-image>
  34. <cover-view>优惠活动</cover-view>
  35. </cover-view>
  36. </view>
  37. </view>
  38. <!-- 地图移动后返回原位置控件 -->
  39. <view class="cover-location">
  40. <cover-image class="img" @click="moveToLocation" src="/static/img/location.png"></cover-image>
  41. </view>
  42. <view class="cover-bottom">
  43. <button @click="scanCode" type="warn">
  44. <u-icon name="scan" color="#fff" size="38"></u-icon>
  45. 扫码洗车
  46. </button>
  47. </view>
  48. </map>
  49. <!-- 用户未授权提示框 -->
  50. <u-modal v-model="showPop" @confirm="intoSetting" :show-cancel-button='false'
  51. confirm-text="设置" title="温馨提示" content="无法获取位置信息,请设置允许使用位置信息" width="70%"></u-modal>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
  57. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  58. import {
  59. checkLogin
  60. } from '@/api/login.js'
  61. import {
  62. getMapStoreList
  63. } from '@/api/store.js'
  64. import {
  65. getLookUpDatas
  66. } from '@/api/data.js'
  67. import {
  68. getUnFinishedOrder
  69. } from '@/api/order.js'
  70. export default {
  71. components: {
  72. uniNavBar,
  73. uniPopup
  74. },
  75. data() {
  76. return {
  77. workStatus: '',
  78. mapCtx: null, // 地图对象
  79. markers: [], // 标注点
  80. lng: '',
  81. lat: '',
  82. showPop: false // 是否显示用户未授权提示框
  83. }
  84. },
  85. onReady() {
  86. this.mapCtx = uni.createMapContext('map')
  87. },
  88. onShow() {
  89. this.getUserLocation()
  90. // 查询是否有未完成的订单
  91. this.getUnFinishedOrder()
  92. },
  93. onLoad() {
  94. // 获取订单状态数据字典
  95. this.getCodeList('ORDER_STATUS')
  96. // 获取支付方式数据字典
  97. this.getCodeList('PAY_TYPE')
  98. // 获取网点标签数据字典
  99. this.getCodeList('STORE_LABEL')
  100. },
  101. methods: {
  102. // 查询是否有未完成的订单
  103. getUnFinishedOrder(){
  104. getUnFinishedOrder().then(res => {
  105. console.log(res)
  106. if(res.status == 200 && res.data){
  107. this.workStatus = 'show'
  108. // 还未启动
  109. if(res.data.dataStatus == "PAID"){
  110. this.$u.vuex('vuex_workStatus','linking')
  111. }
  112. }else{
  113. this.workStatus = 'hide'
  114. }
  115. })
  116. },
  117. // 获取数据字典
  118. getCodeList(code) {
  119. getLookUpDatas({
  120. type: code
  121. }).then(res => {
  122. if (res.status == 200) {
  123. console.log(res.data, 'res.data')
  124. switch (code) {
  125. case 'ORDER_STATUS':
  126. this.$u.vuex('vuex_payStatus', res.data)
  127. break;
  128. case 'PAY_TYPE':
  129. this.$u.vuex('vuex_payType', res.data)
  130. break;
  131. case 'STORE_LABEL':
  132. this.$u.vuex('vuex_storeLabel', res.data)
  133. break;
  134. default:
  135. break;
  136. }
  137. }
  138. })
  139. },
  140. // 如果机器正在运行,提示并点击跳转的运行界面
  141. toWork() {
  142. uni.navigateTo({
  143. url: "/pages/work/index/index"
  144. })
  145. },
  146. // 用户位置信息授权
  147. getUserLocation() {
  148. let _this = this
  149. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope H5及APP平台不适用
  150. // H5及APP平台适配代码
  151. // #ifndef H5 || APP-PLUS
  152. uni.getSetting({
  153. success(res) {
  154. if (!res.authSetting['scope.userLocation']) {
  155. uni.authorize({
  156. scope: 'scope.userLocation',
  157. success(res) {
  158. // 用户已经同意小程序使用位置信息,后续调用 uni.getLocation 接口不会弹窗询问
  159. _this.getLocation()
  160. },
  161. // 用户拒绝授权位置信息时默认展示青海西宁位置地图
  162. fail: (err) => {
  163. _this.showPop = true
  164. }
  165. })
  166. } else {
  167. _this.getLocation()
  168. }
  169. }
  170. })
  171. // #endif
  172. },
  173. // 打开位置设置界面
  174. intoSetting () {
  175. let _this = this
  176. uni.openSetting({
  177. success(res) {
  178. console.log(res,'222')
  179. let data = res.authSetting
  180. if (data['scope.userLocation']) {
  181. _this.showPop = false
  182. _this.getLocation()
  183. } else {
  184. _this.showPop = true
  185. }
  186. },
  187. fail() {
  188. _this.showPop = true
  189. }
  190. })
  191. },
  192. // 获取用户位置
  193. getLocation() {
  194. uni.getLocation({
  195. type: 'gcj02',
  196. success: (res) => {
  197. console.log(res, 'rrrr')
  198. this.showPop = false
  199. let latitude = res.latitude;
  200. let longitude = res.longitude;
  201. this.lng = longitude
  202. this.lat = latitude
  203. this.markers = this.getMarkersData()
  204. },
  205. // 定位失败默认展示青海西宁位置地图
  206. fail: (err) => {
  207. this.lng = '101.760521'
  208. this.lat = '36.636193'
  209. this.markers = this.getMarkersData()
  210. }
  211. });
  212. },
  213. // 点击标点进入网点详情
  214. markertap(e) {
  215. console.log(e)
  216. uni.navigateTo({
  217. url: `/pages/store/storeDetail?id=${e.markerId}`
  218. })
  219. },
  220. // 获取所有标记点数据
  221. getMarkersData() {
  222. uni.showLoading({
  223. title: '加载中...'
  224. })
  225. let params = {
  226. lat: this.lat,
  227. lng: this.lng
  228. }
  229. getMapStoreList(params).then(res => {
  230. uni.hideLoading()
  231. if (res.status == 200) {
  232. let markData = res.data
  233. let markers = [];
  234. for (let item of markData) {
  235. let marker = this.createMarker(item);
  236. markers.push(marker)
  237. }
  238. this.markers = markers
  239. console.log(this.markers, '111111')
  240. } else {
  241. this.toashMsg(res.message)
  242. }
  243. })
  244. },
  245. // 点击回到定位坐标点
  246. moveToLocation() {
  247. this.mapCtx.moveToLocation()
  248. },
  249. // 进入个人中心
  250. toUserCenter() {
  251. uni.showLoading({
  252. title: "正在加载..."
  253. })
  254. // 检验是否登录或登录是否过期
  255. checkLogin().then(res => {
  256. console.log(res)
  257. uni.hideLoading()
  258. if (res.status == '200') {
  259. uni.navigateTo({
  260. url: '/pages/userCenter/index'
  261. })
  262. } else if (res.status == '9001') {
  263. uni.navigateTo({
  264. url: `/pages/login/login?lanuch=${false}&path=` + encodeURIComponent('/pages/userCenter/index')
  265. })
  266. }else if (res.status == '6000'){
  267. this.toashMsg(res.message)
  268. }
  269. })
  270. },
  271. // 打开网点列表
  272. intoList() {
  273. uni.navigateTo({
  274. url: '/pages/store/storeList'
  275. })
  276. },
  277. // 联系客服
  278. openPop() {
  279. let _this = this
  280. uni.showActionSheet({
  281. itemList: ['电话客服'],
  282. success: function(res) {
  283. //电话客服
  284. if (res.tapIndex == 0) {
  285. _this.callPhone()
  286. }
  287. },
  288. fail: function(res) {
  289. console.log(res.errMsg);
  290. }
  291. });
  292. },
  293. // 电话客服
  294. callPhone() {
  295. uni.makePhoneCall({
  296. phoneNumber: '18237162131'
  297. })
  298. },
  299. // 扫描领取优惠卷
  300. scanCoupon(){
  301. uni.scanCode({
  302. success: function (res) {
  303. if(res.scanType == 'WX_CODE'){
  304. console.log(res.path)
  305. uni.navigateTo({
  306. url: '/'+res.path
  307. })
  308. }else{
  309. _this.toashMsg("无法识别此二维码")
  310. }
  311. }
  312. });
  313. },
  314. // 扫码洗车
  315. scanCode () {
  316. let _this = this
  317. uni.showLoading({
  318. title: "正在加载..."
  319. })
  320. // 检验是否登录或登录是否过期
  321. checkLogin().then(res => {
  322. console.log(res)
  323. uni.hideLoading()
  324. if (res.status == '200') {
  325. uni.scanCode({
  326. success: function (res) {
  327. console.log(res);
  328. if(res.scanType == 'WX_CODE'){
  329. uni.navigateTo({
  330. url: '/'+res.path
  331. })
  332. }else{
  333. _this.toashMsg("无法识别此二维码")
  334. }
  335. }
  336. });
  337. } else if (res.status == '9001') {
  338. uni.navigateTo({
  339. url: `/pages/login/login?lanuch=${false}&path=` + encodeURIComponent('/pages/index/index')
  340. })
  341. } else if (res.status == '6000'){
  342. this.toashMsg(res.message)
  343. }
  344. })
  345. },
  346. // 创建标记点 设备状态 USING :使用中 PAUSE:暂停 ON_LINE:在线
  347. createMarker(point) {
  348. let latitude = point.lat;
  349. let longitude = point.lng;
  350. let iconPath = ''
  351. if (point.deviceStatus === 'PAUSE') {
  352. iconPath = '/static/img/store-dky.png'
  353. } else if (point.deviceStatus === 'USING' || point.deviceStatus === 'ON_LINE') {
  354. let today = new Date().toLocaleDateString() // 获取今天日期
  355. let beginTime = today + ' ' + point.beginTime
  356. let endTime = today + ' ' + point.endTime
  357. let beginTimeStamp = new Date(beginTime).getTime() // 获取开始时间戳
  358. let endTimeStamp = new Date(endTime).getTime() // 获取结束时间戳
  359. let nowTimeStamp = new Date().getTime() // 获取当前时间戳
  360. // 结束时间小于开始时间时 为跨天 结束时间应加1天
  361. endTimeStamp = endTimeStamp <=beginTimeStamp ? (endTimeStamp+24*60*60*1000) : endTimeStamp
  362. // 根据当前时间判断目前是否在营业时间范围内
  363. if (nowTimeStamp>=beginTimeStamp && nowTimeStamp<=endTimeStamp) {
  364. iconPath = '/static/img/store.png'
  365. } else {
  366. iconPath = '/static/img/store-dky.png'
  367. }
  368. } else {
  369. iconPath = '/static/img/store-zt.png'
  370. }
  371. let marker = {
  372. iconPath: iconPath,
  373. id: point.id || 0,
  374. name: point.name || '',
  375. latitude: latitude,
  376. longitude: longitude,
  377. width: 30,
  378. height: 49,
  379. callout: {
  380. content: point.name,
  381. fontSize: 14,
  382. }
  383. };
  384. return marker;
  385. }
  386. }
  387. }
  388. </script>
  389. <style lang="scss" scoped>
  390. .content {
  391. display: flex;
  392. flex-direction: column;
  393. align-items: center;
  394. justify-content: center;
  395. padding: 0;
  396. .pageContent {
  397. width: 100%;
  398. flex: 1;
  399. .work-message {
  400. position: absolute;
  401. top: 6%;
  402. width: 80%;
  403. left: 50%;
  404. margin-left: -40%;
  405. background: rgba(0, 0, 0, 0.6);
  406. border-radius: 100rpx;
  407. color: #eee;
  408. .work-message-in {
  409. display: flex;
  410. align-items: center;
  411. padding: 26rpx;
  412. .view {
  413. &:first-child {
  414. flex-grow: 1;
  415. text-align: center;
  416. }
  417. &:last-child {
  418. font-size: 24rpx;
  419. color: #fff;
  420. display: flex;
  421. align-items: center;
  422. }
  423. }
  424. }
  425. }
  426. .cover-view {
  427. position: absolute;
  428. top: calc(60% - 150rpx);
  429. left: calc(50% - 360rpx);
  430. .flex-wrp {
  431. display: flex;
  432. flex-direction: column;
  433. background: rgba(0, 0, 0, 0.3);
  434. border-radius: 10rpx;
  435. padding: 10rpx 0;
  436. }
  437. .flex-item {
  438. width: 110rpx;
  439. height: 110rpx;
  440. font-size: 24rpx;
  441. color: #F8F8F8;
  442. display: flex;
  443. flex-direction: column;
  444. justify-content: center;
  445. align-items: center;
  446. .img {
  447. width: 50rpx;
  448. height: 50rpx;
  449. margin-bottom: 10rpx;
  450. }
  451. }
  452. }
  453. .cover-location {
  454. position: absolute;
  455. top: calc(75%);
  456. left: calc(85%);
  457. .img {
  458. width: 80rpx;
  459. height: 80rpx;
  460. }
  461. }
  462. .cover-bottom {
  463. position: absolute;
  464. bottom: calc(60rpx);
  465. width: 80%;
  466. left: calc(9%);
  467. uni-button[type=warn] {
  468. background: red;
  469. u-icon {
  470. margin-right: 15rpx;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. </style>