海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.8 KiB

  1. <template>
  2. <view>
  3. <view class="list-box">
  4. <view class="lf-row-between list-item" v-for="(item, index) in list" :key="item.id">
  5. <image class="goods-img" mode="aspectFill" :src="item.goods.cover" @click="enterDetail(index)"></image>
  6. <view style="width: 458rpx;">
  7. <view class="lf-font-28 lf-line-2" style="height: 80rpx;" @click="enterDetail(index)">{{ item.goods.name }}</view>
  8. <view class="lf-m-t-15 lf-font-24 lf-color-gray">{{ item.created_at_text }}</view>
  9. <view class="lf-row-between lf-m-t-20">
  10. <lf-price price="3599.00"></lf-price>
  11. <view class="lf-row-center collect-btn" :class="{'cancel': index == 1}">
  12. <text class="lf-iconfont lf-icon-dui1 lf-m-r-1" v-if="index != 1"></text>
  13. <text>{{ index == 1 ? '收藏' : '已收藏' }}</text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 加载 -->
  20. <view class="loading-more">
  21. <text v-if="list.length" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  22. <lf-nocontent v-else></lf-nocontent>
  23. </view>
  24. <!-- 回到顶部 -->
  25. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data(){
  31. return {
  32. list: [],
  33. loadingClass: true,
  34. loadingText: '正在加载中',
  35. page: 1,
  36. isPage: true,
  37. pageSize: 20,
  38. skeletonLoading: true
  39. }
  40. },
  41. onLoad(){
  42. this.getCollectList();
  43. },
  44. methods: {
  45. getCollectList(){
  46. // this.list = [{
  47. // id: 1,
  48. // goods: {cover: '', name: '小毛驴', store: {name: '家具家电'}},
  49. // is_collect: true,
  50. // created_at_text: '2021.07.07'
  51. // },{
  52. // id: 2,
  53. // goods: {cover: '', name: '小毛驴', store: {name: '家具家电'}},
  54. // is_collect: true,
  55. // created_at_text: '2021.07.07'
  56. // }];
  57. // return;
  58. this.$http(this.API.API_COLLECT_LIST).then(res => {
  59. this.skeletonLoading = false;
  60. this.isPage = res.data.has_more_page;
  61. console.log(res)
  62. let list = res.data.items.map(item => {
  63. item.is_collect = true; // 默认都收藏了
  64. return item;
  65. });
  66. if(!res.data.has_more_page){
  67. this.loadingClass = false;
  68. this.loadingText = '已显示全部数据~';
  69. }
  70. if(this.page == 1){
  71. this.list = list;
  72. }else{
  73. this.list.push(...list);
  74. }
  75. }).catch(err => {
  76. this.skeletonLoading = false;
  77. })
  78. },
  79. // 切换收藏状态
  80. switchCollect(index){
  81. let goods_id = this.list[index].goods_id;
  82. this.$http(this.API.API_COLLECT_DEAL, {goods_id}).then(res => {
  83. this.list[index].is_collect = Boolean(res.data.user.is_collect);
  84. })
  85. },
  86. // 进入商品详情页
  87. enterDetail(index){
  88. let goods_id = this.list[index].goods_id;
  89. this.$url('/pages/goodsDetail/index?id='+ goods_id);
  90. }
  91. },
  92. onReachBottom(){
  93. if(this.isPage){
  94. this.page = this.page + 1;
  95. this.getCollectList();
  96. }
  97. },
  98. onPullDownRefresh(){
  99. this.page = 1;
  100. this.isPage = true;
  101. this.loadingClass = true;
  102. this.loadingText = '正在加载中';
  103. this.getCollectList();
  104. uni.stopPullDownRefresh();
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped="scoped">
  109. .list-box{
  110. width: 750rpx;
  111. height: auto;
  112. padding: 0 32rpx;
  113. box-sizing: border-box;
  114. .list-item{
  115. border-bottom: 1rpx solid #EEEEEE;
  116. padding: 30rpx 0;
  117. align-items: flex-start;
  118. .goods-img{
  119. width: 210rpx;
  120. height: 210rpx;
  121. border-radius: 20rpx;
  122. background-color: #EEEEEE;
  123. }
  124. .shop-img{
  125. width: 50rpx;
  126. height: 50rpx;
  127. border-radius: 50%;
  128. }
  129. .shop-name{
  130. width: 305rpx;
  131. color: #555555;
  132. }
  133. }
  134. }
  135. .collect-btn{
  136. width: 155rpx;
  137. height: 63rpx;
  138. border-radius: 32rpx;
  139. border: 2rpx solid #1998FE;
  140. // text-align: center;
  141. // line-height: 63rpx;
  142. color: #1998FE;
  143. font-size: 24rpx;
  144. }
  145. .cancel{
  146. border: 2rpx solid #555555;
  147. color: #555555;
  148. }
  149. </style>