index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view class="content">
  3. <!-- <image class="logo" src="/static/logo.png"/>
  4. <view class="text-area">
  5. <text class="title">{{ title }}</text>
  6. </view>-->
  7. <view style="width: 100%;" class="swiper-content">
  8. <uv-swiper
  9. class="swiper-item-1"
  10. style="width: 100%"
  11. :list="state.swiperList"
  12. previousMargin="30"
  13. nextMargin="30"
  14. circular
  15. :autoplay="true"
  16. radius="5"
  17. bgColor="#ffffff">
  18. </uv-swiper>
  19. </view>
  20. <view class="w100">
  21. <uv-notice-bar mode="closable" speed="50" url="/pages/coupon/index" :text="state.notice"></uv-notice-bar>
  22. </view>
  23. <view class="w100 gap"></view>
  24. <view class="menu-content w100">
  25. <uv-grid :border="false" :col="4">
  26. <uv-grid-item v-for="(item,index) in state.menuList" :key="index" @click="handleMenuClick(item)">
  27. <uv-icon :customStyle="{paddingTop:20+'rpx'}" :name="item.name" :size="22"></uv-icon>
  28. <text class="grid-text">{{ item.title }}</text>
  29. </uv-grid-item>
  30. </uv-grid>
  31. </view>
  32. <view class="w100 gap"></view>
  33. <!-- 站点清单 start-->
  34. <view class="w100 content_station" >
  35. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  36. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  37. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  38. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  39. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  40. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  41. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  42. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  43. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  44. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  45. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  46. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  47. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  48. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  49. <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
  50. </view>
  51. <!-- 站点清单 end-->
  52. <!-- <cover-view class="login_bar">
  53. <login-bar class="w100 text-center"></login-bar>
  54. </cover-view>-->
  55. <!-- <cover-view class="login_bar" v-show="!isLogin">-->
  56. <login-bar class="w100 text-center"></login-bar>
  57. <!-- </cover-view>-->
  58. <tab-bar :index="0" ></tab-bar>
  59. </view>
  60. </template>
  61. <script setup lang="ts">
  62. import {reactive, ref} from 'vue'
  63. import {onHide, onShow, onLoad} from "@dcloudio/uni-app";
  64. import TabBar from "@/components/tab-bar/index.vue";
  65. import LoginBar from "@/components/login-bar/index.vue";
  66. import WashStation from "@/components/station/index.vue"
  67. import {get, post} from "@/utils/https";
  68. import {calcMapDistance} from "@/utils/common"
  69. import {checkLogin} from "@/utils/auth";
  70. const title = ref('Hello')
  71. const isLogin = ref(false)
  72. const change = () => {
  73. console.log("change")
  74. }
  75. const initState = () => ({
  76. swiperList: [
  77. 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  78. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  79. 'https://cdn.uviewui.com/uview/swiper/swiper1.png'
  80. ],
  81. menuList: [
  82. {name: "photo", title: "洗车"},
  83. {name: "lock", title: "充值"},
  84. {name: "star", title: "卡券"},
  85. {name: "red-packet", title: "停车"},
  86. ],
  87. qrcodeOption: {
  88. style: 'round',
  89. size: 230,
  90. // 指定二维码前景,一般可在中间放logo
  91. foregroundImageSrc: 'https://www.uvui.cn/common/logo.png'
  92. },
  93. customStyle: {
  94. 'margin-top': '40rpx',
  95. height: '80rpx',
  96. width: '80%',
  97. borderRadius: '40rpx',//圆角
  98. },
  99. notice: '中秋佳节,全场8折,快来洗车吧!',
  100. stationList: [],
  101. location: {
  102. latitude: 0,
  103. longitude: 0,
  104. }
  105. })
  106. const state = reactive(initState())
  107. onLoad((e: any) => {
  108. let query = decodeURIComponent(e);
  109. let scanTime = e.scancode_time;
  110. console.log(e)
  111. /* if (query) {
  112. uni.showToast({
  113. title: query,
  114. duration: 5000
  115. })
  116. }*/
  117. })
  118. onShow(() => {
  119. const userData = getApp<any>().globalData.user;
  120. if (userData&&userData.id) {
  121. isLogin.value = true;
  122. }
  123. console.log("show index>>>>",isLogin.value,state.stationList,state.location)
  124. let locationData = getApp<any>().globalData.location;
  125. if(!locationData||!locationData.longitude){
  126. loadCurrentLocation();
  127. }else{
  128. state.location = locationData;
  129. loadWashStationList();
  130. }
  131. uni.$on('loginEvent', function (data) {
  132. isLogin.value = data.isLogin;
  133. })
  134. });
  135. onHide(() => {
  136. Object.assign(state, initState());
  137. })
  138. const handleMenuClick = (menu:any) => {
  139. checkLogin().then((res)=>{
  140. if(menu.title==='洗车'){
  141. uni.navigateTo({
  142. url:'/pages-wash/scan/index'
  143. })
  144. }else if(menu.title==='充值'){
  145. uni.navigateTo({
  146. url:'/pages-user/wallet/recharge'
  147. })
  148. }
  149. })
  150. }
  151. /**
  152. * 获取当前的地理位置
  153. */
  154. const loadCurrentLocation = () => {
  155. uni.authorize({
  156. scope: 'scope.userLocation',
  157. success() {
  158. uni.getLocation({
  159. type: 'gcj02', //返回可以用于uni.openLocation的经纬度
  160. success: res => {
  161. let location = {
  162. latitude: res.latitude,
  163. longitude: res.longitude
  164. }
  165. getApp<any>().globalData.location = location;
  166. state.location = location
  167. loadWashStationList();
  168. console.log("loadCurrentLocation location", res)
  169. }
  170. });
  171. },
  172. fail(e) {
  173. loadWashStationList();
  174. console.log("authorize location fail", e)
  175. }
  176. })
  177. }
  178. const loadWashStationList = () => {
  179. post(`/wash-station/listStation`, {pageSize: 5}).then((res: any) => {
  180. console.log(res)
  181. let {list, total} = res;
  182. list.forEach((station: any) => {
  183. if (station.location) {
  184. let stationLocation = JSON.parse(station.location);
  185. station.distance = calcMapDistance(state.location.latitude,state.location.longitude,stationLocation.stationLat,stationLocation.stationLng);
  186. }
  187. })
  188. state.stationList = list;
  189. })
  190. }
  191. const handleNavMap = (station:any) => {
  192. let location = JSON.parse(station.location)
  193. uni.openLocation({
  194. latitude: location.stationLat,
  195. longitude: location.stationLng,
  196. scale: 18,
  197. name: station.stationName,
  198. address: station.address,
  199. });
  200. }
  201. const handleNavStation = (station: any) => {
  202. getApp<any>().globalData.pageData = {station}
  203. uni.navigateTo({
  204. url: '/pages-wash/station/index?id='+station.id
  205. })
  206. console.log(station)
  207. }
  208. </script>
  209. <style scoped lang="scss">
  210. .content {
  211. width: 100%;
  212. display: flex;
  213. flex-direction: column;
  214. align-items: center;
  215. justify-content: center;
  216. border-radius: 8rpx;
  217. }
  218. .logo {
  219. height: 200rpx;
  220. width: 200rpx;
  221. margin: 200rpx auto 50rpx;
  222. }
  223. .menu-content {
  224. width: 100%;
  225. padding: 0 20rpx;
  226. border-radius: 8rpx;
  227. }
  228. .qrcode-content {
  229. margin-top: 40rpx;
  230. padding: 0 20rpx;
  231. width: 100%;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. align-content: center;
  236. justify-content: center;
  237. }
  238. .gap {
  239. width: 100%;
  240. height: 36rpx;
  241. background-color: #f5f3f3;
  242. margin-top: 10rpx;
  243. margin-bottom: 10rpx;
  244. }
  245. .swiper-content{
  246. height: 200rpx;
  247. }
  248. .guide-content {
  249. text-align: center;
  250. }
  251. .loginbar {
  252. position: fixed;
  253. bottom: 20rpx;
  254. }
  255. .content_station{
  256. height: calc(100vh - 600rpx );
  257. overflow: scroll;
  258. }
  259. </style>