checkout.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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', ['currentHotel']),
  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. this.updateCheckinInfo({})
  74. uni.$showMsg('退房办理成功!')
  75. setTimeout(() => {
  76. uni.switchTab({
  77. url: '/pages/home/home'
  78. })
  79. }, 1000)
  80. } else {
  81. uni.$showMsg('退房办理失败')
  82. }
  83. } catch (e) {
  84. uni.$showMsg('退房办理失败')
  85. } finally {
  86. this.checkoutButtonLoading = false
  87. }
  88. },
  89. async getCheckinInfo() {
  90. let {
  91. data: res
  92. } = await uni.$http.post('/checkinInfo/queryByCondition', {
  93. userIdNumber: this.userInfo.idNumber,
  94. status: 1,
  95. hotelId: this.currentHotel.hotelId,
  96. pageNo: 1,
  97. pageSize: 1
  98. });
  99. console.log(res)
  100. if (res.code == 200) {
  101. if (res.data.records.length > 0) {
  102. this.checkinInfo = res.data.records[0];
  103. this.checkinInfo.startTime = moment(this.checkinInfo.startTime).format('YYYY/MM/DD HH:mm')
  104. this.checkinInfo.endTime = moment(this.checkinInfo.endTime).format('YYYY/MM/DD HH:mm')
  105. } else {
  106. this.checkinInfo = {}
  107. }
  108. } else {
  109. uni.$showMsg('查询失败!')
  110. }
  111. }
  112. },
  113. async onLoad() {
  114. await this.getCheckinInfo()
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. .card-item {
  120. margin-bottom: 40rpx;
  121. display: flex;
  122. .card-item-left {
  123. width: 140rpx;
  124. }
  125. }
  126. .completeBtn {
  127. left: 80rpx;
  128. right: 80rpx;
  129. bottom: 120rpx;
  130. position: fixed;
  131. background-color: #0081ff;
  132. color: #ffffff;
  133. }
  134. .not-reservation {
  135. display: flex;
  136. justify-content: center;
  137. height: 100%;
  138. text-align: center;
  139. vertical-align: 100rpx;
  140. }
  141. .tip {
  142. padding-top: 40%;
  143. }
  144. </style>