selectHotel.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="search-area">
  3. <uni-search-bar class="search-bar" placeholder="酒店搜索" v-model="hotelName" cancel-button="none"
  4. @input="searchHotel"></uni-search-bar>
  5. <uni-icons class="icon" type="scan" size="30" @click="scanQRCode"></uni-icons>
  6. </view>
  7. <view class="hotel-list">
  8. <view class="hotel-item" v-for="hotel in hotelListFiltered" :key="hotel.hotelId" @click="selectHotel(hotel)">
  9. <image :src="hotel.picturePath"></image>
  10. <text>{{hotel.name}}</text>
  11. </view>
  12. </view>
  13. </template>
  14. <script setup>
  15. import {
  16. reactive,
  17. ref
  18. } from 'vue'
  19. import {
  20. onLoad
  21. } from '@dcloudio/uni-app'
  22. import {
  23. useHotelStore
  24. } from '../../store/hotelStore'
  25. import {
  26. useAppInfoStore
  27. } from '../../store/appInfoStore'
  28. let hotelName = ref('')
  29. let source = 'home'
  30. let hotelStore = useHotelStore()
  31. let hotel = useHotelStore().hotel
  32. let appInfo = useAppInfoStore()
  33. let hotelList = reactive([])
  34. let hotelListFiltered = reactive([])
  35. async function getHotels() {
  36. let res = await uni.request({
  37. url: '/hotel/available',
  38. method: 'POST',
  39. data: {
  40. appId: appInfo.appId
  41. }
  42. })
  43. hotelList.push(...res.data.data)
  44. hotelListFiltered.push(...res.data.data)
  45. }
  46. function searchHotel(name) {
  47. hotelListFiltered.length = 0
  48. if (name) {
  49. hotelListFiltered.push(...hotelList.filter((hotel) => {
  50. return hotel.name.includes(name)
  51. }))
  52. } else {
  53. hotelListFiltered.push(...hotelList)
  54. }
  55. console.log(hotelListFiltered)
  56. }
  57. async function scanQRCode() {
  58. // let scanRes = await uni.scanCode({
  59. // scanType:['qrCode']
  60. // })
  61. let o = "http://www.baidu.com?name=elephant&age=25&sex=male&num=100"
  62. console.log(uni.parseQuery(o))
  63. }
  64. function selectHotel(hotel) {
  65. console.log(hotel)
  66. hotelStore.updateHotel(hotel)
  67. if (source === 'home') {
  68. uni.switchTab({
  69. url: '/pages/home/home'
  70. })
  71. } else if (source === 'selectCheckinType') {
  72. uni.navigateBack()
  73. }
  74. }
  75. onLoad(async (options) => {
  76. source = options.source
  77. hotelList.length = 0
  78. hotelListFiltered.length = 0
  79. await getHotels()
  80. })
  81. </script>
  82. <style lang="scss">
  83. page {
  84. background-color: #ffffff;
  85. }
  86. .search-area {
  87. background-color: #f0eff5;
  88. display: flex;
  89. align-items: center;
  90. justify-content: space-between;
  91. padding: 0 20rpx;
  92. .search-bar {
  93. width: 80vw;
  94. }
  95. .icon {
  96. margin-right: 20rpx;
  97. }
  98. }
  99. .hotel-list {
  100. margin: 20rpx;
  101. background-color: #ffffff;
  102. .hotel-item {
  103. display: flex;
  104. align-items: center;
  105. background-color: #f1f1f4;
  106. border-radius: 20rpx;
  107. image {
  108. width: 180rpx;
  109. height: 180rpx;
  110. margin: 20rpx;
  111. }
  112. text {
  113. margin-left: 20rpx;
  114. font-size: 40rpx;
  115. }
  116. }
  117. }
  118. </style>