index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 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. })
  110. },
  111. // 获取数据字典
  112. getCodeList(code) {
  113. getLookUpDatas({
  114. type: code
  115. }).then(res => {
  116. if (res.status == 200) {
  117. console.log(res.data, 'res.data')
  118. switch (code) {
  119. case 'ORDER_STATUS':
  120. this.$u.vuex('vuex_payStatus', res.data)
  121. break;
  122. case 'PAY_TYPE':
  123. this.$u.vuex('vuex_payType', res.data)
  124. break;
  125. case 'STORE_LABEL':
  126. this.$u.vuex('vuex_storeLabel', res.data)
  127. break;
  128. default:
  129. break;
  130. }
  131. }
  132. })
  133. },
  134. // 如果机器正在运行,提示并点击跳转的运行界面
  135. toWork() {
  136. uni.navigateTo({
  137. url: "/pages/work/index/index"
  138. })
  139. },
  140. // 用户位置信息授权
  141. getUserLocation() {
  142. let _this = this
  143. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope H5及APP平台不适用
  144. // H5及APP平台适配代码
  145. // #ifndef H5 || APP-PLUS
  146. uni.getSetting({
  147. success(res) {
  148. if (!res.authSetting['scope.userLocation']) {
  149. uni.authorize({
  150. scope: 'scope.userLocation',
  151. success(res) {
  152. // 用户已经同意小程序使用位置信息,后续调用 uni.getLocation 接口不会弹窗询问
  153. _this.getLocation()
  154. },
  155. // 用户拒绝授权位置信息时默认展示青海西宁位置地图
  156. fail: (err) => {
  157. _this.showPop = true
  158. }
  159. })
  160. } else {
  161. _this.getLocation()
  162. }
  163. }
  164. })
  165. // #endif
  166. },
  167. // 打开位置设置界面
  168. intoSetting () {
  169. let _this = this
  170. uni.openSetting({
  171. success(res) {
  172. console.log(res,'222')
  173. let data = res.authSetting
  174. if (data['scope.userLocation']) {
  175. _this.showPop = false
  176. _this.getLocation()
  177. } else {
  178. _this.showPop = true
  179. }
  180. },
  181. fail() {
  182. _this.showPop = true
  183. }
  184. })
  185. },
  186. // 获取用户位置
  187. getLocation() {
  188. uni.getLocation({
  189. type: 'gcj02',
  190. success: (res) => {
  191. console.log(res, 'rrrr')
  192. this.showPop = false
  193. let latitude = res.latitude;
  194. let longitude = res.longitude;
  195. this.lng = longitude
  196. this.lat = latitude
  197. this.markers = this.getMarkersData()
  198. },
  199. // 定位失败默认展示青海西宁位置地图
  200. fail: (err) => {
  201. this.lng = '101.760521'
  202. this.lat = '36.636193'
  203. this.markers = this.getMarkersData()
  204. }
  205. });
  206. },
  207. // 点击标点进入网点详情
  208. markertap(e) {
  209. console.log(e)
  210. uni.navigateTo({
  211. url: `/pages/store/storeDetail?id=${e.markerId}`
  212. })
  213. },
  214. // 获取所有标记点数据
  215. getMarkersData() {
  216. uni.showLoading({
  217. title: '加载中...'
  218. })
  219. let params = {
  220. lat: this.lat,
  221. lng: this.lng
  222. }
  223. getMapStoreList(params).then(res => {
  224. uni.hideLoading()
  225. if (res.status == 200) {
  226. let markData = res.data
  227. let markers = [];
  228. for (let item of markData) {
  229. let marker = this.createMarker(item);
  230. markers.push(marker)
  231. }
  232. this.markers = markers
  233. console.log(this.markers, '111111')
  234. } else {
  235. this.toashMsg(res.message)
  236. }
  237. })
  238. },
  239. // 点击回到定位坐标点
  240. moveToLocation() {
  241. this.mapCtx.moveToLocation()
  242. },
  243. // 进入个人中心
  244. toUserCenter() {
  245. uni.showLoading({
  246. title: "正在加载..."
  247. })
  248. // 检验是否登录或登录是否过期
  249. checkLogin().then(res => {
  250. console.log(res)
  251. uni.hideLoading()
  252. if (res.status == '200') {
  253. uni.navigateTo({
  254. url: '/pages/userCenter/index'
  255. })
  256. } else if (res.status == '9001') {
  257. uni.navigateTo({
  258. url: `/pages/login/login?lanuch=${false}&path=` + encodeURIComponent('/pages/userCenter/index')
  259. })
  260. }else if (res.status == '6000'){
  261. this.toashMsg(res.message)
  262. }
  263. })
  264. },
  265. // 打开网点列表
  266. intoList() {
  267. uni.navigateTo({
  268. url: '/pages/store/storeList'
  269. })
  270. },
  271. // 联系客服
  272. openPop() {
  273. let _this = this
  274. uni.showActionSheet({
  275. itemList: ['电话客服'],
  276. success: function(res) {
  277. //电话客服
  278. if (res.tapIndex == 0) {
  279. _this.callPhone()
  280. }
  281. },
  282. fail: function(res) {
  283. console.log(res.errMsg);
  284. }
  285. });
  286. },
  287. // 电话客服
  288. callPhone() {
  289. uni.makePhoneCall({
  290. phoneNumber: '114'
  291. })
  292. },
  293. // 扫码洗车
  294. scanCode () {
  295. let _this = this
  296. uni.showLoading({
  297. title: "正在加载..."
  298. })
  299. // 检验是否登录或登录是否过期
  300. checkLogin().then(res => {
  301. console.log(res)
  302. uni.hideLoading()
  303. if (res.status == '200') {
  304. uni.scanCode({
  305. success: function (res) {
  306. console.log('条码类型:' + res.scanType);
  307. console.log('条码内容:' + res.result);
  308. // if(res.scanType !== 'WX_CODE'){
  309. // _this.toashMsg("无法识别此二维码")
  310. // }
  311. uni.navigateTo({
  312. url: res.result
  313. })
  314. // uni.navigateTo({
  315. // url: `/pages/getOrder/getOrder?scene=100032,9691`
  316. // })
  317. }
  318. });
  319. } else if (res.status == '9001') {
  320. uni.navigateTo({
  321. url: `/pages/login/login?lanuch=${false}&path=` + encodeURIComponent('/pages/index/index')
  322. })
  323. } else if (res.status == '6000'){
  324. this.toashMsg(res.message)
  325. }
  326. })
  327. },
  328. // 创建标记点 OPEN :正常营业 CLOSED:暂停营业 TO_BE_OPENED:待开业
  329. createMarker(point) {
  330. let latitude = point.lat;
  331. let longitude = point.lng;
  332. let iconPath = ''
  333. if (point.businessStatus === 'CLOSED') {
  334. iconPath = '/static/img/store-dky.png'
  335. } else if (point.businessStatus === 'OPEN') {
  336. let today = new Date().toLocaleDateString() // 获取今天日期
  337. let beginTime = today + ' ' + point.beginTime
  338. let endTime = today + ' ' + point.endTime
  339. let beginTimeStamp = new Date(beginTime).getTime() // 获取开始时间戳
  340. let endTimeStamp = new Date(endTime).getTime() // 获取结束时间戳
  341. let nowTimeStamp = new Date().getTime() // 获取当前时间戳
  342. // 结束时间小于开始时间时 为跨天 结束时间应加1天
  343. endTimeStamp = endTimeStamp <=beginTimeStamp ? (endTimeStamp+24*60*60*1000) : endTimeStamp
  344. // 根据当前时间判断目前是否在营业时间范围内
  345. if (nowTimeStamp>=beginTimeStamp && nowTimeStamp<=endTimeStamp) {
  346. iconPath = '/static/img/store.png'
  347. } else {
  348. iconPath = '/static/img/store-dky.png'
  349. }
  350. } else {
  351. iconPath = '/static/img/store-zt.png'
  352. }
  353. let marker = {
  354. iconPath: iconPath,
  355. id: point.id || 0,
  356. name: point.name || '',
  357. latitude: latitude,
  358. longitude: longitude,
  359. width: 30,
  360. height: 49,
  361. callout: {
  362. content: point.name,
  363. fontSize: 14,
  364. }
  365. };
  366. return marker;
  367. }
  368. }
  369. }
  370. </script>
  371. <style lang="scss" scoped>
  372. .content {
  373. display: flex;
  374. flex-direction: column;
  375. align-items: center;
  376. justify-content: center;
  377. padding: 0;
  378. .pageContent {
  379. width: 100%;
  380. flex: 1;
  381. .work-message {
  382. position: absolute;
  383. top: 6%;
  384. width: 80%;
  385. left: 50%;
  386. margin-left: -40%;
  387. background: rgba(0, 0, 0, 0.6);
  388. border-radius: 100rpx;
  389. color: #eee;
  390. .work-message-in {
  391. display: flex;
  392. align-items: center;
  393. padding: 26rpx;
  394. .view {
  395. &:first-child {
  396. flex-grow: 1;
  397. text-align: center;
  398. }
  399. &:last-child {
  400. font-size: 24rpx;
  401. color: #fff;
  402. display: flex;
  403. align-items: center;
  404. }
  405. }
  406. }
  407. }
  408. .cover-view {
  409. position: absolute;
  410. top: calc(60% - 150rpx);
  411. left: calc(50% - 360rpx);
  412. .flex-wrp {
  413. display: flex;
  414. flex-direction: column;
  415. background: rgba(0, 0, 0, 0.3);
  416. border-radius: 10rpx;
  417. padding: 10rpx 0;
  418. }
  419. .flex-item {
  420. width: 110rpx;
  421. height: 110rpx;
  422. font-size: 24rpx;
  423. color: #F8F8F8;
  424. display: flex;
  425. flex-direction: column;
  426. justify-content: center;
  427. align-items: center;
  428. .img {
  429. width: 50rpx;
  430. height: 50rpx;
  431. margin-bottom: 10rpx;
  432. }
  433. }
  434. }
  435. .cover-location {
  436. position: absolute;
  437. top: calc(75%);
  438. left: calc(85%);
  439. .img {
  440. width: 80rpx;
  441. height: 80rpx;
  442. }
  443. }
  444. .cover-bottom {
  445. position: absolute;
  446. bottom: calc(60rpx);
  447. width: 80%;
  448. left: calc(9%);
  449. uni-button[type=warn] {
  450. background: red;
  451. u-icon {
  452. margin-right: 15rpx;
  453. }
  454. }
  455. }
  456. }
  457. }
  458. </style>