setCheckinDate.vue 5.7 KB

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