时空网前端
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.

129 lines
3.4 KiB

  1. <template>
  2. <view>
  3. <skeleton :loading="skeletonLoading" :row="6" :showAvatar="false" :showTitle="true">
  4. <view class="list-box">
  5. <view class="lf-row-between list-item" v-for="(item, index) in list" :key="item.id">
  6. <image class="goods-img" :src="item.goods.cover" @click="enterDetail(index)"></image>
  7. <view style="width: 480rpx;">
  8. <view class="lf-font-32 lf-line-1" @click="enterDetail(index)">{{ item.goods.name }}</view>
  9. <view class="lf-row-between lf-m-t-20">
  10. <view class="lf-flex">
  11. <image class="shop-img" :src="item.goods.store.cover" v-if="item.goods.store.cover"></image>
  12. <image class="shop-img" src="../../static/center/shop-logo.png" v-else></image>
  13. <view class="lf-m-l-10 lf-font-28 lf-line-1 shop-name">{{ item.goods.store.name }}</view>
  14. </view>
  15. <view @click="switchCollect(index)" class="lf-font-40">
  16. <u-icon name="heart-fill" color="#ff0f00" v-if="item.is_collect"></u-icon>
  17. <u-icon name="heart" v-else></u-icon>
  18. </view>
  19. </view>
  20. <view class="lf-m-t-20 lf-font-24 lf-color-gray">{{ item.created_at_text }}</view>
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 加载 -->
  25. <view class="loading-more">
  26. <text v-if="list.length" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  27. <my-nocontent v-else></my-nocontent>
  28. </view>
  29. <!-- 回到顶部 -->
  30. <u-back-top :scroll-top="pageScrollTop"></u-back-top>
  31. </skeleton>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data(){
  37. return {
  38. list: [],
  39. loadingClass: true,
  40. loadingText: '正在加载中',
  41. page: 1,
  42. isPage: true,
  43. pageSize: 20,
  44. skeletonLoading: true
  45. }
  46. },
  47. onLoad(){
  48. this.getCollectList();
  49. },
  50. methods: {
  51. getCollectList(){
  52. this.$http(this.API.API_COLLECT_LIST).then(res => {
  53. this.skeletonLoading = false;
  54. this.isPage = res.data.has_more_page;
  55. let list = res.data.items.map(item => {
  56. item.is_collect = true; // 默认都收藏了
  57. return item;
  58. });
  59. if(!res.data.has_more_page){
  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. }).catch(err => {
  69. this.skeletonLoading = false;
  70. })
  71. },
  72. // 切换收藏状态
  73. switchCollect(index){
  74. let goods_id = this.list[index].goods_id;
  75. this.$http(this.API.API_COLLECT_DEAL, {goods_id}).then(res => {
  76. this.list[index].is_collect = Boolean(res.data.user.is_collect);
  77. })
  78. },
  79. // 进入商品详情页
  80. enterDetail(index){
  81. let goods_id = this.list[index].goods_id;
  82. this.$url('/pages/goodsDetail/index?id='+ goods_id);
  83. }
  84. },
  85. onReachBottom(){
  86. if(this.isPage){
  87. this.page = this.page + 1;
  88. this.getCollectList();
  89. }
  90. },
  91. onPullDownRefresh(){
  92. this.page = 1;
  93. this.isPage = true;
  94. this.loadingClass = true;
  95. this.loadingText = '正在加载中';
  96. this.getCollectList();
  97. uni.stopPullDownRefresh();
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped="scoped">
  102. .list-box{
  103. width: 750rpx;
  104. height: auto;
  105. padding: 0 32rpx;
  106. box-sizing: border-box;
  107. .list-item{
  108. border-bottom: 1rpx solid #EEEEEE;
  109. padding: 30rpx 0;
  110. .goods-img{
  111. width: 180rpx;
  112. height: 180rpx;
  113. border-radius: 20rpx;
  114. background-color: #EEEEEE;
  115. }
  116. .shop-img{
  117. width: 60rpx;
  118. height: 60rpx;
  119. border-radius: 10rpx;
  120. }
  121. .shop-name{
  122. width: 340rpx;
  123. color: #555555;
  124. }
  125. }
  126. }
  127. </style>