order.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <uni-segmented-control :values="orderStatusLabel" style-type="text" active-color="#666666"
  3. @clickItem="tabChange"></uni-segmented-control>
  4. <view class="order-list">
  5. <view class="order-item" v-for="order in orderList" :key="order.orderId">
  6. <view class="order-id">
  7. <text>订单号:</text>
  8. <text>{{order.orderId}}</text>
  9. </view>
  10. <view class="room-info">
  11. <image :src="order.roomPicPath"></image>
  12. <view class="room-info-text">
  13. <view class="room-type">
  14. <text>{{ order.roomTypeName }}</text>
  15. </view>
  16. <view class="room-price" v-if="current===0">
  17. <text>¥{{ order.price }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="date-info">
  22. <view class="date-info-item">
  23. <view class="date-info-item-title">
  24. <text>入住日期</text>
  25. </view>
  26. <view class="date-info-item-content">
  27. <text>{{formatDateTime(order.startTime)}}</text>
  28. <text>{{convertDateTimeToDayOfWeek(order.startTime)}}</text>
  29. </view>
  30. </view>
  31. <view class="date-info-item">
  32. <view class="date-info-item-title">
  33. <text>离店日期</text>
  34. </view>
  35. <view class="date-info-item-content">
  36. <text>{{formatDateTime(order.endTime)}}</text>
  37. <text>{{convertDateTimeToDayOfWeek(order.endTime)}}</text>
  38. </view>
  39. </view>
  40. <view class="date-info-item">
  41. <text>{{ `共${order.dayNum}晚` }}</text>
  42. <text>{{ order.breakfastNum ? `含${order.breakfastNum}早` : "不含早" }}</text>
  43. </view>
  44. </view>
  45. <view class="button">
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script setup>
  51. import moment from "moment"
  52. import {
  53. reactive,
  54. ref
  55. } from "vue"
  56. import {
  57. useHotelStore
  58. } from '@/store/hotelStore'
  59. import {
  60. getDayOfWeek
  61. } from "../../utils/dateTimeUtil"
  62. import {
  63. onPullDownRefresh,
  64. onReachBottom,
  65. onLoad
  66. } from '@dcloudio/uni-app'
  67. const hotel = useHotelStore().hotel
  68. const orderStatusLabel = ['未入住', '已入住', '已完成']
  69. const orderTitleStatus = ['待入住', '已入住', '已完成']
  70. const orderStatus = ['NOT_CHECKIN', 'CHECKIN', 'FINISHED']
  71. let current = ref(0)
  72. let orderList = reactive([])
  73. let pageNo = ref(1)
  74. const pageSize = 10
  75. let total = ref(0)
  76. function tabChange(e) {
  77. orderList.length = 0
  78. pageNo.value = 1
  79. current.value = e.currentIndex
  80. getOrders(orderStatus[e.currentIndex])
  81. }
  82. async function getOrders(status) {
  83. uni.showLoading({
  84. title: '正在加载'
  85. })
  86. try {
  87. let res = await uni.request({
  88. url: `/order/status`,
  89. method: "POST",
  90. data: {
  91. pageNo: pageNo.value,
  92. pageSize: pageSize,
  93. orderStatus: status,
  94. hotelId: hotel.hotelId
  95. }
  96. })
  97. orderList.push(...res.data.data.records)
  98. total.value = res.data.data.total
  99. } catch (err) {
  100. console.log(err)
  101. uni.showToast({
  102. icon: "none",
  103. title: '加载失败'
  104. })
  105. } finally {
  106. uni.hideLoading()
  107. }
  108. }
  109. function formatDateTime(dateTime) {
  110. return moment(dateTime).format('MM月DD日')
  111. }
  112. function convertDateTimeToDayOfWeek(dateTime) {
  113. return getDayOfWeek(new Date(dateTime))
  114. }
  115. onPullDownRefresh(() => {
  116. pageNo.value = 1
  117. orderList.length = 0
  118. setTimeout(() => {
  119. getOrders(orderStatus[current.value])
  120. uni.stopPullDownRefresh()
  121. }, 500)
  122. })
  123. onReachBottom(() => {
  124. if (orderList.length < total.value) {
  125. pageNo.value++
  126. getOrders(orderStatus[current.value])
  127. } else {
  128. uni.showToast({
  129. icon: "none",
  130. title: '已经到底啦!'
  131. })
  132. }
  133. })
  134. onLoad(async () => {
  135. await getOrders(orderStatus[0])
  136. })
  137. </script>
  138. <style lang="scss">
  139. page {
  140. background-color: #EBEAF0;
  141. }
  142. .order-list {
  143. overflow: hidden;
  144. .order-item {
  145. display: flex;
  146. flex-direction: column;
  147. background-color: #FFFFFF;
  148. border-radius: 24rpx;
  149. margin: 20rpx;
  150. &:last-child {
  151. margin-bottom: 40rpx;
  152. }
  153. .order-id {
  154. color: #333333;
  155. margin: 10rpx;
  156. font-size: 28rpx;
  157. }
  158. .room-info {
  159. margin: 10rpx 20rpx;
  160. display: flex;
  161. background-color: #F1F1F4;
  162. border-radius: 20rpx;
  163. image {
  164. margin: 10rpx;
  165. width: 180rpx;
  166. height: 180rpx;
  167. }
  168. .room-info-text {
  169. width: 60%;
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. font-weight: bold;
  174. margin: 0 20rpx;
  175. .room-price {
  176. color: #ff0000;
  177. }
  178. }
  179. }
  180. .date-info {
  181. margin: 10rpx 20rpx 20rpx 20rpx;
  182. display: flex;
  183. justify-content: space-between;
  184. background-color: #F1F1F4;
  185. .date-info-item {
  186. margin: 10rpx;
  187. display: flex;
  188. flex-direction: column;
  189. .date-info-item-title {
  190. margin: 10rpx;
  191. font-size: 28rpx;
  192. text {
  193. color: #666666;
  194. }
  195. }
  196. .date-info-item-content {
  197. margin: 10rpx;
  198. font-size: 24rpx;
  199. display: flex;
  200. justify-content: space-around;
  201. text {
  202. margin-right: 40rpx;
  203. color: #333333;
  204. }
  205. }
  206. &:last-child {
  207. justify-content: space-around;
  208. font-weight: bold;
  209. margin-right: 20rpx;
  210. text {
  211. color: #333333;
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. .segmented-control--text {
  219. background-color: #ffffff;
  220. }
  221. </style>