chooseHotel.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.post('/hotel', {
  63. name: this.hotelName,
  64. isTest: false,
  65. pageNo: 1,
  66. pageSize: 999
  67. })
  68. if (res.data.data.records.length === 0) {
  69. this.notFound = true
  70. return
  71. }
  72. this.hotelList = res.data.data.records
  73. },
  74. inputFocusd() {
  75. // 取得焦点时显示shortcut
  76. console.log("input focused");
  77. },
  78. inputBlured() {
  79. // 失去焦点时关闭shortcut
  80. console.log("inpot blured");
  81. },
  82. async scanQRCode() {
  83. // #ifdef MP-WEIXIN
  84. let scanResWX = await wx.scanCode({
  85. scanType: ['qrCode']
  86. })
  87. // console.log("扫描二维码的结果", scanResWX);
  88. const hotelId = getParamByName("hotelId", scanResWX.result);
  89. // console.log("hotelName", hotelName);
  90. this.updateCurrentHotel(this.queryHotelByHotelId(hotelId))
  91. uni.switchTab({
  92. url: '/pages/home/home'
  93. })
  94. // #endif
  95. // #ifdef MP-ALIPAY
  96. let scanResAli = await my.scan({
  97. scanType: ['qrCode']
  98. })
  99. console.log("扫描二维码的结果", scanResAli);
  100. // #endif
  101. },
  102. async getHotels() {
  103. let res = await uni.$http.post('/hotel', {
  104. isTest: false,
  105. pageNo: 1,
  106. pageSize: 999
  107. })
  108. this.hotelList = res.data.data.records
  109. },
  110. async queryHotelByHotelId(hotelId) {
  111. let res = await uni.$http.post('/hotel', {
  112. hotelId: hotelId,
  113. isTest: false,
  114. pageNo: 1,
  115. pageSize: 999
  116. })
  117. return res.data.data.records[0]
  118. },
  119. getHotelPicPath(path) {
  120. return IMG_BASE_URL + '/' + path
  121. },
  122. goBack(hotel) {
  123. this.updateCurrentHotel(hotel)
  124. console.log(this.source === "home");
  125. if (this.source === "home") {
  126. uni.switchTab({
  127. url: '/pages/home/home'
  128. })
  129. } else if (this.source === "selectCheckinType") {
  130. uni.redirectTo({
  131. url: '/subpkg_checkin/selectCheckinType/selectCheckinType'
  132. })
  133. }
  134. },
  135. },
  136. async onLoad(option) {
  137. console.log("option", option)
  138. this.source = option.source
  139. // #ifdef MP-WEIXIN
  140. this.displayScanner = true
  141. // #endif
  142. // #ifdef MP-ALIPAY
  143. this.displayScanner = false
  144. // #endif
  145. // 首次载入页面渲染全部酒店,后可根据搜索来搜索其他酒店
  146. await this.getHotels()
  147. },
  148. }
  149. </script>
  150. <style lang="scss">
  151. page {
  152. display: flex;
  153. flex-direction: column;
  154. width: 100%;
  155. height: 100%;
  156. .choose-hotel {
  157. display: flex;
  158. flex-direction: column;
  159. width: 100%;
  160. height: 100%;
  161. .top {
  162. position: sticky;
  163. background-color: #f0eff5;
  164. width: 100%;
  165. top: 0;
  166. z-index: 999;
  167. .choose-hotel--input {
  168. display: flex;
  169. flex-direction: row;
  170. align-items: center;
  171. padding: 20rpx;
  172. height: 80rpx;
  173. .choose-hotel--input__frame {
  174. width: 100%;
  175. height: 100%;
  176. display: flex;
  177. align-items: center;
  178. justify-content: center;
  179. }
  180. .choose-hotel--input__scan {
  181. height: 100%;
  182. width: 30px;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. padding-left: 20rpx;
  187. }
  188. }
  189. }
  190. .choose-hotel--dispaly-area {
  191. background-color: #ffffff;
  192. width: 100%;
  193. height: 100%;
  194. padding-top: 10rpx;
  195. .choose-hotel--description {
  196. padding: 5rpx 20rpx;
  197. .choose-hotel--description__hotel {
  198. background-color: #f1f1f4;
  199. display: flex;
  200. flex-direction: row;
  201. padding: 20rpx 10rpx;
  202. border-radius: 6rpx;
  203. .choose-hotel--description__hotel-name {
  204. display: flex;
  205. align-items: center;
  206. padding-left: 30rpx;
  207. font-size: 38rpx;
  208. }
  209. }
  210. }
  211. }
  212. .choose-hotel--not-found {
  213. background-color: #ffffff;
  214. width: 100%;
  215. position: absolute;
  216. top: 120rpx;
  217. left: 0;
  218. bottom: 0;
  219. padding-top: 20rpx;
  220. display: flex;
  221. justify-content: center;
  222. font-size: 40rpx;
  223. }
  224. }
  225. }
  226. </style>