setCheckinDate.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view>
  3. <uni-card :title="reservationInfo.hotelName" extra="订房信息" note="Tips">
  4. <view class="card-item" v-if="reservationInfo.building">
  5. <view class="card-item-left">
  6. <u-text :text="buildingTip" align="center"></u-text>
  7. </view>
  8. <text>{{reservationInfo.building}}</text>
  9. </view>
  10. <view class="card-item">
  11. <view class="card-item-left">
  12. <u-text :text="floorTip" align="center"></u-text>
  13. </view>
  14. <text>{{reservationInfo.floor}}</text>
  15. </view>
  16. <view class="card-item">
  17. <view class="card-item-left">
  18. <u-text :text="roomTip" align="center"></u-text>
  19. </view>
  20. <text>{{reservationInfo.room}}</text>
  21. </view>
  22. </uni-card>
  23. <view class="date-item">
  24. <view class="date-item-tip">
  25. <u-text :text="startTimeTip" align="center"></u-text>
  26. </view>
  27. <view>
  28. <u-datetime-picker :show="startTimeShow" v-model="startTime" mode="datetime" :minDate="startMinDate"
  29. :maxDate="startMaxDate" @cancel="startTimeShow = false"
  30. @confirm="confirmStartTimeChange"></u-datetime-picker>
  31. <u-text :text="startTimeFormatted" bold="true" @click="startTimeShow = true"></u-text>
  32. </view>
  33. </view>
  34. <view class="date-item">
  35. <view class="date-item-tip">
  36. <u-text :text="endTimeTip" align="center"></u-text>
  37. </view>
  38. <view>
  39. <view>
  40. <u-datetime-picker :show="endTimeShow" v-model="endTime" mode="datetime"
  41. :minDate="endMinDate" :maxDate="endMaxDate" @cancel="endTimeShow = false"
  42. @confirm="confirmEndTimeChange"></u-datetime-picker>
  43. <u-text :text="endTimeFormatted" bold="true" @click="endTimeShow = true"></u-text>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="confirm-btn">
  48. <u-button :text="confirmButtonTip" type="primary" @click="confirmReservation"
  49. :loading="confirmButtonLoading" :loadingText="confirmButtonLoadingText"></u-button>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import moment from 'moment'
  55. import {
  56. mapState,
  57. mapMutations
  58. } from 'vuex'
  59. export default {
  60. data() {
  61. return {
  62. buildingTip: '楼 栋 :',
  63. floorTip: '楼 层 :',
  64. roomTip: '房 间 :',
  65. startTimeTip: '选择起始时间:',
  66. endTimeTip: '选择结束时间:',
  67. startTime: '',
  68. endTime: '',
  69. startTimeShow: false,
  70. endTimeShow: false,
  71. startMinDate: 0,
  72. startMaxDate: 0,
  73. endMinDate: 0,
  74. endMaxDate: 0,
  75. confirmButtonTip: '确认选房',
  76. confirmButtonLoading: false,
  77. confirmButtonLoadingText: '选房中'
  78. };
  79. },
  80. computed: {
  81. ...mapState('m_user', ['userInfo']),
  82. ...mapState('m_business', ['reservationInfo']),
  83. startTimeFormatted() {
  84. let start = new Date(this.startTime)
  85. //默认入住时间14点
  86. return moment(start).format('YYYY/MM/DD HH:mm')
  87. },
  88. endTimeFormatted() {
  89. let end = new Date(this.endTime)
  90. //默认到期时间12点
  91. return moment(end).format('YYYY/MM/DD HH:mm')
  92. },
  93. },
  94. methods: {
  95. confirmStartTimeChange(info) {
  96. //设置起始时间
  97. this.startTime = info.value
  98. //关闭选择器显示
  99. this.startTimeShow = false
  100. },
  101. confirmEndTimeChange(info) {
  102. //设置结束时间
  103. this.endTime = info.value
  104. //关闭选择器显示
  105. this.endTimeShow = false
  106. },
  107. async confirmReservation() {
  108. this.confirmButtonLoading = true
  109. let start = new Date(this.startTime)
  110. let end = new Date(this.endTime)
  111. console.log(start)
  112. console.log(end)
  113. let res = await uni.$http.post('/userPicRoomInfo', {
  114. userId: this.userInfo.userId,
  115. hotelId: this.reservationInfo.hotelId,
  116. building: this.reservationInfo.building,
  117. floor: this.reservationInfo.floor,
  118. room: this.reservationInfo.room,
  119. startTime: start,
  120. endTime: end
  121. })
  122. console.log(res)
  123. console.log(res.data.success)
  124. if (res.data.success == true) {
  125. uni.$showMsg('选房成功!')
  126. setTimeout(() => {
  127. uni.navigateTo({
  128. url: "/subpkg/checkin/checkin"
  129. })
  130. }, 2000)
  131. } else {
  132. uni.$showMsg('选房失败!')
  133. }
  134. this.confirmButtonLoading = false
  135. }
  136. },
  137. onLoad() {
  138. //初始化起始时间为当前时间
  139. this.startTime = new Date()
  140. //初始化结束时间为第二天12点
  141. let tomorrow = new Date(new Date().valueOf() + 24 * 60 * 60 * 1000)
  142. tomorrow.setHours(12, 0, 0)
  143. this.endTime = tomorrow
  144. //初始化可选最小起始时间为当前时间
  145. this.startMinDate = Date.now()
  146. //初始化可选最大起始时间为一个月后
  147. let startMaxDate = new Date(new Date().valueOf() + 30 * 24 * 60 * 60 * 1000)
  148. this.startMaxDate = startMaxDate.valueOf()
  149. //初始化可选最小结束时间为第二天12点
  150. let minEndTime = new Date(new Date().valueOf() + 24 * 60 * 60 * 1000)
  151. minEndTime.setHours(12, 0, 0)
  152. this.endMinDate = minEndTime.valueOf()
  153. //初始化可选最大结束时间为30天后12点
  154. let endMaxDate = new Date(new Date().valueOf() + 31 * 24 * 60 * 60 * 1000)
  155. endMaxDate.setHours(12, 0, 0)
  156. this.endMaxDate = endMaxDate.valueOf()
  157. }
  158. }
  159. </script>
  160. <style lang="scss">
  161. .date-item {
  162. margin: 100rpx 40rpx;
  163. display: flex;
  164. }
  165. .date-item-tip {
  166. width: 220rpx;
  167. }
  168. .confirm-btn {
  169. width: 80%;
  170. margin: 0 auto;
  171. }
  172. .card-item {
  173. margin-bottom: 40rpx;
  174. display: flex;
  175. }
  176. .card-item-left {
  177. width: 220rpx;
  178. }
  179. </style>