index.vue 8.9 KB

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