order.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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="getPicPath(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. ROOM_TYPE_PIC_URL
  54. } from "../../config"
  55. import {
  56. reactive,
  57. ref
  58. } from "vue";
  59. import {
  60. useHotelStore
  61. } from '@/store/hotelStore'
  62. import {
  63. getDayOfWeek
  64. } from "../../utils/dateTimeUtil";
  65. import {
  66. onPullDownRefresh,
  67. onReachBottom
  68. } from '@dcloudio/uni-app'
  69. const hotel = useHotelStore().hotel
  70. const orderStatusLabel = ['未入住', '已入住', '已完成']
  71. const orderTitleStatus = ['待入住', '已入住', '已完成']
  72. const orderStatus = ['NOT_CHECKIN', 'CHECKIN', 'FINISHED']
  73. let current = ref(0)
  74. let orderList = reactive([])
  75. let pageNo = ref(1)
  76. const pageSize = 10
  77. let total = ref(0)
  78. function tabChange(e) {
  79. orderList.length = 0
  80. pageNo.value = 1
  81. current.value = e.currentIndex
  82. getOrders(orderStatus[e.currentIndex])
  83. }
  84. async function getOrders(status) {
  85. uni.showLoading({
  86. title: '正在加载'
  87. })
  88. try {
  89. let res = await uni.request({
  90. url: `/order/status`,
  91. method: "POST",
  92. data: {
  93. pageNo: pageNo.value,
  94. pageSize: pageSize,
  95. orderStatus: status,
  96. hotelId: hotel.hotelId
  97. }
  98. })
  99. orderList.push(...res.data.data.records)
  100. total.value = res.data.data.total
  101. } catch (err) {
  102. console.log(err)
  103. } finally {
  104. uni.hideLoading()
  105. }
  106. }
  107. function getPicPath(path) {
  108. return ROOM_TYPE_PIC_URL + '/' + path
  109. }
  110. function formatDateTime(dateTime) {
  111. return moment(dateTime).format('MM月DD日')
  112. }
  113. function convertDateTimeToDayOfWeek(dateTime) {
  114. return getDayOfWeek(new Date(dateTime))
  115. }
  116. onPullDownRefresh(() => {
  117. pageNo.value = 1
  118. orderList.length = 0
  119. setTimeout(() => {
  120. getOrders(orderStatus[current.value])
  121. uni.stopPullDownRefresh()
  122. }, 500)
  123. })
  124. onReachBottom(() => {
  125. if (orderList.length < total.value) {
  126. pageNo.value++
  127. getOrders(orderStatus[current.value])
  128. } else {
  129. uni.showToast({
  130. icon: "none",
  131. title: '已经到底啦!'
  132. })
  133. }
  134. })
  135. </script>
  136. <style lang="scss">
  137. page {
  138. background-color: #EBEAF0;
  139. }
  140. .order-list {
  141. overflow: hidden;
  142. .order-item {
  143. display: flex;
  144. flex-direction: column;
  145. background-color: #FFFFFF;
  146. border-radius: 24rpx;
  147. margin: 20rpx;
  148. &:last-child {
  149. margin-bottom: 40rpx;
  150. }
  151. .order-id {
  152. color: #333333;
  153. margin: 10rpx;
  154. font-size: 28rpx;
  155. }
  156. .room-info {
  157. margin: 10rpx 20rpx;
  158. display: flex;
  159. background-color: #F1F1F4;
  160. border-radius: 20rpx;
  161. image {
  162. margin: 10rpx;
  163. width: 180rpx;
  164. height: 180rpx;
  165. }
  166. .room-info-text {
  167. width: 60%;
  168. display: flex;
  169. justify-content: space-between;
  170. align-items: center;
  171. font-weight: bold;
  172. margin: 0 20rpx;
  173. .room-price {
  174. color: #ff0000;
  175. }
  176. }
  177. }
  178. .date-info {
  179. margin: 10rpx 20rpx 20rpx 20rpx;
  180. display: flex;
  181. justify-content: space-between;
  182. background-color: #F1F1F4;
  183. .date-info-item {
  184. margin: 10rpx;
  185. display: flex;
  186. flex-direction: column;
  187. .date-info-item-title {
  188. margin: 10rpx;
  189. font-size: 28rpx;
  190. text {
  191. color: #666666;
  192. }
  193. }
  194. .date-info-item-content {
  195. margin: 10rpx;
  196. font-size: 24rpx;
  197. display: flex;
  198. justify-content: space-around;
  199. text {
  200. margin-right: 40rpx;
  201. color: #333333;
  202. }
  203. }
  204. &:last-child {
  205. justify-content: space-around;
  206. font-weight: bold;
  207. margin-right: 20rpx;
  208. text {
  209. color: #333333;
  210. }
  211. }
  212. }
  213. }
  214. }
  215. }
  216. .segmented-control--text {
  217. background-color: #ffffff;
  218. }
  219. </style>