chooseHotel.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. appId: ""
  57. }
  58. },
  59. methods: {
  60. ...mapMutations('m_business', ['updateCurrentHotel']),
  61. async inputChanged() {
  62. this.notFound = false
  63. let res = await uni.$http.post('/hotel/available', {
  64. appId: this.appId,
  65. hotelName: this.hotelName
  66. })
  67. if (res.data.data.length === 0) {
  68. this.notFound = true
  69. console.log("sous", res);
  70. return
  71. }
  72. this.hotelList = res.data.data
  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/available', {
  104. appId: this.appId
  105. })
  106. this.hotelList = res.data.data
  107. },
  108. async queryHotelByHotelId(hotelId) {
  109. let res = await uni.$http.get(`/hotel/${hotelId}`)
  110. return res.data.data
  111. },
  112. getHotelPicPath(path) {
  113. return IMG_BASE_URL + '/' + path
  114. },
  115. goBack(hotel) {
  116. this.updateCurrentHotel(hotel)
  117. console.log(this.source === "home");
  118. if (this.source === "home") {
  119. uni.switchTab({
  120. url: '/pages/home/home'
  121. })
  122. } else if (this.source === "selectCheckinType") {
  123. uni.redirectTo({
  124. url: '/subpkg_checkin/selectCheckinType/selectCheckinType'
  125. })
  126. }
  127. },
  128. },
  129. async onLoad(option) {
  130. console.log("option", option)
  131. this.source = option.source
  132. // #ifdef MP-WEIXIN
  133. this.displayScanner = true
  134. // #endif
  135. // #ifdef MP-ALIPAY
  136. this.displayScanner = false
  137. // #endif
  138. // 首次载入页面渲染全部酒店,后可根据搜索来搜索其他酒店
  139. const {miniProgram: {appId}} = uni.getAccountInfoSync();
  140. this.appId = appId
  141. await this.getHotels()
  142. },
  143. }
  144. </script>
  145. <style lang="scss">
  146. page {
  147. display: flex;
  148. flex-direction: column;
  149. width: 100%;
  150. height: 100%;
  151. .choose-hotel {
  152. display: flex;
  153. flex-direction: column;
  154. width: 100%;
  155. height: 100%;
  156. .top {
  157. position: sticky;
  158. background-color: #f0eff5;
  159. width: 100%;
  160. top: 0;
  161. z-index: 999;
  162. .choose-hotel--input {
  163. display: flex;
  164. flex-direction: row;
  165. align-items: center;
  166. padding: 20rpx;
  167. height: 80rpx;
  168. .choose-hotel--input__frame {
  169. width: 100%;
  170. height: 100%;
  171. display: flex;
  172. align-items: center;
  173. justify-content: center;
  174. }
  175. .choose-hotel--input__scan {
  176. height: 100%;
  177. width: 30px;
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. padding-left: 20rpx;
  182. }
  183. }
  184. }
  185. .choose-hotel--dispaly-area {
  186. background-color: #ffffff;
  187. width: 100%;
  188. height: 100%;
  189. padding-top: 10rpx;
  190. .choose-hotel--description {
  191. padding: 5rpx 20rpx;
  192. .choose-hotel--description__hotel {
  193. background-color: #f1f1f4;
  194. display: flex;
  195. flex-direction: row;
  196. padding: 20rpx 10rpx;
  197. border-radius: 6rpx;
  198. .choose-hotel--description__hotel-name {
  199. display: flex;
  200. align-items: center;
  201. padding-left: 30rpx;
  202. font-size: 38rpx;
  203. }
  204. }
  205. }
  206. }
  207. .choose-hotel--not-found {
  208. background-color: #ffffff;
  209. width: 100%;
  210. position: absolute;
  211. top: 350rpx;
  212. left: 0;
  213. bottom: 0;
  214. padding-top: 20rpx;
  215. display: flex;
  216. justify-content: center;
  217. font-size: 40rpx;
  218. }
  219. }
  220. }
  221. </style>