extend.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view>
  3. <view v-if="Object.keys(checkinInfo).length>0" class="">
  4. <uni-card :title="checkinInfo.hotelName" extra="入住信息" note="Tips">
  5. <view class="card-item" v-if="checkinInfo.building">
  6. <view class="card-item-left">
  7. <text>楼栋:</text>
  8. </view>
  9. <text>{{checkinInfo.building}}</text>
  10. </view>
  11. <view class="card-item">
  12. <view class="card-item-left">
  13. <text>楼层:</text>
  14. </view>
  15. <text>{{checkinInfo.floor}}</text>
  16. </view>
  17. <view class="card-item">
  18. <view class="card-item-left">
  19. <text>房间:</text>
  20. </view>
  21. <text>{{checkinInfo.room}}</text>
  22. </view>
  23. <view class="card-item">
  24. <view class="card-item-left">
  25. <text>起始时间:</text>
  26. </view>
  27. <text>{{checkinInfo.startTime}}\n</text>
  28. </view>
  29. <view class="card-item">
  30. <view class="card-item-left">
  31. <text>结束时间:</text>
  32. </view>
  33. <text>{{checkinInfo.endTime}}</text>
  34. </view>
  35. <view class="card-item">
  36. <view class="card-item-left">
  37. <u-text text="请选择续住至:"></u-text>
  38. </view>
  39. <view>
  40. <u-datetime-picker :show="endTimePickerShow" v-model="newEndTime" mode="datetime"
  41. :minDate="minDate" :maxDate="maxDate" @cancel="endTimePickerShow = false"
  42. @confirm="confirmEndTimeChange"></u-datetime-picker>
  43. <u-text :text="endTimeFormatted" bold="true" @click="endTimePickerShow = true"></u-text>
  44. </view>
  45. </view>
  46. </uni-card>
  47. <view class="completeBtn">
  48. <u-button type="primary" @click="extend" :loading="extendButtonLoading"
  49. :loadingText="extendButtonLoadingText">续住</u-button>
  50. </view>
  51. </view>
  52. <view v-else class="not-reservation">
  53. <text class="tip">无可续住订单</text>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import moment from 'moment'
  59. import {
  60. mapState,
  61. mapMutations
  62. } from 'vuex'
  63. export default {
  64. data() {
  65. return {
  66. newEndTime: '',
  67. checkinInfo: {},
  68. extendButtonLoading: false,
  69. extendButtonLoadingText: '办理中',
  70. endTimePickerShow: false,
  71. minDate: 0,
  72. maxDate: 0,
  73. oldEndTime: ''
  74. };
  75. },
  76. computed: {
  77. ...mapState('m_user', ['userInfo']),
  78. ...mapState('m_business', ['currentHotelId']),
  79. currentTime(e) {
  80. let endTime = new Date(moment(this.checkinInfo.endTime).format());
  81. endTime = moment(endTime.getTime() + 24 * 60 * 60 * 1000).format('YYYY-MM-DD');
  82. return endTime;
  83. },
  84. endTimeFormatted() {
  85. let end = new Date(this.newEndTime)
  86. return moment(end).format('YYYY/MM/DD HH:mm')
  87. },
  88. },
  89. methods: {
  90. ...mapMutations('m_business', ['updateCheckinInfo']),
  91. async extend() {
  92. try {
  93. this.extendButtonLoading = true
  94. let endTime = new Date(this.newEndTime)
  95. let res = await uni.$http.post('/extend', {
  96. id: this.checkinInfo.id,
  97. endTime: moment(endTime).format('YYMMDDHHmmss'),
  98. });
  99. if (res.data.success === true) {
  100. this.updateCheckinInfo({})
  101. uni.$showMsg('续住办理成功!')
  102. setTimeout(() => {
  103. uni.switchTab({
  104. url: '/pages/home/home'
  105. })
  106. }, 2000)
  107. } else {
  108. uni.$showMsg('续住办理失败:' + res.data.msg)
  109. }
  110. } catch (e) {
  111. uni.$showMsg('续住办理失败:')
  112. } finally {
  113. this.extendButtonLoading = false
  114. }
  115. },
  116. confirmEndTimeChange(info) {
  117. //设置结束时间
  118. this.newEndTime = info.value
  119. //关闭选择器显示
  120. this.endTimePickerShow = false
  121. },
  122. async getCheckinInfo() {
  123. let res = await uni.$http.post('/checkinInfo/queryByCondition', {
  124. userIdNumber: this.userInfo.idNumber,
  125. status: 1,
  126. pageNo: 1,
  127. hotelId: this.currentHotelId,
  128. pageSize: 1
  129. });
  130. if (res.data.code == 200) {
  131. if (res.data.data.records.length > 0) {
  132. console.log(res.data.data.records[0].endTime)
  133. let originEndTime = new Date(res.data.data.records[0].endTime);
  134. this.newEndTime = new Date(originEndTime.valueOf() + 24 * 60 * 60 * 1000)
  135. this.oldEndTime = res.data.data.records[0].endTime
  136. let minDate = new Date(this.oldEndTime)
  137. minDate.setDate(minDate.getDate() + 1)
  138. let maxDate = new Date(this.oldEndTime)
  139. maxDate.setFullYear(maxDate.getFullYear() + 1)
  140. this.minDate = minDate.valueOf()
  141. this.maxDate = maxDate.valueOf()
  142. this.checkinInfo = res.data.data.records[0];
  143. this.checkinInfo.startTime = moment(this.checkinInfo.startTime).format('YYYY/MM/DD HH:mm')
  144. this.checkinInfo.endTime = moment(this.checkinInfo.endTime).format('YYYY/MM/DD HH:mm')
  145. } else {
  146. this.checkinInfo = {}
  147. }
  148. } else {
  149. uni.$showMsg('查询失败!')
  150. }
  151. }
  152. },
  153. onLoad() {
  154. this.getCheckinInfo()
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. .card-item {
  160. margin-bottom: 40rpx;
  161. display: flex;
  162. .card-item-left {
  163. width: 220rpx;
  164. }
  165. }
  166. .date-picker-container {
  167. display: flex;
  168. }
  169. .date-picker {
  170. margin-left: 80rpx;
  171. font-weight: bold;
  172. }
  173. .completeBtn {
  174. left: 80rpx;
  175. right: 80rpx;
  176. bottom: 120rpx;
  177. position: fixed;
  178. background-color: #0081ff;
  179. color: #ffffff;
  180. }
  181. .not-reservation {
  182. display: flex;
  183. justify-content: center;
  184. height: 100%;
  185. text-align: center;
  186. vertical-align: 100rpx;
  187. }
  188. .tip {
  189. padding-top: 40%;
  190. }
  191. </style>