海南旅游项目 前端仓库
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.

153 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. let list = res.data.items.map(item => {
  62. item.is_collect = true; // 默认都收藏了
  63. return item;
  64. });
  65. if(!res.data.has_more_page){
  66. this.loadingClass = false;
  67. this.loadingText = '已显示全部数据~';
  68. }
  69. if(this.page == 1){
  70. this.list = list;
  71. }else{
  72. this.list.push(...list);
  73. }
  74. }).catch(err => {
  75. this.skeletonLoading = false;
  76. })
  77. },
  78. // 切换收藏状态
  79. switchCollect(index){
  80. let goods_id = this.list[index].goods_id;
  81. this.$http(this.API.API_COLLECT_DEAL, {goods_id}).then(res => {
  82. this.list[index].is_collect = Boolean(res.data.user.is_collect);
  83. })
  84. },
  85. // 进入商品详情页
  86. enterDetail(index){
  87. let goods_id = this.list[index].goods_id;
  88. this.$url('/pages/goodsDetail/index?id='+ goods_id);
  89. }
  90. },
  91. onReachBottom(){
  92. if(this.isPage){
  93. this.page = this.page + 1;
  94. this.getCollectList();
  95. }
  96. },
  97. onPullDownRefresh(){
  98. this.page = 1;
  99. this.isPage = true;
  100. this.loadingClass = true;
  101. this.loadingText = '正在加载中';
  102. this.getCollectList();
  103. uni.stopPullDownRefresh();
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped="scoped">
  108. .list-box{
  109. width: 750rpx;
  110. height: auto;
  111. padding: 0 32rpx;
  112. box-sizing: border-box;
  113. .list-item{
  114. border-bottom: 1rpx solid #EEEEEE;
  115. padding: 30rpx 0;
  116. align-items: flex-start;
  117. .goods-img{
  118. width: 210rpx;
  119. height: 210rpx;
  120. border-radius: 20rpx;
  121. background-color: #EEEEEE;
  122. }
  123. .shop-img{
  124. width: 50rpx;
  125. height: 50rpx;
  126. border-radius: 50%;
  127. }
  128. .shop-name{
  129. width: 305rpx;
  130. color: #555555;
  131. }
  132. }
  133. }
  134. .collect-btn{
  135. width: 155rpx;
  136. height: 63rpx;
  137. border-radius: 32rpx;
  138. border: 2rpx solid #1998FE;
  139. // text-align: center;
  140. // line-height: 63rpx;
  141. color: #1998FE;
  142. font-size: 24rpx;
  143. }
  144. .cancel{
  145. border: 2rpx solid #555555;
  146. color: #555555;
  147. }
  148. </style>