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

127 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. </skeleton>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data(){
  35. return {
  36. list: [],
  37. loadingClass: true,
  38. loadingText: '正在加载中',
  39. page: 1,
  40. isPage: true,
  41. pageSize: 20,
  42. skeletonLoading: true
  43. }
  44. },
  45. onLoad(){
  46. this.getCollectList();
  47. },
  48. methods: {
  49. getCollectList(){
  50. this.$http(this.API.API_COLLECT_LIST).then(res => {
  51. this.skeletonLoading = false;
  52. this.isPage = res.data.has_more_page;
  53. let list = res.data.items.map(item => {
  54. item.is_collect = true; // 默认都收藏了
  55. return item;
  56. });
  57. if(!res.data.has_more_page){
  58. this.loadingClass = false;
  59. this.loadingText = '已显示全部数据~';
  60. }
  61. if(this.page == 1){
  62. this.list = list;
  63. }else{
  64. this.list.push(...list);
  65. }
  66. }).catch(err => {
  67. this.skeletonLoading = false;
  68. })
  69. },
  70. // 切换收藏状态
  71. switchCollect(index){
  72. let goods_id = this.list[index].goods_id;
  73. this.$http(this.API.API_COLLECT_DEAL, {goods_id}).then(res => {
  74. this.list[index].is_collect = Boolean(res.data.user.is_collect);
  75. })
  76. },
  77. // 进入商品详情页
  78. enterDetail(index){
  79. let goods_id = this.list[index].goods_id;
  80. this.$url('/pages/goodsDetail/index?id='+ goods_id);
  81. }
  82. },
  83. onReachBottom(){
  84. if(this.isPage){
  85. this.page = this.page + 1;
  86. this.getCollectList();
  87. }
  88. },
  89. onPullDownRefresh(){
  90. this.page = 1;
  91. this.isPage = true;
  92. this.loadingClass = true;
  93. this.loadingText = '正在加载中';
  94. this.getCollectList();
  95. uni.stopPullDownRefresh();
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped="scoped">
  100. .list-box{
  101. width: 750rpx;
  102. height: auto;
  103. padding: 0 32rpx;
  104. box-sizing: border-box;
  105. .list-item{
  106. border-bottom: 1rpx solid #EEEEEE;
  107. padding: 30rpx 0;
  108. .goods-img{
  109. width: 180rpx;
  110. height: 180rpx;
  111. border-radius: 20rpx;
  112. background-color: #EEEEEE;
  113. }
  114. .shop-img{
  115. width: 60rpx;
  116. height: 60rpx;
  117. border-radius: 10rpx;
  118. }
  119. .shop-name{
  120. width: 340rpx;
  121. color: #555555;
  122. }
  123. }
  124. }
  125. </style>