123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <template>
- <view class="search-area">
- <uni-search-bar class="search-bar" placeholder="酒店搜索" v-model="hotelName" cancel-button="none"
- @input="searchHotel"></uni-search-bar>
- <uni-icons class="icon" type="scan" size="30" @click="scanQRCode"></uni-icons>
- </view>
- <view class="hotel-list">
- <view class="hotel-item" v-for="hotel in hotelListFiltered" :key="hotel.hotelId" @click="selectHotel(hotel)">
- <image :src="hotel.picturePath"></image>
- <text>{{hotel.name}}</text>
- </view>
- </view>
- </template>
- <script setup>
- import {
- reactive,
- ref
- } from 'vue'
- import {
- onLoad
- } from '@dcloudio/uni-app'
- import {
- useHotelStore
- } from '../../store/hotelStore'
- import {
- useAppInfoStore
- } from '../../store/appInfoStore'
- let hotelName = ref('')
- let source = 'home'
- let hotelStore = useHotelStore()
- let hotel = useHotelStore().hotel
- let appInfo = useAppInfoStore()
- let hotelList = reactive([])
- let hotelListFiltered = reactive([])
- async function getHotels() {
- let res = await uni.request({
- url: '/hotel/available',
- method: 'POST',
- data: {
- appId: appInfo.appId
- }
- })
- hotelList.push(...res.data.data)
- hotelListFiltered.push(...res.data.data)
- }
- function searchHotel(name) {
- hotelListFiltered.length = 0
- if (name) {
- hotelListFiltered.push(...hotelList.filter((hotel) => {
- return hotel.name.includes(name)
- }))
- } else {
- hotelListFiltered.push(...hotelList)
- }
- console.log(hotelListFiltered)
- }
- async function scanQRCode() {
- // let scanRes = await uni.scanCode({
- // scanType:['qrCode']
- // })
- let o = "http://www.baidu.com?name=elephant&age=25&sex=male&num=100"
- console.log(uni.parseQuery(o))
- }
- function selectHotel(hotel) {
- console.log(hotel)
- hotelStore.updateHotel(hotel)
- if (source === 'home') {
- uni.switchTab({
- url: '/pages/home/home'
- })
- } else if (source === 'selectCheckinType') {
- uni.navigateBack()
- }
- }
- onLoad(async (options) => {
- source = options.source
- hotelList.length = 0
- hotelListFiltered.length = 0
- await getHotels()
- })
- </script>
- <style lang="scss">
- page {
- background-color: #ffffff;
- }
- .search-area {
- background-color: #f0eff5;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 20rpx;
- .search-bar {
- width: 80vw;
- }
- .icon {
- margin-right: 20rpx;
- }
- }
- .hotel-list {
- margin: 20rpx;
- background-color: #ffffff;
- .hotel-item {
- display: flex;
- align-items: center;
- background-color: #f1f1f4;
- border-radius: 20rpx;
- image {
- width: 180rpx;
- height: 180rpx;
- margin: 20rpx;
- }
- text {
- margin-left: 20rpx;
- font-size: 40rpx;
- }
- }
- }
- </style>
|