checkout.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view>
  3. <view v-if="Object.keys(checkinInfo).length>0">
  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. </uni-card>
  36. <view class="completeBtn">
  37. <u-button type="primary" @click="checkout" :loading="checkoutButtonLoading"
  38. :loadingText="checkoutButtonLoadingText">退房</u-button>
  39. </view>
  40. </view>
  41. <view v-else class="not-reservation">
  42. <text class="tip">无可退入住记录</text>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import moment from 'moment'
  48. import {
  49. mapState,
  50. mapMutations
  51. } from 'vuex'
  52. export default {
  53. data() {
  54. return {
  55. checkinInfo: {},
  56. checkoutButtonLoading: false,
  57. checkoutButtonLoadingText: '办理中'
  58. };
  59. },
  60. computed: {
  61. ...mapState('m_user', ['userInfo']),
  62. ...mapState('m_business', ['currentHotelId']),
  63. },
  64. methods: {
  65. ...mapMutations('m_business', ['updateCheckinInfo']),
  66. async checkout() {
  67. try {
  68. this.checkoutButtonLoading = true
  69. let res = await uni.$http.post('/checkout', {
  70. id: this.checkinInfo.id
  71. });
  72. if (res.data.success === true) {
  73. uni.$showMsg('退房办理成功!')
  74. setTimeout(() => {
  75. uni.switchTab({
  76. url: '/pages/home/home'
  77. })
  78. }, 1000)
  79. } else {
  80. uni.$showMsg('退房办理失败:' + res.data.msg)
  81. }
  82. } catch (e) {
  83. uni.$showMsg('退房办理失败:')
  84. } finally {
  85. this.checkoutButtonLoading = false
  86. }
  87. },
  88. async getCheckinInfo() {
  89. let {
  90. data: res
  91. } = await uni.$http.post('/checkinInfo/queryByCondition', {
  92. userIdNumber: this.userInfo.idNumber,
  93. status: 1,
  94. hotelId: this.currentHotelId,
  95. pageNo: 1,
  96. pageSize: 1
  97. });
  98. console.log(res)
  99. if (res.code == 200) {
  100. if (res.data.records.length > 0) {
  101. this.checkinInfo = res.data.records[0];
  102. this.checkinInfo.startTime = moment(this.checkinInfo.startTime).format('YYYY/MM/DD HH:mm')
  103. this.checkinInfo.endTime = moment(this.checkinInfo.endTime).format('YYYY/MM/DD HH:mm')
  104. } else {
  105. this.checkinInfo = {}
  106. }
  107. } else {
  108. uni.$showMsg('查询失败!')
  109. }
  110. }
  111. },
  112. onLoad() {
  113. this.getCheckinInfo()
  114. }
  115. }
  116. </script>
  117. <style lang="scss">
  118. .card-item {
  119. margin-bottom: 40rpx;
  120. display: flex;
  121. .card-item-left {
  122. width: 140rpx;
  123. }
  124. }
  125. .completeBtn {
  126. left: 80rpx;
  127. right: 80rpx;
  128. bottom: 120rpx;
  129. position: fixed;
  130. background-color: #0081ff;
  131. color: #ffffff;
  132. }
  133. .not-reservation {
  134. display: flex;
  135. justify-content: center;
  136. height: 100%;
  137. text-align: center;
  138. vertical-align: 100rpx;
  139. }
  140. .tip {
  141. padding-top: 40%;
  142. }
  143. </style>