collect.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="container">
  3. <!-- 分段器区域 -->
  4. <view class="segmented">
  5. <uni-segmented-control :current="activeCurrent" :values="headerList" style-type="text" active-color="#096562" @clickItem="onClickItem" />
  6. </view>
  7. <!-- 列表区域 -->
  8. <scroll-view class="body" scroll-y @scrolltolower="handlePull">
  9. <!-- 每一个盒子区域 -->
  10. <view class="box" v-for="item in list" :key="item.id" @click="handleGoPage(item)">
  11. <!-- 民宿图片区域 -->
  12. <img mode="aspectFill" :src="item.coverImg" />
  13. <!-- 民宿信息区域 -->
  14. <view class="box_info">
  15. <view class="info_name">{{ item.hotel_name }}</view>
  16. <view class="info_rate">
  17. <view class="rate_num">{{ item.score === 0 ? '5.0' : item.score }}</view>
  18. <view v-if="item.score < 1 && item.score > 0" class="rate_msg">很差</view>
  19. <view v-if="item.score < 2 && item.score > 1" class="rate_msg">差</view>
  20. <view v-if="item.score < 3 && item.score > 2" class="rate_msg">一般</view>
  21. <view v-if="item.score < 4 && item.score > 3" class="rate_msg">棒</view>
  22. <view v-if="item.score > 4 || item.score === 0" class="rate_msg">超棒</view>
  23. </view>
  24. <view class="info_town">{{ item.hotelTownshipName }}</view>
  25. </view>
  26. <!-- 民宿价格区域 -->
  27. <view class="box_price">
  28. <view class="price_icon">¥</view>
  29. <view class="price_num">{{ item.min_price }}</view>
  30. <view class="price_msg">起</view>
  31. </view>
  32. </view>
  33. <view class="noData" v-if="list.length === 0">
  34. <img lazy-load :lazy-load-margin="0" src="../../static/images/noData.png" />
  35. {{ noDataMsg }}
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. // 分段器当前激活索引
  45. activeCurrent: 0,
  46. // 分段器数组
  47. headerList: ['收藏', '住过'],
  48. // 列表数据
  49. list: [],
  50. noDataMsg: '暂无收藏数据',
  51. page: 1,
  52. rows: 6,
  53. total: null,
  54. type: '收藏'
  55. }
  56. },
  57. onLoad() {
  58. this.getData()
  59. },
  60. methods: {
  61. async getData() {
  62. const res = await this.$myRequest({
  63. url: '/mhotel/ampgetHotelAndUsersList.action',
  64. data: {
  65. userId: uni.getStorageSync('userInfo').id,
  66. page: this.page,
  67. rows: this.rows,
  68. type: this.type
  69. }
  70. })
  71. // console.log(res)
  72. if (res.code === 200 && res.data) {
  73. this.list = [...this.list, ...res.data.pageList]
  74. this.total = res.data.total
  75. }
  76. },
  77. // 切换分段器回调
  78. onClickItem(e) {
  79. this.activeCurrent = e.currentIndex
  80. if (this.activeCurrent === 0) {
  81. this.noDataMsg = '暂无收藏数据'
  82. this.type = '收藏'
  83. } else {
  84. this.noDataMsg = '暂无住过数据'
  85. this.type = '住过'
  86. }
  87. this.list = []
  88. this.page = 1
  89. this.getData()
  90. },
  91. // 列表下拉到底部回调
  92. handlePull() {
  93. if (this.list.length < this.total) {
  94. this.page++
  95. this.getData()
  96. } else {
  97. uni.showToast({
  98. title: '没有更多数据了',
  99. icon: 'none'
  100. })
  101. }
  102. },
  103. handleGoPage(item) {
  104. uni.navigateTo({
  105. url: `/pages/detail/detail?id=${item.id}`
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .container {
  113. height: 100vh;
  114. background-color: #f2f3f5;
  115. overflow: hidden;
  116. .segmented {
  117. box-sizing: border-box;
  118. padding-bottom: 28rpx;
  119. height: 100rpx;
  120. background-color: #fff;
  121. }
  122. .body {
  123. box-sizing: border-box;
  124. padding: 20rpx 0;
  125. height: calc(100vh - 100rpx);
  126. .box {
  127. display: flex;
  128. align-items: center;
  129. padding: 0 20rpx;
  130. height: 207rpx;
  131. border-bottom: 1rpx solid #e5e5e5;
  132. background-color: #fff;
  133. img {
  134. width: 110rpx;
  135. height: 146rpx;
  136. border-radius: 10rpx;
  137. }
  138. .box_info {
  139. display: flex;
  140. flex-direction: column;
  141. justify-content: space-between;
  142. margin-top: -5rpx;
  143. margin-left: 20rpx;
  144. height: 146rpx;
  145. .info_name {
  146. font-size: 32rpx;
  147. font-weight: bold;
  148. }
  149. .info_rate {
  150. display: flex;
  151. font-size: 24rpx;
  152. .rate_num {
  153. padding: 4rpx 10rpx;
  154. color: #fff;
  155. border-radius: 32rpx 0 0 32rpx;
  156. background-color: #096562;
  157. }
  158. .rate_msg {
  159. padding: 4rpx 10rpx;
  160. color: #096562;
  161. border-radius: 0 32rpx 32rpx 0;
  162. background-color: #dff2f2;
  163. }
  164. }
  165. .info_town {
  166. color: #808080;
  167. font-size: 24rpx;
  168. }
  169. }
  170. .box_price {
  171. display: flex;
  172. align-items: flex-end;
  173. margin-left: auto;
  174. height: 146rpx;
  175. .price_icon {
  176. margin-bottom: 5rpx;
  177. color: #ff5733;
  178. font-size: 24rpx;
  179. }
  180. .price_num {
  181. color: #ff5733;
  182. font-size: 42rpx;
  183. }
  184. .price_msg {
  185. margin-left: 12rpx;
  186. margin-bottom: 5rpx;
  187. color: #808080;
  188. font-size: 24rpx;
  189. }
  190. }
  191. }
  192. .noData {
  193. display: flex;
  194. flex-direction: column;
  195. justify-content: center;
  196. align-items: center;
  197. padding-bottom: 20rpx;
  198. img {
  199. margin-top: 160rpx;
  200. width: 600rpx;
  201. height: 600rpx;
  202. }
  203. }
  204. }
  205. }
  206. </style>