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

158 lines
4.0 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.product.picture" @click="enterDetail(item.agent_product_id)"></image>
  6. <view style="width: 458rpx;">
  7. <view class="lf-font-28 lf-line-2" style="height: 80rpx;" @click="enterDetail(item.id)">{{ item.title }}</view>
  8. <view class="lf-m-t-15 lf-font-24 lf-color-gray">{{ item.created_at || '' }}</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" @click="switchCollect(index,item.is_collect)" :class="{'cancel': !item.is_collect}">
  12. <text class="lf-iconfont lf-icon-dui1 lf-m-r-1" v-if="item.is_collect"></text>
  13. <text>{{ !item.is_collect ? '收藏' : '已收藏' }}</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.$http(this.API.API_COLLECT_LIST,{page: this.page}).then(res => {
  47. this.skeletonLoading = false;
  48. let isPage = res.data.next_page_url == null?false:true;
  49. this.isPage = isPage;
  50. console.log(res)
  51. // let list = res.data.map(item => {
  52. // item.is_collect = true; // 默认都收藏了
  53. // return item;
  54. // });
  55. let list = res.data.data
  56. res.data.data.forEach((item,index) => {
  57. this.$set(list[index],'is_collect',true)
  58. })
  59. if(!isPage){
  60. this.loadingClass = false;
  61. this.loadingText = '已显示全部数据~';
  62. }
  63. if(this.page == 1){
  64. this.list = list;
  65. }else{
  66. this.list.push(...list);
  67. }
  68. console.log('列表',this.list)
  69. }).catch(err => {
  70. this.skeletonLoading = false;
  71. })
  72. },
  73. // 切换收藏状态
  74. switchCollect(index,if_collect){
  75. let goods_id = this.list[index].agent_product_id;
  76. if(if_collect) {
  77. this.$http(this.API.API_DELCOLLECT, {agent_product_id:goods_id}).then(res => {
  78. this.$msg('取消收藏成功!')
  79. console.log(res)
  80. this.list[index].is_collect = false;
  81. })
  82. }else {
  83. this.$http(this.API.API_ADDCOLLECT, {agent_product_id:goods_id}).then(res => {
  84. this.$msg('添加收藏成功!')
  85. console.log(res)
  86. this.list[index].is_collect = true;
  87. })
  88. }
  89. },
  90. // 进入商品详情页
  91. enterDetail(id){
  92. this.$url('/pages/goodsDetail/index?goods_id='+ id);
  93. }
  94. },
  95. onReachBottom(){
  96. if(this.isPage){
  97. this.page = this.page + 1;
  98. this.getCollectList();
  99. }
  100. },
  101. onPullDownRefresh(){
  102. this.page = 1;
  103. this.isPage = true;
  104. this.loadingClass = true;
  105. this.loadingText = '正在加载中';
  106. this.getCollectList();
  107. uni.stopPullDownRefresh();
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped="scoped">
  112. .list-box{
  113. width: 750rpx;
  114. height: auto;
  115. padding: 0 32rpx;
  116. box-sizing: border-box;
  117. .list-item{
  118. border-bottom: 1rpx solid #EEEEEE;
  119. padding: 30rpx 0;
  120. align-items: flex-start;
  121. .goods-img{
  122. width: 210rpx;
  123. height: 210rpx;
  124. border-radius: 20rpx;
  125. background-color: #EEEEEE;
  126. }
  127. .shop-img{
  128. width: 50rpx;
  129. height: 50rpx;
  130. border-radius: 50%;
  131. }
  132. .shop-name{
  133. width: 305rpx;
  134. color: #555555;
  135. }
  136. }
  137. }
  138. .collect-btn{
  139. width: 155rpx;
  140. height: 63rpx;
  141. border-radius: 32rpx;
  142. border: 2rpx solid #1998FE;
  143. // text-align: center;
  144. // line-height: 63rpx;
  145. color: #1998FE;
  146. font-size: 24rpx;
  147. }
  148. .cancel{
  149. border: 2rpx solid #555555;
  150. color: #555555;
  151. }
  152. </style>