selectRoomType.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. ROOM_TYPE_PIC_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 = ROOM_TYPE_PIC_URL + item.roomPicPath
  121. })
  122. },
  123. confirm(days) {
  124. days[0] = days[0] || this.defaultDate
  125. this.endDate = new Date(days[0])
  126. let checkoutTime = this.currentHotel.checkoutTime.split(':')
  127. this.endDate.setHours(checkoutTime[0], checkoutTime[1], checkoutTime[2])
  128. this.endDay = getDay(new Date(days[0]).getDay())
  129. this.showCalendar = false
  130. }
  131. },
  132. async onLoad() {
  133. await this.getRoomTypeList()
  134. },
  135. onShow() {
  136. //开始时间为当前时间
  137. let now = new Date()
  138. this.startDate = new Date()
  139. this.startDay = getDay(new Date().getDay())
  140. //入住时间早于边界时间,默认当天结束
  141. //入住时间晚于边界时间,默认第二天结束
  142. let checkinBoundaryTime = this.currentHotel.checkinBoundaryTime ? this.currentHotel.checkinBoundaryTime :
  143. "06:00:00"
  144. let boundaryTime = new Date(
  145. now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate() +
  146. ' ' + checkinBoundaryTime)
  147. let today = new Date()
  148. today.setHours(0, 0, 0, 0)
  149. if (now < boundaryTime) {
  150. this.endDate = today
  151. } else {
  152. let tomorrow = new Date(today)
  153. tomorrow.setDate(tomorrow.getDate() + 1)
  154. this.endDate = tomorrow
  155. this.minDate = moment(tomorrow).format('YYYY-MM-DD')
  156. }
  157. //星期几
  158. this.endDay = getDay(this.endDate.getDay())
  159. //日历默认日期,即默认结束日期
  160. this.defaultDate = moment(this.endDate).format('YYYY-MM-DD')
  161. //入住结束时间设置为为酒店对应配置
  162. let checkoutTimeSet = this.currentHotel.checkoutTime
  163. let checkoutTime = checkoutTimeSet ? this.currentHotel.checkoutTime.split(':') : "12:00:00".split(':')
  164. this.endDate.setHours(checkoutTime[0], checkoutTime[1], checkoutTime[2])
  165. },
  166. // #ifdef MP-WEIXIN
  167. onShareAppMessage(info) {
  168. return {
  169. title: '源享住',
  170. path: 'pages/login/login',
  171. imageUrl: "/static/logo.png"
  172. }
  173. }
  174. // #endif
  175. }
  176. </script>
  177. <style lang="scss">
  178. page {
  179. background-color: #FFFFFF;
  180. display: flex;
  181. flex-direction: column;
  182. .sticky {
  183. position: sticky;
  184. background-color: #fff;
  185. width: 100%;
  186. top: 0;
  187. z-index: 999;
  188. .checkin-date-info {
  189. display: flex;
  190. background-color: #FFFFFF;
  191. margin: 10rpx 20rpx;
  192. height: 120rpx;
  193. justify-content: space-around;
  194. .date-selector {
  195. margin: 10rpx 20rpx;
  196. display: flex;
  197. width: 50vw;
  198. .date-item {
  199. width: 35vw;
  200. .date-info {
  201. display: flex;
  202. }
  203. }
  204. }
  205. .day-num {
  206. display: flex;
  207. align-items: center;
  208. justify-content: space-between;
  209. .u-image {
  210. margin-left: 20rpx;
  211. }
  212. }
  213. }
  214. }
  215. .room-type-item {
  216. border-radius: 30rpx;
  217. background-color: #FFFFFF;
  218. margin: 20rpx 20rpx;
  219. padding: 40rpx 20rpx;
  220. display: flex;
  221. background: #FFFFFF;
  222. box-shadow: 0rpx 10rpx 6rpx 1rpx rgba(75, 75, 75, 0.1);
  223. border-radius: 10rpx;
  224. .room-type-item-middle {
  225. margin-left: 30rpx;
  226. display: flex;
  227. flex-direction: column;
  228. width: 200rpx;
  229. .room-type-item-middle-text {
  230. font-size: 40rpx;
  231. font-weight: bold;
  232. color: #333333;
  233. }
  234. .room-type-item-middle-bottom {
  235. margin-top: 40rpx;
  236. font-size: 25rpx;
  237. text {
  238. margin-right: 20rpx;
  239. color: #666666
  240. }
  241. }
  242. }
  243. .room-type-item-right {
  244. width: 25%;
  245. margin-left: 20rpx;
  246. .room-type-item-right-text {
  247. margin-top: 30rpx;
  248. margin-bottom: 20rpx;
  249. }
  250. text {
  251. font-size: 40rpx;
  252. font-weight: bold;
  253. color: #FF5C58
  254. }
  255. button {
  256. background-color: #F69B49;
  257. height: 60rpx;
  258. width: 100%;
  259. color: #FFFFFF;
  260. display: flex;
  261. justify-content: center;
  262. align-items: center;
  263. margin-top: 60rpx;
  264. border-radius: 6rpx;
  265. }
  266. }
  267. }
  268. }
  269. </style>