favorites.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="container">
  3. <!-- 空白页 -->
  4. <empty v-if="favoriteList.length < 1"></empty>
  5. <view class="favorites flex" v-for="ls in favoriteList" @click="toproduct(ls.pid)">
  6. <view class="favorites_img"><image :src="ls.image"></image></view>
  7. <view class="favorites_list">
  8. <view class="favorites_name">{{ ls.store_name }}</view>
  9. <view class="favorites_peice flex">
  10. <view>
  11. <text>¥{{ ls.price }}</text>
  12. </view>
  13. <view class="icon_del" @click.prevent.stop="del(ls.pid)" v-show="delshow">
  14. <text class="iconfont icondelete"></text>
  15. <text>取消</text>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import { getcollectList, delcollect } from '@/api/user.js';
  24. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  25. import empty from '@/components/empty';
  26. export default {
  27. components: {
  28. uniLoadMore,
  29. empty
  30. },
  31. data() {
  32. return {
  33. tabCurrentIndex: 0,
  34. favoriteList: '',
  35. delshow: true
  36. };
  37. },
  38. onLoad() {
  39. this.loadData();
  40. },
  41. methods: {
  42. //获取收藏夹列表
  43. loadData() {
  44. let obj = this;
  45. getcollectList({
  46. page: '1',
  47. limit: '10'
  48. })
  49. .then(function(e) {
  50. obj.favoriteList = e.data;
  51. console.log(obj.favoriteList);
  52. })
  53. .catch(function(e) {
  54. console.log(e);
  55. });
  56. },
  57. //跳转商品详情页
  58. toproduct(item) {
  59. let id = item;
  60. uni.navigateTo({
  61. url: `/pages/product/product?id=${id}`
  62. })
  63. },
  64. //删除收藏夹商品
  65. del(item) {
  66. let obj = this;
  67. uni.showModal({
  68. title: '提示',
  69. content: '是否取消收藏该商品',
  70. success: e => {
  71. if (e.confirm) {
  72. delcollect({
  73. id: item,
  74. category: 'product'
  75. })
  76. .then(function(e) {
  77. uni.showToast({
  78. title: '已取消收藏',
  79. duration: 1500,
  80. });
  81. obj.loadData();
  82. })
  83. .catch(function(e) {
  84. console.log(e);
  85. });
  86. }
  87. }
  88. });
  89. },
  90. }
  91. }
  92. </script>
  93. <style lang="scss">
  94. page {
  95. height: 100%;
  96. }
  97. %flex-center {
  98. display: flex;
  99. flex-direction: column;
  100. justify-content: center;
  101. align-items: center;
  102. }
  103. %section {
  104. display: flex;
  105. justify-content: space-around;
  106. align-content: center;
  107. background: #fff;
  108. border-radius: 10rpx;
  109. }
  110. .container {
  111. height: 100%;
  112. background-color: $page-color-base;
  113. padding: 15rpx 0rpx;
  114. font-size: 28rpx;
  115. }
  116. .favorites {
  117. width: 90%;
  118. background-color: #ffffff;
  119. border-radius: 15rpx;
  120. margin: 15rpx auto;
  121. padding: 25rpx 25rpx;
  122. margin-bottom: 25rpx;
  123. }
  124. .favorites_img {
  125. width: 80px !important;
  126. height: 80px;
  127. }
  128. .favorites_img image {
  129. width: 100%;
  130. height: 100%;
  131. }
  132. .favorites_list {
  133. width: 70%;
  134. padding-left: 20rpx;
  135. }
  136. .icon_del {
  137. color: $font-color-base;
  138. z-index: 9999;
  139. font-weight: bold;
  140. }
  141. .favorites_name {
  142. height: 80rpx;
  143. overflow: hidden;
  144. text-overflow: ellipsis;
  145. display: -webkit-box;
  146. -webkit-box-orient: vertial;
  147. -webkit-line-clamp: 2;
  148. }
  149. .favorites_peice {
  150. margin-top: 25rpx;
  151. color: #db1935;
  152. font-weight: bold;
  153. }
  154. </style>