selectRoomType.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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: false,
  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. end.setHours(endTime[0], endTime[1], endTime[2])
  88. let num = ((new Date(end)).valueOf() - (new Date(this.startDate)).valueOf()) / (24 * 60 * 60 *
  89. 1000)
  90. return Math.ceil(num)
  91. },
  92. ...mapState('m_business', ['currentHotel']),
  93. ...mapState('m_user', ['userInfo']),
  94. },
  95. methods: {
  96. ...mapMutations('m_business', ['updateRoomType', 'updateOrder']),
  97. //未预定 跳转至选择房间
  98. async gotoSelectRoom(item) {
  99. let startTime = new Date()
  100. let endTime = this.endDate
  101. //本地保存订单信息
  102. this.updateOrder({
  103. hotelId: this.currentHotel.hotelId,
  104. roomType: item.roomType,
  105. startTime: startTime,
  106. endTime: endTime,
  107. dayNum: this.dayNum,
  108. status: 'ORDER_PLACED',
  109. paymentStatus: 'UNPAID',
  110. createHotelOrderReason: 'CHECKIN',
  111. orderSource: 'MINI_APP'
  112. })
  113. uni.navigateTo({
  114. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' + item.roomType
  115. });
  116. },
  117. async getRoomTypeList() {
  118. let res = await uni.$http.post('/roomType', {
  119. hotelId: this.currentHotel.hotelId,
  120. pageNo: 1,
  121. pageSize: 999
  122. })
  123. this.roomTypeList = res.data.data.records
  124. this.roomTypeList.forEach((item) => {
  125. item.roomPicPath = IMG_BASE_URL + '/' + item.roomPicPath
  126. })
  127. },
  128. confirm(days) {
  129. this.endDate = new Date(days[0])
  130. let checkoutTime = this.currentHotel.checkoutTime.split(':')
  131. this.endDate.setHours(checkoutTime[0], checkoutTime[1], checkoutTime[2])
  132. this.endDay = getDay(new Date(days[0]).getDay())
  133. this.showCalendar = false
  134. }
  135. },
  136. async onLoad() {
  137. await this.getRoomTypeList()
  138. },
  139. onShow() {
  140. //开始时间为当前时间
  141. let now = new Date()
  142. this.startDate = new Date()
  143. this.startDay = getDay(new Date().getDay())
  144. //入住时间早于边界时间,默认当天结束
  145. //入住时间晚于边界时间,默认第二天结束
  146. let checkinBoundaryTime = this.currentHotel.checkinBoundaryTime ? this.currentHotel.checkinBoundaryTime : "06:00:00"
  147. let boundaryTime = new Date(
  148. now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate() +
  149. ' ' + checkinBoundaryTime)
  150. let today = new Date()
  151. today.setHours(0, 0, 0, 0)
  152. if (now < boundaryTime) {
  153. this.endDate = today
  154. } else {
  155. let tomorrow = new Date(today)
  156. tomorrow.setDate(tomorrow.getDate() + 1)
  157. this.endDate = tomorrow
  158. this.minDate = moment(tomorrow).format('YYYY-MM-DD')
  159. }
  160. //星期几
  161. this.endDay = getDay(this.endDate.getDay())
  162. //日历默认日期,即默认结束日期
  163. this.defaultDate = moment(this.endDate).format('YYYY-MM-DD')
  164. //入住结束时间设置为为酒店对应配置
  165. let checkoutTimeSet = this.currentHotel.checkoutTime
  166. let checkoutTime = checkoutTimeSet ? this.currentHotel.checkoutTime.split(':') : "12:00:00".split(':')
  167. this.endDate.setHours(checkoutTime[0], checkoutTime[1], checkoutTime[2])
  168. },
  169. // #ifdef MP-WEIXIN
  170. onShareAppMessage(info) {
  171. return {
  172. title: '源享住',
  173. path: 'pages/login/login',
  174. imageUrl: "/static/logo.png"
  175. }
  176. }
  177. // #endif
  178. }
  179. </script>
  180. <style lang="scss">
  181. page {
  182. background-color: #FFFFFF;
  183. display: flex;
  184. flex-direction: column;
  185. .sticky {
  186. position: sticky;
  187. background-color: #fff;
  188. width: 100%;
  189. top: 0;
  190. z-index: 999;
  191. .checkin-date-info {
  192. display: flex;
  193. background-color: #FFFFFF;
  194. margin: 10rpx 20rpx;
  195. height: 120rpx;
  196. justify-content: space-around;
  197. .date-selector {
  198. margin: 10rpx 20rpx;
  199. display: flex;
  200. width: 50vw;
  201. .date-item {
  202. width: 35vw;
  203. .date-info {
  204. display: flex;
  205. }
  206. }
  207. }
  208. .day-num {
  209. display: flex;
  210. align-items: center;
  211. justify-content: space-between;
  212. .u-image {
  213. margin-left: 20rpx;
  214. }
  215. }
  216. }
  217. }
  218. .room-type-item {
  219. border-radius: 30rpx;
  220. background-color: #FFFFFF;
  221. margin: 20rpx 20rpx;
  222. padding: 40rpx 20rpx;
  223. display: flex;
  224. background: #FFFFFF;
  225. box-shadow: 0rpx 10rpx 6rpx 1rpx rgba(75, 75, 75, 0.1);
  226. border-radius: 10rpx;
  227. .room-type-item-middle {
  228. margin-left: 30rpx;
  229. display: flex;
  230. flex-direction: column;
  231. width: 200rpx;
  232. .room-type-item-middle-text {
  233. font-size: 40rpx;
  234. font-weight: bold;
  235. color: #333333;
  236. }
  237. .room-type-item-middle-bottom {
  238. margin-top: 40rpx;
  239. font-size: 25rpx;
  240. text {
  241. margin-right: 20rpx;
  242. color: #666666
  243. }
  244. }
  245. }
  246. .room-type-item-right {
  247. width: 25%;
  248. margin-left: 20rpx;
  249. .room-type-item-right-text {
  250. margin-top: 30rpx;
  251. margin-bottom: 20rpx;
  252. }
  253. text {
  254. font-size: 40rpx;
  255. font-weight: bold;
  256. color: #FF5C58
  257. }
  258. button {
  259. background-color: #F69B49;
  260. height: 60rpx;
  261. width: 100%;
  262. color: #FFFFFF;
  263. display: flex;
  264. justify-content: center;
  265. align-items: center;
  266. margin-top: 60rpx;
  267. border-radius: 6rpx;
  268. }
  269. }
  270. }
  271. }
  272. </style>