selectRoomType.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="page">
  3. <view class="sticky">
  4. <view>
  5. <!-- #ifdef MP-WEIXIN -->
  6. <NavigateBar title="房源类型" control="back" bgcolor="#a09cc4"></NavigateBar>
  7. <!-- #endif -->
  8. <!-- #ifdef MP-ALIPAY -->
  9. <NavigateBar title="房源类型" bgcolor="#a09cc4"></NavigateBar>
  10. <!-- #endif -->
  11. </view>
  12. <view class="checkin-date-info" @click="showCalendar=true">
  13. <view class="date-selector">
  14. <view class="date-item">
  15. <u-text text="离店" color="#666666" size="13"></u-text>
  16. <view class="date-info">
  17. <u-text :text="endDateFormatted" color="#333333" size="14" bold></u-text>
  18. <u-text :text="endDay" color="#333333" size="14" bold></u-text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="day-num">
  23. <u-text :text="'共'+dayNum+'晚'" color="#333333" size="18" bold></u-text>
  24. <u-image :src="arrowPicPath" width="17rpx" height="32rpx"></u-image>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="room-type-item" v-for="item in roomTypeList" :key="item.id">
  29. <view class="room-type-item-left">
  30. <u-image :src="item.roomPicPath" width="200rpx" height="200rpx" radius="10"></u-image>
  31. </view>
  32. <view class="room-type-item-middle">
  33. <view class="room-type-item-middle-text">
  34. <text>{{item.roomTypeName}}</text>
  35. </view>
  36. </view>
  37. <view class="room-type-item-right">
  38. <view class="room-type-item-right-text">
  39. <text>¥{{item.unitPrice}}</text>
  40. </view>
  41. <button @click="gotoSelectRoom(item)">选房</button>
  42. </view>
  43. </view>
  44. <u-calendar :show="showCalendar" mode="single" @confirm="confirm" @close="showCalendar=false" color="#9e97c3"
  45. :defaultDate="defaultDate" title="离店日期" :minDate="minDate"></u-calendar>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. getDay
  51. } from '../../utils/commonUtils.js'
  52. import moment from 'moment'
  53. import {
  54. IMG_BASE_URL
  55. } from "../../config.js"
  56. import {
  57. mapState,
  58. mapMutations
  59. } from 'vuex'
  60. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  61. export default {
  62. components: {
  63. NavigateBar
  64. },
  65. data() {
  66. return {
  67. roomTypeList: {},
  68. showCalendar: true,
  69. defaultDate: [],
  70. arrowPicPath: '/static/arrow.png',
  71. startDate: '',
  72. startDay: '',
  73. endDate: '',
  74. endDay: '',
  75. minDate: '',
  76. };
  77. },
  78. computed: {
  79. endDateFormatted() {
  80. return moment(this.endDate).format('MM月DD日')
  81. },
  82. dayNum() {
  83. //根据起始时间到第二天的边界时间来算天数
  84. let checkinBoundaryTimeSet = this.currentHotel.checkinBoundaryTime
  85. let end = new Date(this.endDate)
  86. let endTime = checkinBoundaryTimeSet ? this.currentHotel.checkinBoundaryTime.split(":") : "06:00:00".split(
  87. ":")
  88. end.setHours(endTime[0], endTime[1], endTime[2])
  89. let num = ((new Date(end)).valueOf() - (new Date(this.startDate)).valueOf()) / (24 * 60 * 60 *
  90. 1000)
  91. return Math.ceil(num)
  92. },
  93. ...mapState('m_business', ['currentHotel']),
  94. ...mapState('m_user', ['userInfo']),
  95. },
  96. methods: {
  97. ...mapMutations('m_business', ['updateRoomType', 'updateOrder']),
  98. //未预定 跳转至选择房间
  99. async gotoSelectRoom(item) {
  100. let startTime = new Date()
  101. let endTime = this.endDate
  102. //本地保存订单信息
  103. this.updateOrder({
  104. hotelId: this.currentHotel.hotelId,
  105. roomType: item.roomType,
  106. startTime: startTime,
  107. endTime: endTime,
  108. dayNum: this.dayNum,
  109. createHotelOrderReason: 'CHECKIN',
  110. orderSource: 'MINI_APP'
  111. })
  112. uni.navigateTo({
  113. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' + item.roomType
  114. });
  115. },
  116. async getRoomTypeList() {
  117. let res = await uni.$http.get(`/hotel/${this.currentHotel.hotelId}/roomType`)
  118. this.roomTypeList = res.data.data
  119. this.roomTypeList.forEach((item) => {
  120. item.roomPicPath = IMG_BASE_URL + '/' + item.roomPicPath
  121. })
  122. },
  123. confirm(days) {
  124. this.endDate = new Date(days[0])
  125. let checkoutTime = this.currentHotel.checkoutTime.split(':')
  126. this.endDate.setHours(checkoutTime[0], checkoutTime[1], checkoutTime[2])
  127. this.endDay = getDay(new Date(days[0]).getDay())
  128. this.showCalendar = false
  129. }
  130. },
  131. async onLoad() {
  132. await this.getRoomTypeList()
  133. },
  134. onShow() {
  135. //开始时间为当前时间
  136. let now = new Date()
  137. this.startDate = new Date()
  138. this.startDay = getDay(new Date().getDay())
  139. //入住时间早于边界时间,默认当天结束
  140. //入住时间晚于边界时间,默认第二天结束
  141. let checkinBoundaryTime = this.currentHotel.checkinBoundaryTime ? this.currentHotel.checkinBoundaryTime :
  142. "06:00:00"
  143. let boundaryTime = new Date(
  144. now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate() +
  145. ' ' + checkinBoundaryTime)
  146. let today = new Date()
  147. today.setHours(0, 0, 0, 0)
  148. if (now < boundaryTime) {
  149. this.endDate = today
  150. } else {
  151. let tomorrow = new Date(today)
  152. tomorrow.setDate(tomorrow.getDate() + 1)
  153. this.endDate = tomorrow
  154. this.minDate = moment(tomorrow).format('YYYY-MM-DD')
  155. }
  156. //星期几
  157. this.endDay = getDay(this.endDate.getDay())
  158. //日历默认日期,即默认结束日期
  159. this.defaultDate = moment(this.endDate).format('YYYY-MM-DD')
  160. //入住结束时间设置为为酒店对应配置
  161. let checkoutTimeSet = this.currentHotel.checkoutTime
  162. let checkoutTime = checkoutTimeSet ? this.currentHotel.checkoutTime.split(':') : "12:00:00".split(':')
  163. this.endDate.setHours(checkoutTime[0], checkoutTime[1], checkoutTime[2])
  164. },
  165. // #ifdef MP-WEIXIN
  166. onShareAppMessage(info) {
  167. return {
  168. title: '源享住',
  169. path: 'pages/login/login',
  170. imageUrl: "/static/logo.png"
  171. }
  172. }
  173. // #endif
  174. }
  175. </script>
  176. <style lang="scss">
  177. page {
  178. background-color: #FFFFFF;
  179. display: flex;
  180. flex-direction: column;
  181. .sticky {
  182. position: sticky;
  183. background-color: #fff;
  184. width: 100%;
  185. top: 0;
  186. z-index: 999;
  187. .checkin-date-info {
  188. display: flex;
  189. background-color: #FFFFFF;
  190. margin: 10rpx 20rpx;
  191. height: 120rpx;
  192. justify-content: space-around;
  193. .date-selector {
  194. margin: 10rpx 20rpx;
  195. display: flex;
  196. width: 50vw;
  197. .date-item {
  198. width: 35vw;
  199. .date-info {
  200. display: flex;
  201. }
  202. }
  203. }
  204. .day-num {
  205. display: flex;
  206. align-items: center;
  207. justify-content: space-between;
  208. .u-image {
  209. margin-left: 20rpx;
  210. }
  211. }
  212. }
  213. }
  214. .room-type-item {
  215. border-radius: 30rpx;
  216. background-color: #FFFFFF;
  217. margin: 20rpx 20rpx;
  218. padding: 40rpx 20rpx;
  219. display: flex;
  220. background: #FFFFFF;
  221. box-shadow: 0rpx 10rpx 6rpx 1rpx rgba(75, 75, 75, 0.1);
  222. border-radius: 10rpx;
  223. .room-type-item-middle {
  224. margin-left: 30rpx;
  225. display: flex;
  226. flex-direction: column;
  227. width: 200rpx;
  228. .room-type-item-middle-text {
  229. font-size: 40rpx;
  230. font-weight: bold;
  231. color: #333333;
  232. }
  233. .room-type-item-middle-bottom {
  234. margin-top: 40rpx;
  235. font-size: 25rpx;
  236. text {
  237. margin-right: 20rpx;
  238. color: #666666
  239. }
  240. }
  241. }
  242. .room-type-item-right {
  243. width: 25%;
  244. margin-left: 20rpx;
  245. .room-type-item-right-text {
  246. margin-top: 30rpx;
  247. margin-bottom: 20rpx;
  248. }
  249. text {
  250. font-size: 40rpx;
  251. font-weight: bold;
  252. color: #FF5C58
  253. }
  254. button {
  255. background-color: #F69B49;
  256. height: 60rpx;
  257. width: 100%;
  258. color: #FFFFFF;
  259. display: flex;
  260. justify-content: center;
  261. align-items: center;
  262. margin-top: 60rpx;
  263. border-radius: 6rpx;
  264. }
  265. }
  266. }
  267. }
  268. </style>