chooseHotel.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="choose-hotel">
  3. <view class="top">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <NavigateBar title="酒店选择" control="home" bgcolor="#a09cc4"></NavigateBar>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-ALIPAY -->
  8. <NavigateBar title="酒店选择" bgcolor="#a09cc4"></NavigateBar>
  9. <!-- #endif -->
  10. <view class="choose-hotel--input">
  11. <view class="choose-hotel--input__frame">
  12. <u-search placeholder="酒店搜索" v-model="hotelName" bgColor="#ffffff" shape="square"
  13. :showAction="false" color="#181818" margin="0" @change="inputChanged">
  14. </u-search>
  15. </view>
  16. <view class="choose-hotel--input__scan" @click="scanQRCode" v-if="displayScanner">
  17. <u-icon name="scan" color="#4f4e51" size="28"></u-icon>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="choose-hotel--dispaly-area" v-if="!notFound">
  22. <view class="choose-hotel--description" v-for="(hotel, index) in hotelList" :key="index">
  23. <view class="choose-hotel--description__hotel" @click="goBack(hotel)">
  24. <view class="choose-hotel--description__hotel-pic">
  25. <u-image :src="getHotelPicPath(hotel.picturePath)" width="180rpx" height="180rpx"></u-image>
  26. </view>
  27. <view class="choose-hotel--description__hotel-name">
  28. {{ hotel.name }}
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="choose-hotel--not-found" v-if="notFound">{{`未查询到名称中包含“${hotelName}”的酒店`}}</view>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. IMG_BASE_URL
  39. } from "../../config"
  40. import {
  41. mapMutations
  42. } from 'vuex'
  43. import getParamByName from 'get-param-by-name'
  44. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  45. export default {
  46. components: {
  47. NavigateBar
  48. },
  49. data() {
  50. return {
  51. hotelName: "",
  52. hotelList: [],
  53. notFound: false,
  54. displayScanner: true,
  55. source: "",
  56. }
  57. },
  58. methods: {
  59. ...mapMutations('m_business', ['updateCurrentHotel']),
  60. async inputChanged() {
  61. this.notFound = false
  62. let res = await uni.$http.get(`/hotel/hotelName/${this.hotelName}`)
  63. if (res.data.data.length === 0) {
  64. this.notFound = true
  65. return
  66. }
  67. this.hotelList = res.data.data
  68. },
  69. inputFocusd() {
  70. // 取得焦点时显示shortcut
  71. console.log("input focused");
  72. },
  73. inputBlured() {
  74. // 失去焦点时关闭shortcut
  75. console.log("inpot blured");
  76. },
  77. async scanQRCode() {
  78. // #ifdef MP-WEIXIN
  79. let scanResWX = await wx.scanCode({
  80. scanType: ['qrCode']
  81. })
  82. // console.log("扫描二维码的结果", scanResWX);
  83. const hotelId = getParamByName("hotelId", scanResWX.result);
  84. // console.log("hotelName", hotelName);
  85. this.updateCurrentHotel(this.queryHotelByHotelId(hotelId))
  86. uni.switchTab({
  87. url: '/pages/home/home'
  88. })
  89. // #endif
  90. // #ifdef MP-ALIPAY
  91. let scanResAli = await my.scan({
  92. scanType: ['qrCode']
  93. })
  94. console.log("扫描二维码的结果", scanResAli);
  95. // #endif
  96. },
  97. async getHotels() {
  98. let res = await uni.$http.get('/hotel')
  99. this.hotelList = res.data.data
  100. },
  101. async queryHotelByHotelId(hotelId) {
  102. let res = await uni.$http.get(`/hotel/${hotelId}`)
  103. return res.data.data
  104. },
  105. getHotelPicPath(path) {
  106. return IMG_BASE_URL + '/' + path
  107. },
  108. goBack(hotel) {
  109. this.updateCurrentHotel(hotel)
  110. console.log(this.source === "home");
  111. if (this.source === "home") {
  112. uni.switchTab({
  113. url: '/pages/home/home'
  114. })
  115. } else if (this.source === "selectCheckinType") {
  116. uni.redirectTo({
  117. url: '/subpkg_checkin/selectCheckinType/selectCheckinType'
  118. })
  119. }
  120. },
  121. },
  122. async onLoad(option) {
  123. console.log("option", option)
  124. this.source = option.source
  125. // #ifdef MP-WEIXIN
  126. this.displayScanner = true
  127. // #endif
  128. // #ifdef MP-ALIPAY
  129. this.displayScanner = false
  130. // #endif
  131. // 首次载入页面渲染全部酒店,后可根据搜索来搜索其他酒店
  132. await this.getHotels()
  133. },
  134. }
  135. </script>
  136. <style lang="scss">
  137. page {
  138. display: flex;
  139. flex-direction: column;
  140. width: 100%;
  141. height: 100%;
  142. .choose-hotel {
  143. display: flex;
  144. flex-direction: column;
  145. width: 100%;
  146. height: 100%;
  147. .top {
  148. position: sticky;
  149. background-color: #f0eff5;
  150. width: 100%;
  151. top: 0;
  152. z-index: 999;
  153. .choose-hotel--input {
  154. display: flex;
  155. flex-direction: row;
  156. align-items: center;
  157. padding: 20rpx;
  158. height: 80rpx;
  159. .choose-hotel--input__frame {
  160. width: 100%;
  161. height: 100%;
  162. display: flex;
  163. align-items: center;
  164. justify-content: center;
  165. }
  166. .choose-hotel--input__scan {
  167. height: 100%;
  168. width: 30px;
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. padding-left: 20rpx;
  173. }
  174. }
  175. }
  176. .choose-hotel--dispaly-area {
  177. background-color: #ffffff;
  178. width: 100%;
  179. height: 100%;
  180. padding-top: 10rpx;
  181. .choose-hotel--description {
  182. padding: 5rpx 20rpx;
  183. .choose-hotel--description__hotel {
  184. background-color: #f1f1f4;
  185. display: flex;
  186. flex-direction: row;
  187. padding: 20rpx 10rpx;
  188. border-radius: 6rpx;
  189. .choose-hotel--description__hotel-name {
  190. display: flex;
  191. align-items: center;
  192. padding-left: 30rpx;
  193. font-size: 38rpx;
  194. }
  195. }
  196. }
  197. }
  198. .choose-hotel--not-found {
  199. background-color: #ffffff;
  200. width: 100%;
  201. position: absolute;
  202. top: 120rpx;
  203. left: 0;
  204. bottom: 0;
  205. padding-top: 20rpx;
  206. display: flex;
  207. justify-content: center;
  208. font-size: 40rpx;
  209. }
  210. }
  211. }
  212. </style>